jQuery scrollTop移到错误的位置 [英] Jquery scrollTop goes to the wrong position

查看:219
本文介绍了jQuery scrollTop移到错误的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在带有滚动的div内,当我按下单击我"按钮时,下面的脚本应滚动到文本"SHOULD GO HERE".类似于锚链接.

Inside a div with scroll, when I press the button CLICK ME, the script below should scroll to the text "SHOULD GO HERE". Something similar to an anchor link.

JsFiddle : https://jsfiddle.net/hhqnjojr/2/

相反,脚本将滚动到文本"SHOULD GO HERE"上方的随机位置(?).拜托,我在做什么错了?

Instead, the script scrolls to a random position (?) way above the text "SHOULD GO HERE". Please, what am I doing wrong?

$("#my_button").click(function() {
    $('#wrapper_div').animate({
        scrollTop: $("#go_here").offset().top
    }, 2000);
}); 

推荐答案

$ window.scrollTo(0,0);

$window.scrollTo(0, 0);

在您的点击事件中将此内容写入,它将移至顶部,并根据您的要求给出位置.

Write this in your click event ,this will move to top, give the position according to your requirement.

这篇关于jQuery scrollTop移到错误的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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