Nút lên đầu trang hầu như trang website nào cũng có vì nó khá đơn giản chứ không phức tạp gì. Cơ chế của nó khi trang được cuộn xuống dưới nút Back to Top hiện ra còn khi lên đầu trang thì nút Back to Top sẽ ẩn đi. Ngoài ra khi click vào nút trang sẽ cuộn lên đầu.
Xem DEMO: www.son.pro.vn
Bước 1: Đăng nhập và mẫu tìm thẻ </body>
Bước 2: Chèn cod JavaScript sau, vào trước thẻ </body>
<style>.bt-top,.bt-bottom,.bt-home{border-radius:50px;visibility:hidden;background-color:#e9b144;width:40px;height:40px;text-align:center;line-height:36px;position:fixed;bottom:10px;right:10px;z-index:999;cursor:pointer;opacity:0;-webkit-transform:translateZ(0);transition:all .3s}.bt-home{bottom:10px!important;visibility:visible;opacity:.8;background:#333}.bt-top.show{visibility:visible;opacity:.8}.bt-bottom{opacity:.8;visibility:visible}.bt-top i,.bt-bottom i{font-size:22px;color:#fff;position:absolute;top:9px;left:13px}.bt-home i{font-size:17px;top:12px;left:12px;color:#fff;position:absolute}.bt-bottom i{top:10px}.bt-top:hover,.bt-bottom:hover,.bt-home:hover{opacity:1}.blog-footer-widgets{color:#ccc;clear:both;background:#323232;font-size:15px;padding:10px 0}#bp_toc a{color:#222}#bp_toc a:hover{color:#333}#footer-colleft{width:68%;float:left;margin:0;padding:0}#st-postleft{width:69%;float:left;margin:0;padding:0;position:relative;overflow:hidden}#st-sidebar-wrapper{width:30%;float:right;margin:0;padding:0}#colleft1{width:48%;float:left;margin:0;padding:0}#colleft2{width:48%;float:right;margin:0;padding:0}#colright{width:30%;float:right;margin:0;padding:0}#st-post-wrapper{max-width:1200px;width:100%;margin:0 auto;padding:0;overflow:hidden;margin-top:65px}#comments,.footer .widget,.sidebar .widget,.bt-top,.bt-bottom,.bt-home{box-shadow:0 1px 0 rgba(0,0,0,.05),0 3px 3px rgba(0,0,0,.05)}.st-hide{display:none}</style>
<div class='bt-top' title='Lên trên'><i class='fa fa-angle-up'/></div>
<div class='bt-bottom' title='Xuống dưới'><i class='fa fa-angle-down'/></div>
<script type='text/javascript'>
//<![CDATA[
// Back to Top, Down, Home
(function(){$(document).ready(function(){return $(window).scroll(function(){return $(window).scrollTop()>750?$(".bt-top").addClass("show"):$(".bt-top").removeClass("show")}),$(".bt-top").click(function(){return $("html,body").animate({scrollTop:"0"})})})}.call(this));(function(){$(document).ready(function(){return $(window).scroll(function(){return $(window).scrollTop()>750?$(".bt-bottom").addClass("st-hide"):$(".bt-bottom").removeClass("st-hide")}),$(".bt-bottom").click(function(){return $("html,body").animate({scrollTop:"99999"})})})}.call(this));
//]]>
</script>

Bước 3: Lưu lại và kiểm tra kết quả
Xin cảm ơn!

No comments