Dynamic tag hover effect lazy loading sample code
- 2020-03-29 23:55:43
- OfStack
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- the label for dynamic binding events -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- the dynamic tags (query) -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
var outTimer;//The execution time
var upTimer;//The execution time
var sqDiv = $("#tm");//Div to display
var test="";//Id, in order to move the mouse over the div displayed, div does not disappear
var dd = "";//The value passed across a field
function test1(){
$("#tm").empty();//Now empty the div
$.ajax({ //Add data
type:"post",
url:"<%=path %>/webmodule/constructionDecision/BaseCD/getCommunityInfo.do?stCode="+dd,
dataType:"json",
async:false,
success:function(data){
var td="";
for(var i=0;i<data.length;i++){
td+="<a id ='"+data[i].gridNumber+"'>"+data[i].name+"</a>";
}
$("#tm").append(td);
}
});
$("#tm").show();
}
function test2(){//Method to hide div
if(test ==""){
$("#tm").hide();
}
}
$("#cityTable a").die().live('mouseover mouseout', function(event) { //Bind events to dynamic tags
if(event.type=='mouseover'){ //Move on
clearTimeout(outTimer);//Clear the elapsed time so that the function can be executed without a mouse swipe, reducing the stress 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 div displayed
},function(){
test = "";
test2();
});
clearTimeout(upTimer);
outTimer = setTimeout(test2, 500);
}
});
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- the dynamic tags (query) -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
//HoverDuring mouse lag time
//OutDuring mouse out delay time
//HoverEvent is a mouse-over execution method
//OutEvent moves the mouse over the executed method
$( 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);
});
});
}
//$("#sosoFod h3").each( function() {
$("#sosoweb").each( function() {
var test = "";//When test is empty, mouse over to the field to show div, and move out of the hidden div
var that = $(this);
var id = that.attr("id");
var div = $("#tm");
div.css("position", "absolute");//Make this layer absolutely locatable
that.hoverDelay( {
outDuring :1000,
hoverEvent : function() {
div.css("display", "block");
var p = that.position(); //Gets the left and top of this element
var x = p.left + that.width();//Gets the left of the floating layer
var docWidth = $(document).width();//Gets the width of the 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();
}
}
});
}) ;