=========== HTML ===========
<div class="button_top"></div>
=========== CSS ===========
.button_top {
background: url("../images/top_png.png") no-repeat scroll 0 0 rgba(0, 0, 0, 0);
bottom: 70px;
height: 70px;
position: fixed;
right: 22px;
width: 70px;
display: none;
cursor: pointer;
}
=========== JS ===========
var offset = 220;
var duration = 500;
$(window).scroll(function() {
console.log($(window).width());
if($(window).width()<1190){
$(".button_top").remove();
}
if ($(this).scrollTop() > offset) {
$('.button_top').fadeIn(duration);
} else {
$('.button_top').fadeOut(duration);
}
});
$(".button_top").click(function(event){
event.preventDefault();
$('html, body').animate({scrollTop: 0}, duration);
return false;
});
Không có nhận xét nào:
Đăng nhận xét