一个简易的“返回顶部”页面效果
2017-07-27 11:21
411 查看
参考的廖大神的实现方法:https://www.liaoxuefeng.com/article/0013738939371174a66d9fcf5094b1dbf28e9e9ccbf9d61000
当网页页面过长时,查看内容多有不便,因此大多数的网页都实现了一个“返回顶部”的功能按钮。
以下使用的是html+css+js实现的“返回顶部”功能。
1.在html页面中嵌入“返回顶部”的部件
设置left:92%控制部件在整个页面靠右位置。
设置border-radius为width(height)的一半,让部件呈现为圆形。
3.js控制部件的show与hide
并且设置点击之后1000ms返回顶部。
demo下载地址:http://download.csdn.net/detail/somehow1002/9912094
当网页页面过长时,查看内容多有不便,因此大多数的网页都实现了一个“返回顶部”的功能按钮。
以下使用的是html+css+js实现的“返回顶部”功能。
1.在html页面中嵌入“返回顶部”的部件
<div class="go-top"> <div class="arrow"></div> <div class="stick"></div> </div>2.css中定义该部件的形态
.go-top { display: none; opacity: 0.6; z-index: 999999; position: fixed; bottom: 40px; left: 92%; margin-left: 40px; border: 1px solid #a38a54; width: 50px; height: 50px; background-color: #bfc092; border-radius: 25px; cursor: pointer; } .go-top:hover { opacity: 1; filter: alpha(opacity=100); } .go-top div.arrow { position: absolute; left: 15px; top: 3px; width: 0; height: 0; border: 9px solid transparent; border-bottom-color: #0066cc; } .go-top div.stick { position: absolute; left: 20px; top: 20px; width: 8px; height: 14px; display: block; background-color: #0066cc; -webkit-border-radius: 1px; -moz-border-radius: 1px; border-radius: 1px; }
设置left:92%控制部件在整个页面靠右位置。
设置border-radius为width(height)的一半,让部件呈现为圆形。
3.js控制部件的show与hide
$(function() { $(window).scroll(function() { if ($(window).scrollTop() > 600) $('div.go-top').show(); else $('div.go-top').hide(); }); $('div.go-top').click(function() { $('html, body').animate({scrollTop: 0}, 1000); }); });当页面浏览到600px之后,跳出“返回顶部”部件。
并且设置点击之后1000ms返回顶部。
demo下载地址:http://download.csdn.net/detail/somehow1002/9912094
相关文章推荐
- JS实现效果-点击按钮返回到页面顶部
- jquery实现页面常用的返回顶部效果
- [转载] jQuery实现一个动画版返回顶部和底部的效果
- HTML页面实现返回顶部效果 go to top
- 一个带微博按钮的jquery返回顶部效果代码
- 如何实现“返回顶部”的页面效果
- 使用js写点击一个事件使页面返回顶部以及控制一个元素在右下角的固定位置的方法
- 如何实现“返回顶部”的页面效果
- 一个简单的返回顶部效果
- 返回页面顶部top按钮通过锚点实现(自写)
- 写一个JavaScript“返回顶部”功能
- JS实现部分HTML固定页面顶部随屏滚动效果
- 常用组件之侧栏菜单滑动及返回顶部效果
- 三款简单的JS返回页面顶部代码
- Js返回页面顶部
- 仿CSDN Blog返回页面顶部功能
- 小程序实现页面顶部选项卡效果
- 网页页面“返回到顶部”
- Multiple-View ViewPager-如何实现Viewpager控件的一个页面展示多个page以及回弹效果