prevent page repositioning after editing with jQuery
I'm updating several image src attributes on a page, and they are updated properly, but when jQuery updates those items, the page scrolls down to those items (they are below the 'fold') - how can I stop the page from auto-scrolling down to the changes I'm making with jQuery? 开发者_如何学运维 I see the same behavior with IE and FireFox
// insert images into current page
$("img.nominphoto",$(".nominwrap")).each(function(){
var userItemID=$(this).attr("title");
$(this).attr("src",hashImageURLs[userItemID]);
});
Thanks
You may be able to fines it by using $(window).scrollTop
and maybe hooking to the image's load method using .one()
so it only triggers then releases (reset scrollTop when it's completed loading)--but this is a hack at best.
If you're not already (and assuming the images are fixed-height and width) it's "proper" to specify the width/height of an image. This allows the renderer to layout the page (despite missing or updated content), but also prevents any image(s) [re]loading from having adverse effects later on.
精彩评论