本文实例讲述了JS实现先显示大图后自动收起显示小图的广告代码。分享给大家供大家参考。具体如下:
这是一个非常不错的JavaScript图片特效,当最初打开网页的时候,显示的是大图片,就像遮屏广告一样,停留一会后,自动缓慢收起,这时由JS控制更换广告图片,始终显示在网页顶部,在一些大门户网站我们经常见到这种效果,个人感觉挺酷哦!
先来看看运行效果截图:
在线演示地址如下:
http://demo.jb51.net/js/2015/js-big-to-small-pic-adv-codes/
具体代码如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>先显示大图随后自动收起显示小图的JS广告</title> <meta http-equiv="content-type" content="text/html;charset=gb2312"> <style type="text/css"> html,body{margin:0;text-align:center;font-size:12px;} img{border:none} p{margin:0px} </style> <script type="text/javascript"> var showAD = { curve: function(t, b, c, d, s) { if ((t /= d / 2) < 1) return c / 2 * t * t * t + b; return c / 2 * ((t -= 2) * t * t + 2) + b }, fx: function(from, to, playTime, onEnd) { var Me = this, who = this.adWrap, position = 0, changeVal = to - from, curve = this.curve; playTime = playTime / 10; who.style.overflow = 'hidden'; function _run() { if (position++<playTime) { who.style.height = Math.max(1, Math.abs(Math.ceil(curve(position, from, changeVal, playTime)))) + "px"; setTimeout(_run, 10) } else { onEnd && onEnd.call(Me, to) } }; _run() }, init: function(info) { var Me = this, loadImg = new Image; loadImg.src = info.endImgURL; window.onload=function() { Me.endImgURL = info.endImgURL; Me.img = document.getElementById(info.imgID); Me.adWrap = document.getElementById(info.adWrapID); var max = Me.img.height; setTimeout(function() { Me.fx(max, 0, 500, function(x) { this.img.src = this.endImgURL; this.curve = function(t, b, c, d) { if ((t /= d) < (1 / 2.75)) { return c * (7.5625 * t * t) + b } else if (t < (2 / 2.75)) { return c * (7.5625 * (t -= (1.5 / 2.75)) * t + .75) + b } else if (t < (2.5 / 2.75)) { return c * (7.5625 * (t -= (2.25 / 2.75)) * t + .9375) + b } else { return c * (7.5625 * (t -= (2.625 / 2.75)) * t + .984375) + b } }; this.fx(0, this.img.height,600) }) }, info.timeout || 1000) }; } }; showAD.init({ adWrapID: 'ad_box_2009_06', imgID: 'adImg', endImgURL: 'images/as.jpg' }); </script> </head> <body> <div id="ad_box_2009_06"><img src="/UploadFiles/2021-04-02/ab.jpg">希望本文所述对大家的javascript程序设计有所帮助。
华山资源网 Design By www.eoogi.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
华山资源网 Design By www.eoogi.com
暂无评论...
更新日志
2024年09月20日
2024年09月20日
- 《黑神话:悟空》周伯通!大佬用左右手分别挑战两只虎先锋
- 《黑神话:悟空》攻击动作致敬《大话西游》:这也太帅了!
- 《星舰铳犬太阳系物语》游戏背景介绍
- 《战锤40K星际战士2》终极版有后续DLC说明
- 《第9层》游戏特色玩法介绍
- 刀郎.2006-刀郎【九雨天下】【WAV+CUE】
- 59.9高校生.1994-素兰万岁【上华】【WAV+CUE】
- ECHO.1991-你是爱我还是需要我(国专)【EMI百代】【WAV+CUE】
- 交错战线零课主线困难通关阵容推荐一览
- 交错战线挖掘矿场角色推荐攻略
- 命运圣契公测平民阵容怎么搭配 新手开荒平民阵容攻略
- 金梅《现代发烧的声音2》发烧碟[WAV+CUE]
- 雨果唱片-《历史录音珍藏系列-现代芭蕾舞剧·红色娘子军》2CD【WAV】
- [雨果唱片]李冰《地方民歌·戏曲系列-爱的颂歌》WAV
- 《模拟人生》真人电影官宣!玛格特·罗比担任制片人