当前位置: 移动技术网 > IT编程>开发语言>JavaScript > js实现左右两侧浮动广告

js实现左右两侧浮动广告

2018年08月11日  | 移动技术网IT编程  | 我要评论
本文实例为大家分享了js实现左右浮动广告展示的具体代码,供大家参考,具体内容如下 <html> <title>左右两侧浮动广告<

本文实例为大家分享了js实现左右浮动广告展示的具体代码,供大家参考,具体内容如下

<html>
<title>左右两侧浮动广告</title>
<head>
</head>
<body>
<table style="background-color:#eeeee2;width:1024px;height:2000px;t" align="center">
 <tr><td> </td></tr>
</table>
<script language="javascript">
<!--
 var showad = true;
 var toppx = 60; //上端位置
 var addivw = 100; //宽度
 var addivh = 300; //高度
 var pagewidth = 800; //页面多少宽度象素下正好不出现左右滚动条
 var minscreenw = 1024; //显示广告的最小屏幕宽度象素
 var closebuttonhtml = '<div align="right" style="position: absolute;top:0px;right:0px;margin:2px;padding:2px;z-index:2000;"><a href="javascript:;" rel="external nofollow" rel="external nofollow" mce_href="javascript:;" rel="external nofollow" rel="external nofollow" onclick="hidead()" style="color:red;text-decoration:none;font-size:12px;" mce_style="color:red;text-decoration:none;font-size:12px;">关闭</a></div>'
 var adcontenthtml = '<div align="center" style="color:green;font-size:23pt;font-family:黑体;" mce_style="color:green;font-size:23pt;font-family:黑体;"><br><br>广告</div>';
 document
  .write('<div id="javascript.leftdiv" style="position: absolute;border: 1px solid #336699;background-color:#eeeee2;z-index:1000;width:'+addivw+'px;height:'+addivh+'px;top:-1000px;word-break:break-all;display:none;">'
   + closebuttonhtml
   + '<div>'
   + adcontenthtml
   + '</div></div>');
 document
  .write('<div id="javascript.rightdiv" style="position: absolute;border: 1px solid #336699;background-color:#eeeee2;z-index:1000;width:'+addivw+'px;height:'+addivh+'px;top:-1000px;word-break:break-all;display:none;">'
   + closebuttonhtml
   + '<div>'
   + adcontenthtml
   + '</div></div>');
 function scall() {
 if (!showad) {
  return;
 }
 if (document.body.clientwidth < minscreenw) {
  //alert("临时提示:/n/n显示器分辨率宽度小于" + minscreenw + ",不显示广告");
  showad = false; 
  document.getelementbyid("javascript.leftdiv").style.display = "none";
  document.getelementbyid("javascript.rightdiv").style.display = "none";
  return;
 }
 var borderpx =( ((window.screen.width - pagewidth) / 2 - addivw) / 2 );
 document.getelementbyid("javascript.leftdiv").style.display = "";
 document.getelementbyid("javascript.leftdiv").style.top = document.body.scrolltop
  + toppx;
 document.getelementbyid("javascript.leftdiv").style.left = document.body.scrollleft
  + borderpx;
 document.getelementbyid("javascript.rightdiv").style.display = "";
 document.getelementbyid("javascript.rightdiv").style.top = document.body.scrolltop
  + toppx;
 document.getelementbyid("javascript.rightdiv").style.left = document.body.scrollleft
  + document.body.clientwidth
  - document.getelementbyid("javascript.rightdiv").offsetwidth
  - borderpx;
 }
 function hidead() {
 showad = false;
 document.getelementbyid("javascript.leftdiv").style.display = "none";
 document.getelementbyid("javascript.rightdiv").style.display = "none";
 }
 window.onscroll = scall;
 window.onresize = scall;
 window.onload = scall;
//-->
</script>
</body>
</html>

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持移动技术网。

如您对本文有疑问或者有任何想说的,请 点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网