FORK ME

console 命令行工具 X clear

                    
>
console
jQuery(document).ready(function($) {	
			if($("meta[name=toTop]").attr("content")=="true"){
				$("<div id='toTop'><img src='http://ossweb-img.qq.com/images/chanpin/v2/public/jq_demo/images/back.png'></div>").appendTo('body');
				$("#toTop").css({
					width: '50px',
					height: '50px',
					bottom:'10px',
					right:'15px',
					position:'fixed',
					cursor:'pointer',
					zIndex:'999999',
				});
				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"},
									500
									)
							});
				}
		});
<meta name="toTop" content="true"> 
<!-- meta需要添加在头部 -->
 <div>向下滚动查看效果</div>
* { margin:0; padding:0}
html {
height:1000px;
font-family: "Microsoft Yahei", "SimSun", "Arial";
background:#fff;
}

本项目引用的自定义外部资源