-1

我是 jquery 的新手,我创建了一组导航链接,这些链接可以一次单击完成多个功能。加载文件似乎需要很长时间,因此网页对单击的链接做出反应需要很长时间。这可能是因为我有“scrollTo”jquery 插件吗?我附上了一个链接控件的示例,所有链接都是相同的,只是有一些变化。

问题是代码的格式还是代码本身的问题?

   $(".releases").click(function(){
    $('html, body').stop().animate({ scrollTop: 0 }, 3000, function(){ //returns to top of the page
        $("#content").load('content.html #releases'); //loads the content associated with the link
        $("#banner").stop().animate({
            'background-position-x' : '-700px',
            'background-position-y' : '-500px'}, //background image position change
            2000, function()
            {$.scrollTo("#content", 3000); //returns to the main page content
        });     
    });
});
4

1 回答 1

1

我认为您的代码加载速度并不慢,我认为问题在于代码本身。它会在加载其他信息之前尝试返回页面顶部,如果您打开新页面,它将位于顶部,并且需要 3 秒您允许页面滚动回顶部。

$('html, body').stop().animate({ scrollTop: 0 }, 3000, function(){ 

这是你的问题,如果页面已经在顶部,你需要一个 if - else 语句来覆盖初始滚动顶部。

于 2013-10-08T10:16:12.673 回答