jQuery focus control layer shows the method of delay hiding
- 2020-05-12 02:11:29
- OfStack
This example demonstrates the method of jQuery focus control layer display delay hiding. Share with you for your reference. The specific implementation method is as follows:
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
</head>
<body>
<b id="button"> Am I </b>
<div id="div" style="background:#faf;outline:none;display:none"> I am content </div>
<script type="text/javascript" src="jquery.js"></script>
<script>
$(document).ready(function(){
jQuery.focusShow({butID:'#button',divID:'#div',mouse:'over',time:'500'})
})
jQuery.extend({
focusShow: function(config){
//ps: Focus control layer display , Latency hiding
//focusShow({butID:' button ID',divID:' The container ID',mouse:'over || click',time:' 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>
I hope this article has been helpful to your jQuery programming.