meiyourena 2013-10-17 10:51
浏览 252
已采纳

jquery滚动

[code="js"]
;(function($){ //开始前加分号是为了兼容性;此处$作为匿名函数的形参
//返回顶部
$.fn.toTop = function(options){
var options=$.extend({bottom:"30%",right:100,showHeight:20},options);
this.css("bottom",options.bottom);
this.css("right",options.right+'px');
this.css("visibility","hidden");
$(this).addClass('top topStyle');
$this=$(this);
$(window).scroll(function(){
if($(window).scrollTop>=options.showHeight)$this.css("visibility","visible");
else $this.css("visibility","hidden");
});
$(this).click(function(){
$(window).scroll(0);
});
return this;
}
})(jQuery)
[/code]
[code="html"]
<!DocType html>






置顶
<br> $(function(){<br>   $(&quot;#divToTop&quot;).toTop();<br> });<br>



这是内容
这是内容
这是内容
这是内容
这是内容
这是内容
这是内容
这是内容
这是内容

这是内容
这是内容
这是内容
这是内容
这是内容
这是内容
这是内容
这是内容
这是内容

这是内容
这是内容
这是内容
这是内容
这是内容
这是内容
这是内容
这是内容
这是内容

这是内容
这是内容
这是内容
这是内容
这是内容
这是内容
这是内容
这是内容
这是内容

这是内容
这是内容
这是内容
这是内容
这是内容
这是内容
这是内容
这是内容
这是内容



[/code]
[code="css"]
.topStyle
{
background-color: transparent;
cursor: pointer;
position: fixed;
}
.top
{
background: url(img/gotop.png);
height: 48px;
width: 48px;
background-position: 102px 48px;
}
.top:hover
{
background: url(img/gotop.png);
height: 48px;
width: 48px;
background-position: 102px 0px;
}
[/code]

当滚动时

没有出现
  • 写回答

1条回答 默认 最新

  • iteye_13122 2013-10-21 17:48
    关注

    [code="js"]if($(window).scrollTop>=options.showHeight)$this.css("visibility","visible");

    else $this.css("visibility","hidden"); [/code]

    这段代码需要改成:

    [code="js"]if($(window).scrollTop()>=options.showHeight)$this.css("visibility","visible");

    else $this.css("visibility","hidden"); [/code]

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?