回到顶部按钮
本實戰來自個人研究,不一定是最好的!
僅支持IE8及以上版本!
?
HTML:
1 <!--回到頂部 開始--> 2 <div id="to_top" class="to_top"> 3 <i class="to_top_pic"></i> 4 </div> 5 <!--回到頂部 結束-->
?
CSS:
1 /*回到頂部按鈕,切忌初始化不要用float、position(absolute,relative,fixed)等脫離文檔的定位*/ 2 #to_top { 3 width: 50px; 4 height: 50px; 5 margin: 500px 0 0 1020px; 6 background: #efefef; 7 /*position: fixed;*/ 8 /*top: 0;*/ 9 }
?
JS:
/*** 回到頂部* */var toTopDistance = 700;//偵聽滾動事件$(window).on('scroll', function () {//console.log($(document).scrollTop());//console.log(toTopDistance);/*** 滾到一定程度,回到頂部按鈕一直顯示在右上方*/if($(document).scrollTop() >= toTopDistance) {$('#to_top').css({'position': 'fixed','top': 0,'margin': '0 0 0 1020px'});}else {$('#to_top').css({'position': 'static','margin': '500px 0 0 1020px'});}});
?
轉載于:https://www.cnblogs.com/lqcdsns/p/5514976.html
總結
- 上一篇: 数据库SQL优化大总结之百万级数据库优化
- 下一篇: 岩棉板多少钱啊?