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]

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

报告相同问题?

悬赏问题

  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式