Home >Web Front-end >JS Tutorial >Dynamic label hover effect lazy loading sample code_jquery

Dynamic label hover effect lazy loading sample code_jquery

WBOY
WBOYOriginal
2016-05-16 17:13:181118browse

-----------------------For dynamic label binding events--------------------- ---

Copy code The code is as follows:

var outTimer;//Execution time
var upTimer;//Execution time
var sqDiv = $("#tm");//The div to be displayed
var test="";//Identification, in order to move the mouse to the displayed div
var dd = "";//Scratch the value passed by a certain field
function test1(){
$("#tm").empty();// Now clear the div
$.ajax({ //Add data in it
type: "post",
url: "<%=path %>/webmodule/constructionDecision/BaseCD/getCommunityInfo.do ?stCode=" dd,
dataType:"json",
async:false,
success:function(data){
var td="";
for(var i=0 ;itd ="" data[i].name "";
}
$("#tm").append(td);
}
});
$("#tm").show();
}

function test2(){//How to hide div
if(test ==""){
$("#tm").hide();
}
}
$("#cityTable a").die().live('mouseover mouseout', function(event) { //Bind events to dynamic tags

if(event.type=='mouseover '){ //When moving up
clearTimeout(outTimer);//Clear the time out first, so as to avoid executing functions when the mouse is moved over and reduce the pressure on the server
dd=$(this).attr( "id");
upTimer = setTimeout(test1, 500);//Execute after 0.5 seconds
}
if(event.type=='mouseout'){
sqDiv.hover(
function(){
test = "on";//Indicates that the mouse is on the displayed div
}, function(){
test = "";
test2();
});
clearTimeout(upTimer);
outTimer = setTimeout(test2, 500);
}
});

------ -----------------------Non-dynamic tags (query information)--------------------- ----------------
Copy code The code is as follows:

//hoverDuring The delay time when the mouse passes
//outDuring The delay time when the mouse moves out
//hoverEvent The method executed when the mouse passes
//outEvent The method executed when the mouse moves out
$( function() {
$.fn.hoverDelay = function(options) {
var defaults = {
hoverDuring :200,
outDuring :200,
hoverEvent : function() {
$.noop();
},
outEvent : function() {
$.noop();
}
};
var sets = $.extend(defaults , options || {});
var hoverTimer, outTimer;
return $(this).each( function() {
$(this).hover( function() {
clearTimeout( outTimer);
hoverTimer = setTimeout(sets.hoverEvent, sets.hoverDuring);
}, function() {
clearTimeout(hoverTimer);
outTimer = setTimeout(sets.outEvent, sets.outDuring );
});
}); The code is as follows:

//$("#sosoFod h3").each( function() {
$("#sosoweb").each( function() {
var test = "";//When test is empty, move the mouse to the field to display the div and move out of the hidden div var that = $(this); var id = that.attr("id"); var div = $("#tm"); div.css("position", "absolute");//Let this layer be absolutely positioned that.hoverDelay( { outDuring : 1000,
hoverEvent: function() {
div.css("display", "block");
var p = that.position(); //Get the left and top of this element
var x = p.left that.width();//Get the left of this floating layer
var docWidth = $(document).width();//Get the width of the web page
if (x > docWidth - div.width() - 20) {
x = p.left - div.width();
}
div.css("left", x);
div.css ("top", p.top);
//$("#tm").show();

},
outEvent : function() {

$("#tm").hoverDelay( {
outDuring :1000,
hoverEvent : function() {
test = "on";
$("#tm").show() ;
},
outEvent : function() {
test="";
$("#tm").hide();
}
});
if(test==""){
$("#tm").hide();
}
}
});
});

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn