jQuery scrolltop - 首次使用后无法正常工作 [英] jQuery scrolltop - not working after first use

查看:113
本文介绍了jQuery scrolltop - 首次使用后无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在此菜单上使用jQuery scrolltop功能: http://goethesternfriseure.de/index.php

i am using jQuery scrolltop function on this menu: http://goethesternfriseure.de/index.php

问题是滚动功能仅在第一次工作。在第二次点击链接后,它会滚动到底部。

the issue is that the scroll function is only working at the first time. after a second click on a link, it scrolls to much to the bottom.

$('.sectionlink').click(function(e){
            var sectionelement = $(this).attr("rel");
            var myoffset = $('#'+sectionelement).offset().top;
            $('html, body').animate({
                scrollTop: myoffset
            }, 800);

            e.preventDefault();
        });

有谁知道那里发生了什么?

does anyone know whats happening there?

推荐答案

您的滚动顶部无法正常工作,因为您必须添加px:

your scroll top is not functioning cause you have to add "px" :

$('.sectionlink').click(function(e){
            var sectionelement = $(this).attr("rel");
            var myoffset = $('#'+sectionelement).offset().top;
            $('html, body').animate({
                scrollTop: myoffset+"px"
            }, 800);

            e.preventDefault();
        });

这篇关于jQuery scrolltop - 首次使用后无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆