jQuery或JS,使元素离开屏幕底部并在顶部输入
jQuery or JS, make element leave the screen on bottom and enter on top
我们一直在寻找解决方案,但找不到类似的解决方案。正如标题所说,我将导航绝对定位在屏幕的最底部,但当用户到达底部时,我希望导航"向下滑动",并显示在顶部。
我的逻辑是查看用户获得的屏幕高度,这样我就只能动画化一个css属性。
这是我写的不起作用的代码
if ( (topDistance-10) < scrollTop ) {
//Navigation control
var navHeight = $(window).height();
$(".navigation").animate({bottom: -64},600).delay(1000).css('bottom' , navHeight).delay( 3500 ).animate({bottom: navHeight - 64},600);
}
HTML:
<ul class="navigation stickBottom">
<li data-slide="1"><a href="">home</a></li>
<li data-slide="2"><a href="">truth</a></li>
<li data-slide="3"><a href="">about</a></li>
<li data-slide="4"><a href="">contact</a></li>
</ul>
css:
.navigation {
position: fixed;
z-index: 3;
bottom: 0;
width: 100%;
left: 0;
padding: 15px 0 15px 20px;
background-color: rgba(0, 0, 0, 0.75);
}
.navigation li{
color:#fff;
display: inline-block;
padding: 0 10px;
line-height:30px;
margin-bottom:2px;
font-weight:bold;
-webkit-transition: all .2s ease-in-out;
text-align:left;
font-size:26px;
}
试着像这样使用
var body = $("html, body");
body.animate({scrollTop:0}, '500', 'swing', function() {
alert("Finished animating");
});
参见此示例http://jsfiddle.net/hellosze/MMgXu/
好的,谢谢你的帮助,这就是我需要的
// 1. Hide On Bottom
$(".navigation").animate({bottom: -64},200);
// 2. Switch to top
setTimeout(function() {
$(".navigation").attr('style' , 'bottom:' + navHeight + 'px');
},300);
// 3. Show on top
setTimeout(function() {
$(".navigation").animate({bottom: navHeight - 64},200);
},400);
相关文章:
- 如何将图表放在顶部和底部
- 滚动到顶部或底部后的简单效果
- 如何使一个元素从网页的顶部跳到底部再跳回到顶部
- 垂直与特定边距的顶部和底部对齐
- HTML导航在屏幕底部,并粘贴到顶部
- 粘贴Bootstrap在粘贴底部到达并滚动回顶部后闪烁
- 我们如何在fullPage.js中为不同的部分制作不同的填充顶部和底部值
- 当在堆栈底部添加ImageView时,我想删除RelativeLayout中的顶部ImageView,但它正在删除整个布
- 为什么javascript在页面底部或有时在页面顶部运行
- 使手风琴/可折叠中的 DIV 保持固定在页面的顶部和底部
- 如何使用 jQuery 检测元素的顶部靠近浏览器底部
- 如何在滚动到底部后在页脚上方设置“返回顶部”
- Div 在页眉到达其顶部时开始滚动,当其底部到达页脚时停止滚动
- 在 jquery 中滚动到顶部并滚动到底部
- 当您离开页面底部 100 像素时,淡出“滚动到顶部”按钮
- 用于页面更改的煎茶静态顶部和底部栏
- 当在 Ul 上使用向上/向下箭头到达溢出自动项目的顶部/底部时显示隐藏的项目
- 不是将新列表项推到底部,而是推到顶部
- 检测(事件)尝试在使用JavaScript或AngularJS页面顶部/底部时向上/向下滚动
- 滚动到顶部/底部按钮错误