javascript - jquery offset incrementing previous value on .hide() -
setting position jquery.offset() not behaving expect. example code attempts overlay div (.slide) (.active) div on hover. understand offset({top,left}} set position of element {top, left} incrementing position amount each time.
as exercise - if set active block display:block , remove active.hide() statement positioning works expect. .hide() appears causing offset accumulation. im grateful guidance.
http://jsfiddle.net/laurencefass/q815mqkm/
$(".slide").mouseenter(function (e) { $(this).css("background-color", "red"); offset = $(this).offset(); }
more code follow link...
see fiddle edited code overlay div on top of hovered div. assume wanted. see updated fiddle. in code setting top:1 , left:1 not true div's @ different positions , need use offsets instead of using 1 , 1 every time , setting offset defined setting coordinates(position) of element make work element should made visible @ first instance set coordinates
active.show(); //show div first , set offset active.offset({ top: offset.top, left: offset.left });
Comments
Post a Comment