最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - how to show an image loading spinner with knockout.js - Stack Overflow

programmeradmin1浏览0评论

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
Add a ment  | 

1 Answer 1

Reset to default 9

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.

发布评论

评论列表(0)

  1. 暂无评论