【发布时间】:2015-04-18 14:19:55
【问题描述】:
基本上我正在制作一个返回顶部按钮,但我无法显示该按钮。
这是我的代码:
JavaScript:
$(document).ready(function() {
var btt = $('.back-to-top');
$(window).on('scroll', function () {
var self = $(this),
height = self.height(),
top = self.scrollTop();
if(top > height) {
if(!btt.is(':visible')) {
btt.show();
}
} else {
btt.hide();
}
});
});
HTML:
<a href="#" class="back-to-top">Back to top</a>
【问题讨论】:
-
什么是你的 html 中的 back-to-top?是按钮的id还是class?
-
@Stamen 它的类。我已将其添加到问题中
-
有可能是链接显示了,但是不可见,因为你已经滚动到页面底部了。换句话说,链接可能不会随着 html 中的滚动而移动。我建议你添加一些 console.log 或 alert 调试消息来看看发生了什么。
标签: javascript jquery