[英]button to scroll all the way to the top with click of button
i have this javascript so that when a user is scrolling on the page there will be a small icon to the side that will scroll all the way back up the page rather than manually scrolling. 我有这个javascript,因此当用户在页面上滚动时,侧面会有一个小图标,它将一直滚动到整个页面上,而不是手动滚动。 The button shows fine but when i click on it it is not going all the way to the top.
该按钮显示正常,但是当我单击它时,并不会一直到顶部。
html html
<a href="#" class="scrollup">Scroll</a>
Script 脚本
$(document).ready(function () {
$('#main').scroll(function () {
if ($(this).scrollTop() > 100) {
$('.scrollup').fadeIn();
} else {
$('.scrollup').fadeOut();
}
});
$('.scrollup').click(function () {
$("html, body, main_container, main").animate({ scrollTop: 0 }, 600);
return false;
});
});
problem is in the selectors, you are missing either #
id selector or .
问题是在选择,你缺少要么
#
id选择或.
class selector, to me it seems id: 类选择器,对我来说似乎是id:
change this: 改变这个:
$("html, body, main_container, main")
to this and see if it helps: 为此,看看是否有帮助:
$("html, body, #main_container, #main")
//-------------^----------------^--------these selector notations
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.