jQuery焦点控制图层展示延迟隐藏的方法

复制代码 代码如下:


<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
</head>
<body>
<b>点我</b>
<div>我是内容</div>
<script type="text/javascript" src="https://www.jb51.net/jquery.js"></script>
<script>
$(document).ready(function(){
    jQuery.focusShow({butID:'#button',divID:'#div',mouse:'over',time:'500'})
})
jQuery.extend({
    focusShow: function(config){
        //ps:焦点控制图层展示,延迟隐藏
        //focusShow({butID:'按钮ID',divID:'容器ID',mouse:'over || click',time:'时间'})
        var butID = $(config.butID || false),
            divID = $(config.divID || false),
            mouse = config.mouse || 'click',
            time = config.time || '500',
            timer;
        function re(){$(divID).hide()}
        switch (mouse){
            case "click":
                butID.bind({'click':function(){divID.attr('tabindex','-1');divID.focus()}});
                divID.bind({
                    "focus":function(){clearTimeout(timer);divID.show()},
                    "blur":function(){timer = setTimeout(re,time)}
                })
                break
            case "over":
                $(butID,divID).each(function(){
                    $(this).bind({
                        'mouseover':function(){clearTimeout(timer);divID.show()},
                        'mouseout':function(){timer = setTimeout(re,time)}
                    })
                })
                break
            default:
        }
    }
});
</script>
</body>
</html>

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wgfzpj.html