凌的博客

您现在的位置是:首页  > 前端学习 > JQuery

JQuery

jQuery回到头部

2015-04-03JQuery0
var GotoTop = { setPos:function(width){ var win = $(window); var win_width = $(window).width(); $(\"#backToTop\").css({ left: parseInt(win_width - (win_width-width)/2)+2, bottom:150 });
var GotoTop = {
	setPos:function(width){
		var win = $(window);
		var win_width = $(window).width();
		$("#backToTop").css({
			left: parseInt(win_width - (win_width-width)/2)+2,
			bottom:150
		});
	},
	bind:function(){
		$("#backToTop").click(function(){
			//$("html,body").scrollTop(0);
			$("html,body").animate({ scrollTop: 0 },240);	
		});
		$(window).scroll(function(){
			if($(document).scrollTop() > 500){
				$("#backToTop").css("display","block");
			}else{
				$("#backToTop").css("display","none");
			}
		});
	},
	init:function(width){
		$('').appendTo("body");	
		GotoTop.setPos(width);
		$(window).resize(function(){
			GotoTop.setPos(width);
		});
		GotoTop.bind();
	}
};

//返顶效果
$(function(){
  GotoTop.init(960);
});

如果本文对您有所帮助,请支持下本站哦!!!^_^

文章评论

0条评论