I'm using knockout to bind a list of images. What's the best way to set up a spinner background while the images are loading. I have a spinner class I can set and unset to the background image, but wondering if there is an easy way to bind to image complete events with knockout.js.
using jquery UIs little spinner thing, I have a binding handler like
ko.bindingHandlers.Loading = {
update: function (element, valueAccessor, allBindingsAccessor) {
var value = valueAccessor(), allBindings = allBindingsAccessor();
var valueUnwrapped = ko.utils.unwrapObservable(value);
if (valueUnwrapped == true)
$(element).showLoading(); // Make the element visible
else
$(element).hideLoading(); // Make the element invisible
}
};
and then use it like
<div data-bind="Loading: isLoading" >
so, basically, you can bind it to anything on your view model that might represent its loading ( or busy ) or not.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With