[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>
当滚动时
[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]