jquery 滚动 fadeIn 页脚,隐藏在页面底部
我有一个带有“更多”提示的页脚,该提示会淡入以提示用户下面有更多内容。
如果有更多内容(您需要向下滚动才能看到),它会在页面加载时淡入文档顶部。
如果页面下方没有更多内容可供滚动,则它不会淡入(如果加载时所有内容都适合窗口)。这是成功的。
我已经将其编写为当到达页面底部的段落时不会淡入。因此,如果您需要向下滚动才能看到内容,它会淡入,直到您到达页面末尾(由段落“#last”表示)。这部分将不起作用。
想法将不胜感激。
HTML页脚:
<footer id="fixedmore">
<p>more</p>
<div class="downArrow">
</div>
</footer>
HTML最后一段
<p id="last">
THE END
</p>
CSS固定页脚
#fixedmore
{
width:100%;
height:30px;
left:0px;
bottom:0px;
position:fixed;
color:white;
text-align:center;
text-shadow:0px 0px 4px rgba(0,0,0,0.5);
font-weight:500;
font-size:14px;
/* fallback/image non-cover color */
background-color:rgba(0,0,0,0.3);
/* Safari 4+, Chrome 1-9 */
background-image: -webkit-gradient(linear, 0% 0%, 0% 100%, from(rgba(0,0,0,0.5)), to(rgba(0,0,0,0.05)));
/* Safari 5.1+, Mobile Safari, Chrome 10+ */
background-image: -webkit-linear-gradient(top, rgba(0,0,0,0.5), rgba(0,0,0,0.05));
/* Firefox 3.6+ */
background-image: -moz-linear-gradient(top, rgba(0,0,0,0.5), rgba(0,0,0,0.05));
/* IE 10+ */
background-image: -ms-linear-gradient(top, rgba(0,0,0,0.5), rgba(0,0,0,0.05));
/* Opera 11.10+ */
background-image: -o-linear-gradient(top, rgba(0,0,0,0.5), rgba(0,0,0,0.05));
}
.downArrow
{
width:0;
height:0;
border-left:50px solid transparent;
border-right:50px solid transparent;
border-top:10px solid white;
margin:auto;
}
CSS最后一段
#last
{
text-align:center;
font-size:10px;
}
JQuery窗口滚动
$(window).scroll(function(){
$('#fixedmore').hide();
var distanceTop = $('#last').offset().top - $(window).height();
if ($(window).scrollTop() < distanceTop){
$('#fixedmore').fadeIn(3000);
}
else{
$('#fixedmore').hide();
};
});
I have a footer with a "more" prompt that fades in to prompt the user there is more content below.
It fades in on page loading, at the top of the document, if there is more content (that you need to scroll down to see).
If there is no more content down the page to scroll to it doesn't fade in (if all the content there is fits into the window at load). This is successful.
I have written it to not fade in when it gets to a paragraph at the bottom of the page. So if there is content you need to scroll down to see, it will fade in until you get to the end of the page (signaled by the paragraph '#last'). This part will not work.
Ideas would be greatly appreciated.
HTML footer:
<footer id="fixedmore">
<p>more</p>
<div class="downArrow">
</div>
</footer>
HTML last paragraph
<p id="last">
THE END
</p>
CSS fixed footer
#fixedmore
{
width:100%;
height:30px;
left:0px;
bottom:0px;
position:fixed;
color:white;
text-align:center;
text-shadow:0px 0px 4px rgba(0,0,0,0.5);
font-weight:500;
font-size:14px;
/* fallback/image non-cover color */
background-color:rgba(0,0,0,0.3);
/* Safari 4+, Chrome 1-9 */
background-image: -webkit-gradient(linear, 0% 0%, 0% 100%, from(rgba(0,0,0,0.5)), to(rgba(0,0,0,0.05)));
/* Safari 5.1+, Mobile Safari, Chrome 10+ */
background-image: -webkit-linear-gradient(top, rgba(0,0,0,0.5), rgba(0,0,0,0.05));
/* Firefox 3.6+ */
background-image: -moz-linear-gradient(top, rgba(0,0,0,0.5), rgba(0,0,0,0.05));
/* IE 10+ */
background-image: -ms-linear-gradient(top, rgba(0,0,0,0.5), rgba(0,0,0,0.05));
/* Opera 11.10+ */
background-image: -o-linear-gradient(top, rgba(0,0,0,0.5), rgba(0,0,0,0.05));
}
.downArrow
{
width:0;
height:0;
border-left:50px solid transparent;
border-right:50px solid transparent;
border-top:10px solid white;
margin:auto;
}
CSS last paragraph
#last
{
text-align:center;
font-size:10px;
}
JQuery window scroll
$(window).scroll(function(){
$('#fixedmore').hide();
var distanceTop = $('#last').offset().top - $(window).height();
if ($(window).scrollTop() < distanceTop){
$('#fixedmore').fadeIn(3000);
}
else{
$('#fixedmore').hide();
};
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想您会发现它确实会触发,但是滚动顶部事件会在您开始滚动时触发,而不是在您停止时触发,这正是您想要的。您可以测试一下:如果您滚动到页面底部,停止,然后稍微滚动一下以使 #last 保持可见,您应该会看到 #fixedmore 保持隐藏状态。问题是,大多数时候你的用户会从更远的地方滚动到#last,所以它不会触发。
James Padolsey 的此插件允许对于特殊的滚动事件,如scrollStart 和(更重要的是!)scrollEnds。试一试!
I think you'll find it does fire, but the scrollTop event fires when you start scrolling, not when you stop, which is what you want. you can test this: if you scroll to the bottom of your page, stop, and then scroll around just a little bit so that #last remains visible, you should see that #fixedmore stays hidden. The problem is, most of the time your users will be scrolling into #last from further away, so it won't fire.
This plugin by James Padolsey allows for special scroll events like scrollStart and (more importantly!) scrollEnds. Give it a whirl!