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

javascript - Is there a fade + disable plugin in jQuery? - Stack Overflow

programmeradmin2浏览0评论

So we monly e across faded objects that cannot be used on the Internet, such as a text-box that has a gray/faded appearance that cannot be clicked in and typed into.

I would like to do the same with a CSS object, which would later be un-faded and enabled to be used.

Any help would be appreciated.

Thanks!

So we monly e across faded objects that cannot be used on the Internet, such as a text-box that has a gray/faded appearance that cannot be clicked in and typed into.

I would like to do the same with a CSS object, which would later be un-faded and enabled to be used.

Any help would be appreciated.

Thanks!

Share edited Mar 24, 2011 at 5:28 gideon 19.5k11 gold badges74 silver badges114 bronze badges asked Mar 24, 2011 at 5:00 honeywindhoneywind 2273 silver badges13 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 6

You mean something like:

$(element).fadeTo('fast', 0.5).attr('disabled', 'disabled');

Note that this assumes jQuery.

Is there a fade + disable plugin in jQuery?

jQuery plugin

(function($) {
    $.fn.fadeAndDisable = function(delay) {
        delay = delay || 500;
        return this.each(function() {
            $(this).fadeTo(0.5, delay, function() {
                $(this).attr('disabled', 'disabled');
            })
        });
    }

    $.fn.fadeAndEnable = function(delay) {
        delay = delay || 500;
        return this.each(function() {
            $(this).fadeTo(1, delay, function() {
                $(this).removeAttr('disabled');
            })
        });
    }

})(jQuery);

jsFiddle.

Usage

$('input').fadeAndDisable(1000);
$('input').fadeAndEnable(1000);

You may want to extend this to allow callbacks, which is trivial to add.

You can either use animate() or fadeout() and then you can include option to disable..

发布评论

评论列表(0)

  1. 暂无评论