当前位置: 首页 > 实例教程 > 脚本特效 > 动态内容 > 文字/图片自动播放脚本

动态内容
文字/图片自动播放脚本
顶置浮动内容条
内容前后翻页
内容折叠效果
可滚动内容
固定中间渐变提示效果
垂片切换内容
垂片图片内容切换
模拟分页效果
自动隐藏的广告框效果

动态内容 中的 文字/图片自动播放脚本


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-07-27   浏览: 558 ::
收藏到网摘: n/a

文字/图片自动播放脚本 - 软晨网(RuanChen.com)

效果演示:

JavaScript is a scripting language originally developed by Netscape to add interactivity and power to web documents. It is purely client side, and runs completely on the client's browser and computer.
Java is completely different from JavaScript- it's more powerful, more complex, and unfortunately, a lot harder to master. It belongs in the same league as C, C++, and other more complex languages.
DHTML is the embodiment of a combination of technologies- JavaScript, CSS, and HTML. Through them a new level of interactivity is possible for the end user experience.

第一步: 在你的页面HEAD区域加上下面这段代码:

<style type="text/css"> .gallerycontroller{ width: 250px } .gallerycontent{ width: 250px; height: 200px; border: 1px solid black; background-color: #DFDFFF; padding: 3px; display: block; } </style> <script type="text/javascript"> var tickspeed=3000 // (3000=3 秒,依此类推) var displaymode="auto" //显示方式 ("auto"自动 或 "manual"手动). if (document.getElementById){ document.write('<style type="text/css">\n') document.write('.gallerycontent{display:none;}\n') document.write('</style>\n') } var selectedDiv=0 var totalDivs=0 function getElementbyClass(classname){ partscollect=new Array() var inc=0 var alltags=document.all? document.all.tags("DIV") : document.getElementsByTagName("*") for (i=0; i<alltags.length; i++){ if (alltags[i].className==classname) partscollect[inc++]=alltags[i] } } function contractall(){ var inc=0 while (partscollect[inc]){ partscollect[inc].style.display="none" inc++ } } function expandone(){ var selectedDivObj=partscollect[selectedDiv] contractall() selectedDivObj.style.display="block" if (document.gallerycontrol) temp.options[selectedDiv].selected=true selectedDiv=(selectedDiv<totalDivs-1)? selectedDiv+1 : 0 if (displaymode=="auto") autocontrolvar=setTimeout("expandone()",tickspeed) } function populatemenu(){ temp=document.gallerycontrol.menu for (m=temp.options.length-1;m>0;m--) temp.options[m]=null for (i=0;i<totalDivs;i++){ var thesubject=partscollect[i].getAttribute("subject") thesubject=(thesubject=="" || thesubject==null)? "HTML Content "+(i+1) : thesubject temp.options[i]=new Option(thesubject,"") } temp.options[0].selected=true } function manualcontrol(menuobj){ if (displaymode=="manual"){ selectedDiv=menuobj expandone() } } function preparemode(themode){ displaymode=themode if (typeof autocontrolvar!="undefined") clearTimeout(autocontrolvar) if (themode=="auto"){ document.gallerycontrol.menu.disabled=true autocontrolvar=setTimeout("expandone()",tickspeed) } else document.gallerycontrol.menu.disabled=false } function startgallery(){ if (document.getElementById("controldiv")) //if it exists document.getElementById("controldiv").style.display="block" getElementbyClass("gallerycontent") totalDivs=partscollect.length if (document.gallerycontrol){ populatemenu() if (document.gallerycontrol.mode){ for (i=0; i<document.gallerycontrol.mode.length; i++){ if (document.gallerycontrol.mode[i].checked) displaymode=document.gallerycontrol.mode[i].value } } } if (displaymode=="auto" && document.gallerycontrol) document.gallerycontrol.menu.disabled=true expandone() } if (window.addEventListener) window.addEventListener("load", startgallery, false) else if (window.attachEvent) window.attachEvent("onload", startgallery) else if (document.getElementById) window.onload=startgallery </script>

第二步:在HTML中想显示该效果的位置上加上下面的代码:

<div class="gallerycontent" subject="What is JavaScript?"> JavaScript is a scripting language originally developed by Netscape to add interactivity and power to web documents. It is purely client side, and runs completely on the client's browser and computer. </div> <div class="gallerycontent" subject="Java & JavaScript Differences"> Java is completely different from JavaScript- it's more powerful, more complex, and unfortunately, a lot harder to master. It belongs in the same league as C, C++, and other more complex languages. </div> <div class="gallerycontent" subject="What is DHTML?"> DHTML is the embodiment of a combination of technologies- JavaScript, CSS, and HTML. Through them a new level of interactivity is possible for the end user experience. </div> <div id="controldiv" style="display:none" class="gallerycontroller"> <form name="gallerycontrol"> <select class="gallerycontroller" size="3" name="menu" onChange="manualcontrol(this.options.selectedIndex)"> <option>Blank form</option> </select><br> Auto: <input type="radio" checked name="mode" value="auto" onClick="preparemode('auto')"> Manual: <input type="radio" name="mode" value="manual" onClick="preparemode('manual')"> </form> </div>

可以参考第二步里的写法,来添加自己的内容,类似这样的:

<div class="gallerycontent" subject="What is JavaScript?"> 展示内容放这1 </div> <div class="gallerycontent" subject="Java & JavaScript Differences"> 展示内容放这2 </div>

评论 (0) All

登陆 | 还没注册?