/**
* JQuery广告代码
*/
ad ={
basePath: '',
content: [],
floatDivs: [],
closeHtml : '<img class="close" width="66px" height="22px" src="'+this.basePath+'/html/images/close.gif">',
showAD: function(){
for(var i =0; i<this.content.length; i++){
var adConfig = this.content[i];
if(adConfig && adConfig.isOpen){
this.generateHtml(adConfig);
}
}
this.maxTop = jQuery("body").attr("clientHeight") + jQuery(window).scrollTop() - 1; //设置浮动时的最大高度
this.maxLeft = jQuery("body").attr("clientWidth") + jQuery(window).scrollLeft() - 1; //设置浮动时的最大宽度
this.floatStrat();
},
generateHtml: function(o){ /*生成包含关闭的Html代码*/
var adHtml = this.generateADHtml(o);
var adDiv = jQuery("<div class='ad'/>");
var divHeight = o.height + (o.allowClose? 22 : 0);
adDiv.css({height: divHeight +"px", width: o.width+"px"});
adDiv.top = o.top || (jQuery(window).height() - divHeight);
var tableHtml = "";
switch(o.position){
case "left":
adDiv.css({left:'0px', top:o.top+'px'});
tableHtml = this.generateTableHtml(adHtml,o.allowClose? this.closeHtml:null);
break;
case "right":
adDiv.css({right:'0px', top:o.top+'px'});
tableHtml = this.generateTableHtml(adHtml,o.allowClose? this.closeHtml:null);
break;
case "bottom":
adDiv.css({right:'0px',bottom:'0px'});
tableHtml = this.generateTableHtml(o.allowClose? this.closeHtml:null, adHtml);
break;
case "float":
adDiv.css({left:o.left + 'px', top: o.top + 'px',position:'absolute'});
tableHtml = this.generateTableHtml(adHtml,o.allowClose? this.closeHtml:null);
this.addFloatDiv(adDiv);
break;
};
adDiv.append(jQuery(tableHtml));
adDiv.appendTo("body");
adDiv.find(".close").bind("click",function(){adDiv.css("display","none")});
if(jQuery.browser.msie && jQuery.browser.version <= 6 && o.position != 'float'){/*如果是IE6及以下版本*/
jQuery(window).scroll(function(){
if(adDiv.css("display") != "none"){
var windowTop=jQuery(window).scrollTop();
adDiv.animate({top:adDiv.top +windowTop+"px"},{duration:800,queue:false});
}
});
}
},
generateADHtml: function(o){ /*生成广告的内容*/
var str = '<a target="_blank" href="' + o.href +'">'
if(o.type=="img"){
str += '<img src="' + o.src + '" width="'+o.width+'px" height="'+ o.height+'px"/>'
}else if(o.type=="flash"){
str += "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' width='"+o.width+"' height='"+o.height+"' >";
str += "<param name='movie' value='"+this.basePath + o.src +"' />";
str += "<param name='quality' value='high' />";
str += "<param name='wmode' value='transparent'/>";
str += "<param name='swfversion' value='8.0.35.0' />";
str += "<embed wmode='transparent' src='"+this.basePath + o.src+"' quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' width='"+o.width+"' height='"+o.height+"'></embed>";
str += "</object>";
}
return str + "</a>";
},
generateTableHtml: function(s1, s2){
var tableBegin = "<table>";
if(s1){
tableBegin = tableBegin + "<tr><td>" +
s1 + "</td></tr>";
}
if(s2){
tableBegin = tableBegin + "<tr><td>" +
s2 + "</td></tr>";
}
tableBegin = tableBegin + "</table>";
return tableBegin;
},
floatStrat: function(){
var hasFloatDiv = false;
for(var i = 0 ; i<this.floatDivs.length; i++){
var ad = this.floatDivs[i];
hasFloatDiv = hasFloatDiv || ad.css("display") != "none";
if(ad.css("display") != "none" && ad.autoMove == true){
var curTop = parseInt(ad.css("top"));
var curLeft = parseInt(ad.css("left"));
// alert(jQuery("body").attr("clientWidth") + "--"+jQuery(window).scrollLeft()+"--"+parseInt(ad.css("width")) +"--" +ad.attr("offsetWidth"));
// alert(jQuery("body").attr("clientHeight") +"--"+ jQuery(window).scrollTop()+"--"+parseInt(ad.css("height")));
if(jQuery("body").attr("clientHeight") + jQuery(window).scrollTop() - 1 < this.maxTop){
this.maxTop = jQuery("body").attr("clientHeight") + jQuery(window).scrollTop() - 1;
}
// if(jQuery("body").attr("clientWidth") + jQuery(window).scrollLeft() - 1 < this.maxLeft){
this.maxLeft = jQuery("body").attr("clientWidth") + jQuery(window).scrollLeft() - 1;
// }
var t = jQuery("body").attr("clientHeight") + jQuery(window).scrollTop() - 1;
var r = ad.attr("offsetHeight") + curTop;
var s = ad.attr("offsetHeight") + curTop > jQuery("body").attr("clientHeight") + jQuery(window).scrollTop() - 1;
if(ad.attr("offsetWidth") + curLeft > this.maxLeft)
{
curLeft = jQuery(window).scrollLeft() + jQuery("body").attr("clientWidth") - ad.attr("offsetWidth");
ad.dirW = false;
}
if(ad.attr("offsetHeight") + curTop > this.maxTop)
{
curTop = jQuery(window).scrollTop() + jQuery("body").attr("clientHeight") - ad.attr("offsetHeight");
ad.dirH = false;
}
if(curLeft <= jQuery(window).scrollLeft())
{
curLeft = jQuery(window).scrollLeft();
ad.dirW = true;
}
if(curTop <= jQuery(window).scrollTop())
{
curTop = jQuery(window).scrollTop();
ad.dirH = true;
}
curLeft = curLeft + (ad.dirW ? 5 : -5) + "px";
curTop = curTop + (ad.dirH ? 5 : -5) + "px"
ad.css({left:curLeft, top:curTop});
}
}
if(hasFloatDiv){
setTimeout("NCPortal.ad.floatStrat()", 200);
}
},
addFloatDiv: function(o){
o.autoMove = true;
o.dirH = true; /*纵向移动,true:向下;false:向上,默认向下*/
o.dirW = true; /*横向移动,true:向右;false:向左,默认向右*/
o.bind("mouseover",function(){o.autoMove = false});
o.bind("mouseout",function(){o.autoMove = true});
this.floatDivs.push(o);
}
}
ad.content = [
/*position:left/right/bottom/float*/
{top:50,height:170,width:70,isOpen:true,position:'left',allowClose:true,src:'http://img1.126.net/channel5/008981/mbb110300l_110509.swf',type:"flash",href:"http://www.163.com"},
{top:50,height:170,width:70,isOpen:true,position:'right',allowClose:true,src:'http://img1.126.net/channel5/008981/mbb110300l_110509.swf',type:"flash",href:"http://www.163.com"},
{top:50,left:50,height:170,width:70,isOpen:true,position:'float',allowClose:true,src:'http://img1.126.net/channel5/008981/mbb110300l_110509.swf',type:"flash",href:"http://www.163.com"},
{height:80,width:100,isOpen:true,position:'bottom',allowClose:true,src:'http://www.91jquery.com/tm/j-1.jpg',type:'img',href:"http://www.jquery.com"}
];
jQuery(function() {
NCPortal.ad.showAD();
});
/*广告CSS*/
.ad{display: block; overflow: hidden; z-index: 10000; position: fixed;_position:absolute;-moz-user-select:none;}
分享到:
相关推荐
基于jquery 右侧浮动广告代码,自己整理的,很好看懂。。
基于jquery的全屏弹性伸缩广告代码.rar
基于JQuery的右下角广告代码.zip
漂亮的基于jQuery实用下拉菜单代码 JQuery,div+css,网页特效,广告设计
基于jquery的可拉下的幕布广告代码.zip
基于jquery实现的左右固定顶部可收缩的全屏广告代码,中间广告位在5秒之后,自动收起。兼容主流浏览器(不兼容IE6)
一个基于jquery 的幻灯片效果 阿里巴巴首页的幻灯片广告效果
Animation Banner 基于jQuery的广告图片切换特效插件.zip
基于jquery的banner广告图片动画切换插件示例.zip
基于jQuery实现可关闭全屏背景广告特效源码.zip
代码简介:一款基于jQuery CSS实现的带阴影的撕页广告代码。 适用浏览器:IE8 、FireFox、Chrome、Safari、Opera。
基于jQuery实现的上下翻转滚动的广告效果源码.zip
1. 2款jQuery图片自动切换常用广告代码 2. jquery+css五屏焦点图淡入淡出+圆形按钮切换广告图片代码 3. jQuery+CSS实用图片收缩与放大效果插件 4. jquery+div实现同时滑动切换的图文展示特效插件下载 5. ...
个人在国外网站上CopY整理的一款实用的网页大图切换代码,本代码基于Jquery,兼容性强,可以兼容目前所有主流浏览器,是一款带有过度效果(类似于幻灯片切换效果),带有左右按钮切换的一块很好的网页广告代码,所以...
为您提供-基于jquery特效,jquery弹出层效果,js特效代码大全,JS广告代码,导航菜单代码,下拉菜单代码和jquery焦点图片代码。
1. 2款jQuery图片自动切换常用广告代码 2. jquery+css五屏焦点图淡入淡出+圆形按钮切换广告图片代码 3. jQuery+CSS实用图片收缩与放大效果插件 4. jquery+div实现同时滑动切换的图文展示特效插件下载 5. jquery+...
基于jQuery的遮屏广告,向下拉开的广告特效,本演示代码一共演示了三种广告特效,第一种形式原广告显示数秒后隐藏,第二种形式原广告显示数秒后大板块隐藏,显示用来重播的标签,第三种形式原广告显示数秒后隐藏,...
基于jquery实现图片广告轮换效果代码,需要的朋友可以参考下。
基于jquery的滚动固定位置广告位插件,支持自定义偏移量。 用法: window.onscroll=function(){floatWin("branding","right","top")} window.onscroll=function(){floatWin("branding","left","top")} window....