ซึ่งวันนี้เองผมมี Code Back to top (แบล็คทูท็อป) ดีๆมาฝากกันซึ่งจะไม่แสดงเมื่อท่านอยุ่ส่วนบนของเว็บไซต์แต่จะปรากฏเมื่อเลื่อนลงข้างล่างมาเริ่มกันเลยดีกว่า
ก่อนอื่นเลยให้ท่านไปใส่ id ให้ body
โค้ด: เลือกทั้งหมด
<body id="top">
โค้ด: เลือกทั้งหมด
<p id="back-top">
<a href="#top">
<span style="color: white;" class="glyphicon glyphicon-arrow-up pondtoptoptop"></span>
Back to Top
</a>
</p>
โค้ด: เลือกทั้งหมด
#back-top {
position: fixed;
bottom: 15px;
/*margin-left: -150px;*/
right: 20px;
}
#back-top a {
/*width: 60px;*/
display: block;
text-align: center;
font: 11px/100% Arial, Helvetica, sans-serif;
/*text-transform: uppercase;*/
text-decoration: none;
color: black;
font-weight:bold;
opacity: 0.9;
/* transition */
-webkit-transition: 1s;
-moz-transition: 1s;
transition: 1s;
}
#back-top a:hover {
color: #000;
}
/* arrow icon (span tag) */
#back-top span {
width: 60px;
height: 60px;
display: block;
margin-bottom: 7px;
background: #ddd url(up-arrow.png) no-repeat center center;
/* rounded corners */
-webkit-border-radius: 15px;
-moz-border-radius: 15px;
border-radius: 15px;
/* transition */
-webkit-transition: 1s;
-moz-transition: 1s;
transition: 1s;
}
#back-top a:hover span {
background-color: #005419;
}
โค้ด: เลือกทั้งหมด
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js"></script>
<script>
$(document).ready(function(){
// hide #back-top first
$("#back-top").hide();
// fade in #back-top
$(function () {
$(window).scroll(function () {
if ($(this).scrollTop() > 150) {
$('#back-top').fadeIn();
} else {
$('#back-top').fadeOut();
}
});
// scroll body to 0px on click
$('#back-top a').click(function () {
$('body,html').animate({
scrollTop: 0
}, 1100);
return false;
});
});
});
</script>