内容滚动javascript错误,内容在到达页面时继续滚动

时间:2017-08-10 23:01:44

标签: javascript jquery html css

这是javascript&的CSS:

    $(document).ready(function() {

    /* Every time the window is scrolled ... */
    $(window).scroll( function(){

        /* Check the location of each desired element */
        $('.content-scroll').each( function(i){

            var bottom_of_object = $(this).position().top + $(this).outerHeight();
            var bottom_of_window = $(window).scrollTop() + $(window).height();

            /* Adjust the "200" to either have a delay or that the content starts fading a bit before you reach it  */
            bottom_of_window = bottom_of_window + 800; 

            /* If the object is completely visible in the window, fade it it */
            if( bottom_of_window > bottom_of_object ){

                $(this).animate({'margin-top':'0'},10000);

            }

        }); 

    });

});

CSS:

.content-scroll { margin-top: 1000px; }

我正在制作一个简单的单页wordpress商店网站,并且在滚动到某个页面的某个点时我遇到的脚本存在问题。

关于 - 服务 - 联系 - 商店

每个链接正确加载页面的相关部分,效果流畅,但在加载内容时,我已实现了一些javascript,因此每个部分内容本身都会向上滚动,因为您可以在此处看到我的示例测试网站:

http://test.flixonstudios.co.uk/

当点击商店链接时,它会加载页面上的最后一个部分......但正如您所看到的,它有点抖动,如果您稍微向上滚动,滚动脚本仍然会发生。

有人可以推荐如何制作它,例如,点击商店链接,它上面的所有内容都会立即加载,而不是滚动?

这个概念是让用户经历每个部分,一次一个,但是一旦有人查看了所有内容,然后返回到他们想要直接进入商店部分的网站。

任何反馈意见。谢谢你的阅读。

1 个答案:

答案 0 :(得分:0)

您可以删除所有滚动事件处理程序,只需让部分/导航按钮(About,Services ..等)具有锚点标记,该标记在href属性中具有与您想要的页面部分对应的哈希值导航到,例如在您的联系人部分中,只需在与此部分对应的h2元素中添加“联系人”ID,然后为导航按钮(“联系人”)指定一个标记{href of { {1}}