2013-05-14 155 views
1

我正在做页面转换与jQuery通过淡出内容和淡出当页面加载,但我的问题是当我点击我的链接,并调用我的点击功能和重定向它加载在页面顶部的页面。有没有办法阻止这种行为?这是我的页面转换的点击功能,预先感谢任何帮助!jQuery单击锚标记防止页面滚动到顶部

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; 
} 
+1

你能提供的标记,如果你创建新的拨弄,看看它是如何工作的将是巨大的。 – vitozev 2013-05-14 06:24:21

+0

听起来像你需要风格的标记。 'javascript'工作正常。 – 2013-05-14 06:25:52

回答

1

良好的解决方案:使用历史API与hashbangs后备

不好解决: 作为一种简单的黑客,你可以捕捉当前的滚动位置

$(".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 to this line will work only for a link without get parameters. 
     $(".content").fadeOut(500, redirectPage); 
    }); 

    function redirectPage() { 
     window.location = linkLocation; 
    } 
+0

非常感谢你,我会用int和hashbang来看待int,但这也是一个很好的小黑客,谢谢! – 2013-05-14 07:22:03

相关问题