我可以在页面的顶部或底部滚动。但是5秒后,我想要我的滚动disapear。我使用Jquery的属性延迟&隐藏。我必须刷新我的页面,以便在我的div关闭后运行我的代码。
$(function () {
var scrollTrigger = 100, // px
backToTop = function () {
var scrollTop = $(window).scrollTop();
if (scrollTop > scrollTrigger) {
$("a[href='#top']").addClass('show').delay(2000).hide(500);
$("a[href='#bottom']").addClass('show').delay(2000).hide(500);
} else {
$("a[href='#top']").removeClass('show');
$("a[href='#bottom']").removeClass('show');
}
};
backToTop();
$(window).on('scroll', function () {
backToTop();
});
$("a[href='#top']").click(function() {
$("html, body").animate({ scrollTop: 0 }, "slow");
return false;
});
$("a[href='#bottom']").click(function() {
$('html,body').animate({ scrollTop: 9999 }, 'slow');
return false;
});
});发布于 2017-03-29 08:29:42
使用setTimeout()函数。参考
settimeout.asp,https://www.sitepoint.com/jquery-settimeout-function-examples/
示例
backToTop = function () {
$("a[href='#top']").show(500);
$("a[href='#bottom']").show(500);
setTimeout(function() {
$("a[href='#top']").hide(500);
$("a[href='#bottom']").hide(500);
}, 5000)
};发布于 2017-03-29 09:01:17
这里有一个函数:
var goToTop = function(){
window.scrollTo(0,/*y-coordinate (should be 0 if well-designed website)*/);
setTimeout(function(){$(this).hide(500);},5000);
}将其用作按钮上的单击事件绑定,如下所示:
$(document).ready(
$(my button JQ selector).click(goToTop);
);然后,当你滚动,你应该再次显示(500)‘它。
https://stackoverflow.com/questions/43087712
复制相似问题