javascript - jQuery Click anchor tag prevent page from scrolling to top -
i'm doing page transitions jquery fading out content , fading in when page loads problem when click link , call click function , redirecting page loads @ the top of page. there way can prevent behavior? here click function page transition, in advance help!
link
<a href="../categories/categories.php"></a> jquery
$(".content").fadein(750); $("a").click(function(event){ event.preventdefault(); linklocation = this.href; $(".content").fadeout(500, redirectpage); }); function redirectpage() { window.location = linklocation; }
good solution : use history api hashbangs fallback
bad solution: easy hack can capture current scroll position
$(".content").fadein(750); var offset = window.location.href.match(/offset=(\d+)/) if(offset){ $(document).scrolltop(offset[1]) } $("a").click(function(event){ event.preventdefault(); linklocation = this.href + "?offset="+$(document).scrolltop();//pay //special attentions line work link without parameters. $(".content").fadeout(500, redirectpage); }); function redirectpage() { window.location = linklocation; }
Comments
Post a Comment