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 plete events with knockout.js.
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 plete events with knockout.js.
Share Improve this question asked May 23, 2012 at 20:44 MonkeyBonkeyMonkeyBonkey 47.9k82 gold badges270 silver badges479 bronze badges 1- malsup./jquery/block/#demos – deltree Commented May 23, 2012 at 20:54
1 Answer
Reset to default 9using 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.