JS代码判断集锦大全第4/5页

 更新时间:2007年12月06日 21:15:02   投稿:mdxy-dxy  
本文通过实例代码给大家介绍了js代码判断的方法,代码简单易懂,非常不错,具有一定的参考借鉴价值,需要的朋友参考下吧
广告JS代码效果大全 1.[普通效果] 现在很多网站广告做的如火如荼,现在我就来介绍一下常见的对联浮动广告效果的代码使用方法,介绍的这种效果,在1024*768分辨率下正常显示,在800*600的分辨率下可以自动隐藏,以免遮住页面影响访问者浏览内容,下面就是实现效果所需代码: var delta=0.015 var collection; function floaters() { this.items = []; this.addItem = function(id,x,y,content) { document.write('<DIV id='+id+' style="Z-INDEX: 0; POSITION: absolute; width:80px; height:60px;left:'+(typeof(x)=='string'?eval(x):x)+';top:'+(typeof(y)=='string'?eval(y):y)+'">'+content+'</DIV>'); var newItem = {}; newItem.object = document.getElementById(id); newItem.x = x; newItem.y = y; this.items[this.items.length] = newItem; } this.play = function() { collection = this.items setInterval('play()',10); } } function play() { if(screen.width<=800) { for(var i=0;i<collection.length;i++) { collection.object.style.display = 'none'; } return; } for(var i=0;i<collection.length;i++) { var followObj = collection.object; var followObj_x = (typeof(collection.x)=='string'?eval(collection.x):collection.x); var followObj_y = (typeof(collection.y)=='string'?eval(collection.y):collection.y); if(followObj.offsetLeft!=(document.body.scrollLeft+followObj_x)) { var dx=(document.body.scrollLeft+followObj_x-followObj.offsetLeft)*delta; dx=(dx>0?1:-1)*Math.ceil(Math.abs(dx)); followObj.style.left=followObj.offsetLeft+dx; } if(followObj.offsetTop!=(document.body.scrollTop+followObj_y)) { var dy=(document.body.scrollTop+followObj_y-followObj.offsetTop)*delta; dy=(dy>0?1:-1)*Math.ceil(Math.abs(dy)); followObj.style.top=followObj.offsetTop+dy; } followObj.style.display = ''; } } var theFloaters = new floaters(); theFloaters.addItem('followDiv1','document.body.clientWidth-100',0,'</a><br><a href=广告链接地址 target=_blank><img src=广告图片地址 width=100 height=400 border=0></a>' target=_blank); theFloaters.addItem('followDiv2',0,0,'<br><a href=广告链接地址 target=_blank><img src=广告图片地址 width=100 height=400 border=0></a>' target=_blank); theFloaters.play(); 把上面的代码另存为一个JS文件,然后在想实现此效果的页面用 调用即可!注意修改广告图片地址和连接地址! 广告JS代码效果大全 ~~~~~~~~~~ 2.[鼠标感应] 与前面一个代码不同的是,当鼠标移动到广告图片上是可以感应显示另外设置好的广告大图效果,下面就是实现效果所需代码: function bigshow(){ document.all.div_250.style.visibility = 'visible'; document.all.div_80.style.visibility = 'hidden'; } function bighide(){ document.all.div_80.style.visibility = 'visible'; document.all.div_250.style.visibility = 'hidden'; } var ad_80= new Array(1); var ad_250= new Array(1); ad_80[0]="<a href=http://www.dfeng.net target=_blank><img src=/skin/adv43/ad/ad_ad.gif border=0></a>"; ad_250[0]="<a href=http://www.dfeng.net target=_blank><img src=/skin/adv43/ad/ad_ad2.gif border=0></a>"; var imgheight; var fubioleft; window.screen.width>800 ? fubioleft=15:fubioleft=15 document.write('<DIV id=floater_left style="Z-INDEX: 25; LEFT:'+fubioleft+'px; WIDTH: 28px;POSITION: absolute; TOP: 42px; HEIGHT: 22px">'); ad_now = new Date(); ad_id= ad_now.getSeconds() %1 var adhead1="<div id=div_80 style='position:absolute; width:95px; height:62px; z-index:12' onMouseOver=bigshow();>"; var adhead2="</div><div id=div_250 style='position:absolute; visibility: hidden; z-index:13;width: 80; height: 60' onMouseOut=bighide();>"; //var adhead1="<div id=div_80 style='position:absolute; width:95px; height:62px; z-index:20' onMouseOut='//MM_showHideLayers(\"div_250\",\"\",\"hide\")' onMouseOver='MM_showHideLayers(\"div_250\",\"\",\"show\")'>"; //var adhead2="</div><div id=div_250 style='position:absolute; z-index:21;visibility: hidden; width: 80; height: 60' onMouseOver='MM_showHideLayers(\"div_250\",\"\",\"show\")' onMouseOut='MM_showHideLayers(\"div_250\",\"\",\"hide\")'>"; document.write(adhead1+ad_80[ad_id]+adhead2+ad_250[ad_id]+"</div>"); document.write ("</div>"); self.onError=null; currentX = currentY = 0; whichIt = null; lastScrollX = 0; lastScrollY = 0; NS = (document.layers) ? 1 : 0; IE = (document.all) ? 1: 0; function heartBeat() { if(IE) { diffY = document.body.scrollTop; diffX = document.body.scrollLeft; } if(NS) { diffY = self.pageYOffset; diffX = self.pageXOffset; } if(diffY != lastScrollY) { percent = .5 * (diffY - lastScrollY); if(percent > 0) percent = Math.ceil(percent); else percent = Math.floor(percent); if(IE) document.all.floater_left.style.pixelTop += percent; if(NS) document.floater_left.top += percent; lastScrollY = lastScrollY + percent; } if(diffX != lastScrollX) { percent = .5 * (diffX - lastScrollX); if(percent > 0) percent = Math.ceil(percent); else percent = Math.floor(percent); if(IE) document.all.floater_left.style.pixelLeft += percent; if(NS) document.floater_left.left += percent; lastScrollX = lastScrollX + percent; } } if(NS || IE) action = window.setInterval("heartBeat()",1);var ad_80= new Array(1); var ad_250= new Array(1); ad_80[0]="<a href=http://www.dfeng.net target=_blank><img src=/skin/adv43/ad/ad_ad.jpg border=0></a>"; ad_250[0]="<a href=http://www.dfeng.net target=_blank><img src=/skin/adv43/ad/ad_ad.jpg border=0></a>"; var imgheight; var fubioleft; window.screen.width>800 ? fubioleft=15:fubioleft=15 document.write('<DIV id=floater_right style="Z-INDEX: 25; LEFT:'+fubioleft+'px; WIDTH: 28px;POSITION: absolute; TOP: 42px; HEIGHT: 22px">'); ad_now = new Date(); ad_id= ad_now.getSeconds() %1 function myload() { if (navigator.appName == "Netscape") { document.div_right_80.pageX=+window.innerWidth-130; document.div_right_250.pageX=+window.innerWidth-300; mymove(); } else { div_right_80.style.left=document.body.offsetWidth-130; div_right_250.style.left=document.body.offsetWidth-300; mymove(); } } function mymove() { if(document.ns) { document.div_right_80.left=pageXOffset+window.innerWidth-130; document.div_right_250.left=pageXOffset+window.innerWidth-300; setTimeout("mymove();",20) } else { div_right_80.style.left=document.body.scrollLeft+document.body.offsetWidth-145; div_right_250.style.left=document.body.scrollLeft+document.body.offsetWidth-300; setTimeout("mymove();",20) } } var adhead1="<div id=div_right_80 style='position:absolute; width:95px; height:60px; z-index:12' onMouseOver=bigshow_right();>"; var adhead2="</div><div id=div_right_250 style='position:absolute; visibility: hidden; z-index:13;width: 250; height: 250' onMouseOut=bighide_right();><div align=right>"; document.write(adhead1+ad_80[ad_id]+adhead2+ad_250[ad_id]+"</div></div>"); myload() document.write ("</div>"); self.onError=null; currentX_right = currentY_right = 0; whichIt_right = null; lastScrollX_right = 0; lastScrollY_right = 0; NS = (document.layers) ? 1 : 0; IE = (document.all) ? 1: 0; function heartBeat_right() { if(IE) { diffY_right = document.body.scrollTop; diffX_right = document.body.scrollLeft; } if(NS) { diffY_right = self.pageYOffset; diffX_right = self.pageXOffset; } if(diffY_right != lastScrollY_right) { percent_right = .5 * (diffY_right - lastScrollY_right); if(percent_right > 0) percent_right = Math.ceil(percent_right); else percent_right = Math.floor(percent_right); if(IE) document.all.floater_right.style.pixelTop += percent_right; if(NS) document.floater_right.top += percent_right; lastScrollY_right = lastScrollY_right + percent_right; } if(diffX_right != lastScrollX_right) { percent_right = .5 * (diffX_right - lastScrollX_right); if(percent_right > 0) percent_right = Math.ceil(percent_right); else percent_right = Math.floor(percent_right); if(IE) document.all.floater_right.style.pixelLeft += percent_right; if(NS) document.floater_right.left += percent_right; lastScrollX_right = lastScrollX_right + percent_right; } } if(NS || IE) action = window.setInterval("heartBeat_right()",1); function bigshow_right(){ document.all.div_right_250.style.visibility = 'visible'; document.all.div_right_80.style.visibility = 'hidden'; } function bighide_right(){ document.all.div_right_80.style.visibility = 'visible'; document.all.div_right_250.style.visibility = 'hidden'; }document.write(''); document.write(''); document.write(''); 3.[允许关闭] 与前面两个代码不同的是,广告图下方增加了一个图片按纽,允许访客点击关闭广告图片,下面文本框中就是实现效果所需代码: var delta=0.015; var collection; var closeB=false; function floaters() { this.items = []; this.addItem = function(id,x,y,content) { document.write('<DIV id='+id+' style="Z-INDEX: 10; POSITION: absolute; width:80px; height:60px;left:'+(typeof(x)=='string'?eval(x):x)+';top:'+(typeof(y)=='string'?eval(y):y)+'">'+content+'</DIV>'); var newItem = {}; newItem.object = document.getElementById(id); newItem.x = x; newItem.y = y; this.items[this.items.length] = newItem; } this.play = function() { collection = this.items setInterval('play()',30); } } function play() { if(screen.width<=800 || closeB) { for(var i=0;i<collection.length;i++) { collection.object.style.display = 'none'; } return; } for(var i=0;i<collection.length;i++) { var followObj = collection.object; var followObj_x = (typeof(collection.x)=='string'?eval(collection.x):collection.x); var followObj_y = (typeof(collection.y)=='string'?eval(collection.y):collection.y); if(followObj.offsetLeft!=(document.body.scrollLeft+followObj_x)) { var dx=(document.body.scrollLeft+followObj_x-followObj.offsetLeft)*delta; dx=(dx>0?1:-1)*Math.ceil(Math.abs(dx)); followObj.style.left=followObj.offsetLeft+dx; } if(followObj.offsetTop!=(document.body.scrollTop+followObj_y)) { var dy=(document.body.scrollTop+followObj_y-followObj.offsetTop)*delta; dy=(dy>0?1:-1)*Math.ceil(Math.abs(dy)); followObj.style.top=followObj.offsetTop+dy; } followObj.style.display = ''; } } function closeBanner() { closeB=true; return; } var theFloaters = new floaters(); // theFloaters.addItem('followDiv1','document.body.clientWidth-100',0,'<a href=http://www.dfeng.net target=_blank><img src=ad/doublead/right.gif width=100 height=554 border=0></a><br><br><img src=ad/doublead/close.gif >'); theFloaters.addItem('followDiv2',0,0,'<a href=http://www.dfeng.net target=_blank><img src=ad/doublead/ad_ad.gif width=100 height=400 border=0 ></a><br><br><img src=ad/doublead/close.gif >'); theFloaters.play(); 把上面的代码分别另存为两个JS文件,然后在想实现此效果的页面用 <script type="text/javascript" language="javascript1.2" src="*.js"></SCRIPT> 调用即可,*代表你另存的文件名!注意修改广告图片地址和连接地址!

相关文章

  • 深入理解选择框脚本[推荐]

    深入理解选择框脚本[推荐]

    选择框是通过<select>和<option>元素创建的,又称为下拉列表框。为了方便与这个控件交互,除了所有表单字段共有的属性和方法外,javascript还提供了一些属性和方法。本文将详细介绍选择框脚本
    2016-12-12
  • 深入理解JavaScript中的Base64编码字符串

    深入理解JavaScript中的Base64编码字符串

    在我们进行前端开发时,针对项目优化,常会提到一条:针对较小图片,合理使用Base64字符串替换内嵌,可以减少页面http请求。本文整理了一些Base64编码字符串的相关知识,感兴趣的可以了解一下
    2023-02-02
  • 小程序实现图片预览裁剪插件

    小程序实现图片预览裁剪插件

    这篇文章主要为大家详细介绍了小程序实现图片预览裁剪插件,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2019-11-11
  • 微信小程序scroll-view隐藏滚动条的方法详解

    微信小程序scroll-view隐藏滚动条的方法详解

    这篇文章主要介绍了微信小程序scroll-view隐藏滚动条的方法,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
    2020-03-03
  • ES6 let和const定义变量与常量的应用实例分析

    ES6 let和const定义变量与常量的应用实例分析

    这篇文章主要介绍了ES6 let和const定义变量与常量的应用,结合实例形式分析了ES6使用let定义变量以及使用const定义常量的相关操作技巧,需要的朋友可以参考下
    2019-06-06
  • 直接拿来用的页面跳转进度条JS实现

    直接拿来用的页面跳转进度条JS实现

    这篇文章主要为大家分享了一款直接拿来用的页面跳转进度条,由javascript实现,可以直接跳转到相应页面,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2016-01-01
  • js利用appendChild对<li>标签进行排序的实现方法

    js利用appendChild对<li>标签进行排序的实现方法

    下面小编就为大家带来一篇js利用appendChild对<li>标签进行排序的实现方法。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2016-10-10
  • JavaScript 特有方法计算二进制中1的个数 split方法

    JavaScript 特有方法计算二进制中1的个数 split方法

    这是一道网上看到的前端的笔试题,主要思想是利用JavaScript的toString方法将十进制数转换为二进制的字符串。然后for循环遍历计算字符串中”1″出现的次数。
    2010-05-05
  • 在页面中引入js的两种方法(推荐)

    在页面中引入js的两种方法(推荐)

    下面小编就为大家带来一篇在页面中引入js的两种方法(推荐)。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2017-08-08
  • JavaScript仿支付宝6位数字密码输入框

    JavaScript仿支付宝6位数字密码输入框

    最近做了一个项目,涉及到某宝购物支付密码的输入框功能,下面小编把实现思路分享到脚本之家平台供大家参考
    2016-12-12

最新评论