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

网页版右侧显示浮动二维码代码

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

<!-- 二维码 begin -->
<script type="text/javascript">
 (function(aClz,maxSize,co) {
 var doc = document,
  side = (function() {
   var body = doc.body,
    firstChild = body.firstChild,
    wrap = doc.createElement('div');
   wrap.className = 'side-btns-2w';
   wrap.style.display = 'none';
   wrap.innerHTML = '<a class="side-btns-2w-img" target="_blank" href="http://m.newshainan.com/" title="手机海口视窗" suda-uatrack="key=qr_code&value=news_index_qrcode"><em>手机海口视窗</em> <img src="http://www.newshainan.com//skin/haikou/haikou.png" width="100"> <span>点击或扫描访问</span> </a> <a href="javascript:;" class="side-btns-2w-close" title="关闭" suda-uatrack="key=qr_code&value=news_index_qrcode_close">关闭</a>';
   firstChild ? firstChild.parentNode.insertBefore(wrap, firstChild) : body.appendChild(wrap);
   return wrap;
  })(),
  clz = side.className,
  nClz = clz + ' ' + aClz,
  cookieName = co.name || 'TDCDIS',
  domain = co.domain || 'm.newshainan.com',
  lnks = side.getElementsByTagName('a'),
  close = lnks[lnks.length-1],
  toggle = function(dis) {
   side.style.display = dis;
  }, addEvent = function(o, s, fn) {
   if (o.attachEvent) {
    o.attachEvent('on' + s, fn);
   } else {
    o.addEventListener(s, fn, false);
   }
   return o;
  }, 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;
   }
  };
  // name, value, expire(hour), path, domain, secure
  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!=''){
   toggle('none');
   return;
  }
  toggle('block');
  resize();
  addEvent(window, 'resize', resize);
  addEvent(close,'click',function(e){
   toggle('none');
   cookie.setCookie(cookieName,'1',15*24,'/',domain);
   if(window.event){
    window.event.returnValue = false;
   }else{
    e.preventDefault();
   }
  });

 })('side-btns-2w-resize',1230,{
  name:'TDCDIS',    //cookie名
  domain:'m.newshainan.com'  //domain 根据频道不同
 });
 </script>
<!-- 二维码 end -->

样式代码:

 /*二维码*/
 .side-btns-2w {width:110px;top: 250px;_top:expression(documentElement.scrollTop + 250);left: 50%;margin: 0 0 0 505px;position: fixed;_position:absolute;z-index: 0;overflow: hidden; font: 12px/22px Arial;color:#333;}
 .side-btns-2w em,.side-btns-2w span{font-style: normal;font-weight: normal;line-height: 27px;}
 .side-btns-2w-img{ display:block;width:110px;background: #EBEBEB;line-height: 0;text-align: center;position: relative;zoom:1;}
 .side-btns-2w-img:link,.side-btns-2w-img:visited{color:#333;text-decoration: none;}
 .side-btns-2w-img:hover,.side-btns-2w-img:active{color:#333;text-decoration: none;background: #D1D1D1;}
 .side-btns-2w img{border: 0;display: block; margin:0 auto;padding: 0;}
 .side-btns-2w-close{width:40px;height: 18px;line-height: 80px;margin:0 0 0 70px;display:block;overflow: hidden;background: url(/images/close.jpg) no-repeat;}
 .side-btns-2w-resize{display: none !important;}

  (来源:海南科技网)

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

相关资讯:

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