[英]Not Working - Header Slide up on scroll down page, and down again on scroll up - jquery
I have the following jQuery where I am attempting to hide the header on scroll down and appear on scroll up, but I cannot get it to work? 我有以下jQuery,我尝试在其中向下滚动隐藏标题并在向上滚动显示标题,但是我无法使其正常工作? All content that will be slideUp etc... is in a header tag
所有将为slideUp等的内容都在标题标签中
$(document).ready( function () {
$(window).scroll(function() {
var currentScrollTop = $(this).scrollTop();
if (currentScrollTop > 80){
$('header').slideUp(200);}
else {
$('header').slideDown(200);}
});
});
I can get the header to disappear with the following code but really struggling to make it functional 我可以使用以下代码使标头消失,但实际上很难使它起作用
$(document).ready( function () {
$('body').scroll(function() {
$('header').slideUp(200);
});
});
Where am I going wrong? 我要去哪里错了? Thanks in advance
提前致谢
I don't get really what is the effect you want to achieve but what you are probably having wrong is the use of window
as a referential for .scroll()
instead of the use of document
. 我并没有真正想获得什么效果,但是您可能会出错的是使用
window
作为.scroll()
的引用而不是document
的引用。
So try instead to use $(document).scroll(function(){...});
因此,请尝试使用
$(document).scroll(function(){...});
as I've tried in this jsFiddle . 正如我在jsFiddle中尝试过的那样 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.