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]

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

报告相同问题?

悬赏问题

  • ¥23 (标签-bug|关键词-密码错误加密)
  • ¥66 比特币地址如何生成taproot地址
  • ¥20 数学建模数学建模需要
  • ¥15 关于#lua#的问题,请各位专家解答!
  • ¥15 什么设备可以研究OFDM的60GHz毫米波信道模型
  • ¥15 不知道是该怎么引用多个函数片段
  • ¥30 关于用python写支付宝扫码付异步通知收不到的问题
  • ¥15 隐藏系统界面pdf的打印、下载按钮
  • ¥15 基于pso参数优化的LightGBM分类模型
  • ¥15 安装Paddleocr时报错无法解决