全屏弹性伸缩广告代码

经常会看到门户网站,如[163网易,新浪,等等],打开页面时隔几秒钟,页面中央也现一个透明的FLASH动画浮出来,展示一段时音后消失,再次打开首 页就不会有[这里通过记录cookie来判断,只显示一次,这样必免用户对广告的反感],其原理跟大家分享一下我这里拿jquery框架为列,
1.页面引用jquery框架 jquery-1.4.2.min.js[最新的,老版也样]   jquery.cookie.js[jquery cookie插件]
2.页面加一个DIV的盒子 命名ID =*  [我这里就命名为 indexheadpopup],
3.id=indexheadpopup 写样式
<style>
#indexheadpopup{width:600px; height:300px; background:#ff6600;position:absolute;display:none}
</style>
3.就是调用以下的代码
4.就是做FLASH swf透明的动画或图片[这里做动画是FLASH导入的文件为PNG 用失量图做效果好]

  1. jQuery(function() {
  2.         
  3.         var COOKIE_NAME = "mode";    //定义cookie名称
  4.         if( $.cookie(COOKIE_NAME)){
  5.             $("#indexheadpopup").hide();  
  6.         }else{
  7.            var winH = $(window).height();  //获取窗口高度
  8.            var winW = $(window).width();   //获取窗口宽度度
  9.           $("#indexheadpopup").css({'top': winH/2-$("#indexheadpopup").height()/2,'left': winW/2-
  10. $("#indexheadpopup").width()/2 }); //这里动画显示的位置
  11.             
  12.             $("#indexheadpopup").slideDown(1000, function() {
  13.             setTimeout("ClearIndexHeadPopup()", '18000');
  14.             });
  15.                 //展开1000表示1秒中显示动画 #indexheadpopup 内的东东  18000就是18秒后执行下面的函数ClearIndexHeadPopup
  16.           $.cookie(COOKIE_NAME,"mode", { path: '/', expires: 10 });
  17.         }
  18.         //写入mode  cookie名称
  19.     });
  20. function ClearIndexHeadPopup() {
  21.          $('#indexheadpopup').hide();
  22.             //关闭#indexheadpopup东西 ,这里可以用jquery效果里的方法,有很多种,这里就不说了
  23.             
  24. }
  25. 代码写的不好,我也是新手来的,不足的地方希望大家谅解
    看了步聚就赶快动手,试试看,demo就不打包了,东西不多,亲自试验一下,很爽的
首页中有,停留几秒中就会显示 ,只会显示一次,删除COOKIE,刷新就可以再显示

JS
jQuery(function() {
//Set the popup window to center
var COOKIE_NAME = "mode";
if( $.cookie(COOKIE_NAME)){
$("#indexheadpopup").hide();
}else{
var winH = $(window).height();
var winW = $(window).width();
$("#indexheadpopup").css({'top': winH/2-$("#indexheadpopup").height()/2,'left': winW/2-$("#indexheadpopup").width()/2 });
$("#indexheadpopup").slideDown(1000, function() {
setTimeout("ClearIndexHeadPopup()", '18000');
});
$.cookie(COOKIE_NAME,"mode", {path: '/', expires: 1});
}

});
function ClearIndexHeadPopup() {
$('#indexheadpopup').hide();

}

调用的FLASH对像,这里要
<script type="text/javascript">
  writeFlash('images/homead.swf',600, 300);
</script>

这里我简化了flash swf文件的插入方式
http://www.gocd.com.cn/templets/default/js/flash.js

function writeFlash(FlashFile,width, height)
{
document.writeln(" <object classid=/"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000/" codebase=/"http:download.macromedia.com//pub//shockwave//cabs//flash//swflash.cab#version=9,0,28,0/" width=/""+width+"/" height=/""+height+"/"> ");
document.writeln(" <param name=/"movie/" value=/""+FlashFile+"/" //> ");
document.writeln(" <param name=/"quality/" value=/"high/" //> ");
document.writeln(" <param name=/"wmode/" value=/"transparent/" //> ");
document.writeln(" <embed src=/""+FlashFile+"/" quality=/"high/" pluginspage=/"http:www.adobe.com//shockwave//download//download.cgi?P1_Prod_Version=ShockwaveFlash/" type=/"application//x-shockwave-flash/" width=/""+width+"/" height=/""+height+"/" wmode=/"transparent/"> <//embed> ");
document.writeln(" <//object> ")
<!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <title></title> <link rel="stylesheet" href="css/index.css" type="text/css" media="screen" /> <script type="text/javascript" src="js/jquery-1.7.2.min.js"></script> <script type="text/javascript" src="js/index.js"></script> <!--[if lt IE 7]> <link rel="stylesheet" href="css_2/ie6.css?v000020" type="text/css" media="screen" /> <script type="text/javascript" src="js/ie6.js?v000020"></script> <![endif]--> </head> <body> <div class="pub_c"> <div class="m_banner"> <div class="banner b1" style=" background-image:url(images/banner_2.jpg);" id="banner1"> <div class="main_c pr"> <a href="#" title="" class="start_btn"></a> </div> </div> <div class="banner b5" style=" background-image:url(images/banner_17.jpg);display:none;" id="banner5"> <div class="main_c"> <a href="#" target="_blank" title="" class="l1"></a> <div class="countdown"> <span class="num_1 fsm">0</span> <span class="num_2 fsm">0</span> </div> </div> </div> <div class="banner b2" style=" background-image:url(images/banner_12.jpg);display:none;" id="banner2"> <div class="main_c pr"> <p>更多新功能介绍及教程请 <a href="#" target="_blank" title="">点击此处</a> 或咨询 <a target="_blank" href="http://wpa.qq.com/msgrd?v=3&uin=123456&site=qq&menu=yes" title="">客服QQ</a> / <a target="_blank" href="http://crm2.qq.com/page/portalpage/wpa.php?uin=123456&f=1&ty=1&aty=0&a=&from=6" title="">商务QQ</a></p> </div> </div> <div class="banner b3" style=" background-image:url(images/banner_3.jpg);display:none;" id="banner3"> </div> <div class="banner b4" style=" background-image:url(images/banner_4.jpg);display:none;" id="banner4"> <div class="main_c pr"> <a href="#" title="" class="start_btn">查看详情</a> </div> </div> <div class="banner_ctrl"> <a href="#" class="prev" title=""></a> <a href="javascript:;" class="next" title=""></a> </div> </div> </body> </html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值