当前位置: 编程技术>jquery
jquery鼠标下拉滚动置顶效果的例子
来源: 互联网 发布时间:2014-10-09
本文导语: 如何用jquery实现鼠标下拉滚动置顶效果?来看一个例子。 完整代码: $(function(){ //置顶按钮显示/隐藏实现 $(window).scroll(function(){ var w_height = $(window).height();//浏览器高度 var scroll_top = $(document).scrollTop();//滚...
如何用jquery实现鼠标下拉滚动置顶效果?来看一个例子。
完整代码:
$(function(){
//置顶按钮显示/隐藏实现
$(window).scroll(function(){
var w_height = $(window).height();//浏览器高度
var scroll_top = $(document).scrollTop();//滚动条到顶部的垂直高度
if(scroll_top > w_height){
$("#goto-top").fadeIn(500);
}else{
$("#goto-top").fadeOut(500);
}
});
//置顶
$("#goto-top").click(function(e){
e.preventDefault();
$(document.documentElement).animate({
scrollTop: 0
},200);
//支持chrome
$(document.body).animate({
scrollTop: 0
},200);
});
}) // www.
#goto-top {
display:none;
position:fixed;
width:38px;
height:36px;
background:url(/tech-jquery/images/goto-top.png) no-repeat 0 0;
bottom:40px;
right:40px;
-webkit-transition:all 0.2s;
-moz-transition:all 0.2s;
-o-transition:all 0.2s;
transition:all 0.2s;
z-index:9999;
}
#goto-top:hover {
background:url(/tech-jquery/images/goto-top.png) no-repeat 0 -36px;
}