当前位置: 首页 > 工具软件 > jQuery.toTop > 使用案例 >

toTop.js回到顶部

黄修永
2023-12-01
jQuery(document).ready(function($) {
	$("<div id='toTop'><img src='/plugin/common/toTop/1.png'></div>").appendTo('body');
	$("#toTop").css({
		width: '50px',
		height: '50px',
		bottom:'100px',
		right:'15px',
		position:'fixed',
		cursor:'pointer',
		zIndex:'999',
	});
	if($(this).scrollTop()==0){
		$("#toTop").hide();
	}
	$(window).scroll(function(event) {
		/* Act on the event */
		if($(this).scrollTop()==0){
			$("#toTop").hide();
		}
		if($(this).scrollTop()!=0){
			$("#toTop").show();
		}
	});
	$("#toTop").click(function(event) {
		/* Act on the event */
		$("html,body").animate({
			scrollTop:"0px"},
			800
			)
	});
});

 

 类似资料: