您的位置:海南科技网首页 > 建站经验 > 正文

网页返回顶部代码

2017-08-23 22:29:07 来源:海南科技网 繁体中文 关闭 收藏 打印 复制

<!-- 返回顶部 begin -->
<script type="text/javascript">
 // 返回顶部js
 (function(aClz,maxSize,co) {
  var doc = document, side = (function() {var body = doc.body, firstChild = body.firstChild, wrap = doc.createElement('div'); wrap.className = 'side-btns-wrap'; wrap.innerHTML = '<div class="side-btns-top"><a class="side-btns-top-btn" href="javascript:;" title="返回顶部" suda-uatrack="key=channel_index_up_to_top&value=news" hidefocus>返回顶部</a><a class="side-btns-top-close" href="javascript:;" title="关闭" suda-uatrack="key=channel_index_up_to_top&value=news_close" hidefocus>关闭</a></div>'; firstChild ? firstChild.parentNode.insertBefore(wrap, firstChild) : body.appendChild(wrap); return wrap; })(), clz = side.className, nClz = clz + ' ' + aClz, cookieName = co.name || 'close_newsidxtop', domain = co.domain || 'm.newshainan.com', path = co.path|| '/', lnks = side.getElementsByTagName('a'), btn = lnks[0], close = lnks[1], addEvent = function(o, s, fn) {if (o.attachEvent) {o.attachEvent('on' + s, fn); } else {o.addEventListener(s, fn, false); } return o; }, toggle = function() {var top = doc.documentElement.scrollTop || doc.body.scrollTop, visible = (top > 0 ? 'visible' : 'hidden'); side.style.visibility = visible; }, sideToggle = function(dis) {side.style.display = dis; }, resize = function() {var body = doc.documentElement || doc.body; if (!body) {return; } var width = body.offsetWidth; if (width < maxSize) {side.className = nClz; } else {side.className = clz; } }, toTop = function() {doc.documentElement.scrollTop = 0; doc.body.scrollTop = 0; }; var cookie = (function() {var co = {}; co.getCookie = function(name) {name = name.replace(/([.[]$])/g, '\$1'); var rep = new RegExp(name + '=([^;]*)?;', 'i'); var co = document.cookie + ';'; var res = co.match(rep); if (res) {return unescape(res[1]) || ""; } else {return ""; } }; co.setCookie = function(name, value, expire, path, domain, secure) {var cstr = []; cstr.push(name + '=' + escape(value)); if (expire) {var dd = new Date(); var expires = dd.getTime() + expire * 3600000; dd.setTime(expires); cstr.push('expires=' + dd.toGMTString()); } if (path) {cstr.push('path=' + path); } if (domain) {cstr.push('domain=' + domain); } if (secure) {cstr.push(secure); } document.cookie = cstr.join(';'); }; co.deleteCookie = function(name) {document.cookie = name + '=;' + 'expires=Fri, 31 Dec 1999 23:59:59 GMT;'; }; return co; })(); var display = cookie.getCookie(cookieName); if(display!=''){sideToggle('none'); return; } sideToggle('block'); resize(); addEvent(window, 'resize', resize); addEvent(close,'click',function(e){sideToggle('none'); cookie.setCookie(cookieName,'1',15*24,path,domain); if(window.event){window.event.returnValue = false; }else{e.preventDefault(); } }); addEvent(window, 'scroll', toggle); addEvent(btn, 'click', toTop); })('side-btns-wrap-resize',1110,{
  name:'close_newsidxtop',    //cookie名
  domain:'m.newshainan.com' //domain 根据频道不同
 });
 </script>

<!-- 返回顶部 end -->

样式代码:

 /*返回顶部*/
 .side-btns-wrap{width:50px;left: 50%; margin-left:505px;position: fixed;bottom: 40px; _position:absolute;_top:expression(documentElement.scrollTop + documentElement.clientHeight-120);z-index:100;visibility: hidden;overflow: hidden;}
 .side-btns-top{width:50px;}
 .side-btns-top a{display: block; line-height:500px; cursor:pointer;}
 .side-btns-top-btn { height: 50px; width: 50px;background:url(/images/news_zxh_content_btn_bg.png) no-repeat 0 -110px;  filter:Alpha(Opacity=35); opacity:.35; overflow:hidden;}
 .side-btns-top-btn:hover {filter:Alpha(Opacity=50); opacity:.5;}
 .side-btns-top-close{width: 50px;height: 18px;margin-top:1px;background: url(/images/close2.png) no-repeat;}
 .side-btns-wrap-resize{display: none !important;}

  (来源:海南科技网)

版权声明:
1.本站登载此文仅出于传递更多信息,并不意味着赞同其观点或证实其描述,不承担侵权行为的连带责任。
2.如本网信息涉及版权等问题,请于发布起15个工作日内发送邮件与本网联系,我们将及时删除处理。

相关资讯:

版权声明:
1.本站登载此文仅出于传递更多信息,并不意味着赞同其观点或证实其描述,不承担侵权行为的连带责任。
2.如本网信息涉及版权等问题,请于发布起15个工作日内发送邮件与本网联系,我们将及时删除处理。