您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 广告经营 > jQuery防止被屏蔽的浮动对联广告和提示框
/*-----------------------------------------------------------------------------------------------------------------功能说明:防止被浏览器屏蔽的浮动对联广告程序,可自定义个广告个数和显示位置,可以定义flash和图片广告-----------------------------------------------------------------------------------------------------------------参数说明:ads这是一个要显示的广告数组对象,可根据要显示的广告内容进行设定相关信息广告内容参数:targetUrl:点击广告转向的页面链接imgUrl:广告显示的图片或者flash地址isflash:广告是否是flash,true表示为flash广告,默认为false图片广告position:广告显示的屏幕位置,分left和right,即显示在屏幕左或者右margin:广告距屏幕两侧的距离,若position为right,则距屏幕右侧距离,position为left,则为距左侧的距离top:广告距屏幕顶部的距离,默认为200pxshowclose:是否在广告上方显示关闭按钮-----------------------------------------------------------------------------------------------------------------作者:刘伟neijlw@gmail.com日期:2010-01-10-----------------------------------------------------------------------------------------------------------------示例:varparam=[{targetUrl:::true,position:left,showclose:true},{targetUrl:::false,position:right,showclose:true}];$(document).ready(function(){$.adv.showAd(param);});*/(function($){$.extend({adv:{show:function(ads){this.adFlagId=newDate().getTime();if(!ads||ads.length1)return;varth=this;functionmakeAd(ad){varstr=[divid='ad];str.push(ad.position);str.push(th.adFlagId);str.push('style='position:absolute;);if(ad.top){str.push(top:);str.push(ad.top);str.push(px;);}else{str.push(top:200px;);}if(ad.position.toLowerCase()=='left'){str.push(left:);str.push(ad.left?ad.left:2);}elseif(ad.position.toLowerCase()=='right'){str.push(right:);str.push(ad.right?ad.right:2);}str.push(px;');if(ad.showclose){str.push(divstyle='text-align:right;padding-right:5px;'spanstyle='cursor:pointer;'onclick=\$('#ad+ad.position+th.adFlagId+').hide();\id='close_+ad.position+th.adFlagId+'×/span/div);}str.push(div);if(ad.isflash){str.push(objectclassid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'codebase='=7,0,19,0'paramname='movie'value=');str.push(ad.imgUrl);str.push('/paramname='quality'value='high'/embedsrc=');str.push(ad.imgUrl);str.push('quality='high'pluginspage='='application/x-shockwave-flash'/embed/object);}else{str.push(ahref=');str.push(ad.targetUrl);str.push('target='_blank'imgsrc=');str.push(ad.imgUrl);str.push('border='0'//a);}str.push(/div);str.push(/div);returnstr.join();}for(vari=0;iads.length;i++){$(document.body).append(makeAd(ads[i]));}vartmpt=0;if(window.innerHeight){tmpt=window.pageYOffset;}elseif(document.documentElement&&document.documentElement.scrollTop){tmpt=document.documentElement.scrollTop;}elseif(document.body){tmpt=document.body.scrollTop;}this.oldFloatAdTop=tmpt+200;setInterval(function(){th.scroll();},5);},scroll:function(){varo=$(div[id^='ad']:visible);if(o.length1)return;varpos=o.offset();vartmpt=0;if(window.innerHeight){tmpt=window.pageYOffset;}elseif(document.documentElement&&document.documentElement.scrollTop){tmpt=document.documentElement.scrollTop;}elseif(document.body){tmpt=document.body.scrollTop;}varstep=20;vartopMarg=200;if(pos.top=tmpt+topMarg){if(Math.abs(pos.top-tmpt-topMarg)step){this.oldFloatAdTop+=step;}o.css(margin-top,(this.oldFloatAdTop)+px);}elseif(pos.toptmpt+topMarg){if(Math.abs(pos.top-tmpt-topMarg)step){this.oldFloatAdTop-=step;}o.css(margin-top,(this.oldFloatAdTop)+px);}}}});})(jQuery);
本文标题:jQuery防止被屏蔽的浮动对联广告和提示框
链接地址:https://www.777doc.com/doc-1468652 .html