首页 > 其他 > 详细

hover事件优化(延时操作)

时间:2015-02-11 16:16:47      阅读:315      评论:0      收藏:0      [点我收藏+]

JQ的hover事件拓展

编写原因:当鼠标滑过某个带有hover事件的元素,但是仅仅是路过,并不是希望查看此部分内容的时候,效果不理想

$.fn.extend({
    delayed : function(fn1,fn2,time){
        time = time || 150
        var _this = this;
        
        _this.delayedTimer = null;
        return $(this).mouseenter(function(){
            clearTimeout(_this.delayedTimer);
            _this.delayedTimer = setTimeout(function (){
                fn1.call(_this);                
            },time)
        }).mouseleave(function(){
            clearTimeout(_this.delayedTimer);
            _this.delayedTimer = setTimeout(function (){
                fn2.call(_this);                
            },time)
        })
    }
})    

用法和hover基本一样,但是此方法目前无法针对多个元素,但是添加起来应该也不费劲

hover事件优化(延时操作)

原文:http://www.cnblogs.com/liqingchang/p/4286349.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!