代码驿站移动版
频道导航
HTML/Xhtml
CSS
JavaScript
HTML5
PHP教程
ASP.NET
正则表达式
AJAX
ThinkPHP
Yii
MySQL
MariaDB
Oracle
MongoDB
Redis
DedeCMS
PHPCMS
帝国CMS
WordPress
Discuz
其它CMS
Zend Studio
Sublime
Notepad
Dreamweaver
Windows
Linux
Nginx
Apache
IIS
CentOS
Ubuntu
Debian
网站优化
工具资源
PHP源码
ASP.NET源码
其它源码
图标素材
按钮素材
字体素材
DedeCMS模板
帝国CMS模板
PHPCMS模板
WordPress模板
Discuz!模板
单页模板
开发软件下载
服务器软件下载
广告投放
联系我们
版权申明
软件编程
网页前端
移动开发
数据库
服务器
脚本语言
PHP代码
JAVA代码
Python代码
Android代码
当前位置:
主页
>
网页前端
>
JavaScript代码
>
js自动滑动+鼠标滑动区域
时间:2021-04-19 08:07:58 | 栏目:
JavaScript代码
| 点击:次
<style type="text/css"> <!-- body{text-align:center;} table{width:500px; margin:0px auto;} td{padding:5px; font-weight:bold; text-align:center;} .iborder{border:1px #333333 solid; margin-top:5px;} .topnavon{background:#FFCC00; cursor:pointer;} .topnavoff{background:#000000; color:#FFFFFF;} --> </style> <script language="javascript"> <!-- /*新闻栏目播放*/ var scrollNewsCt=1; var pauseTime=10*1000; var timer0; function hideAllClips() { for (i=1; i<4; i++){ var allClips="newsbox"+i; var clipNum="clipNum"+i; document.getElementById(allClips).style.display="none"; document.getElementById(clipNum).className="topnavoff"; } } function clip_Switch(n) { var curClip="newsbox"+n; var curClipNum="clipNum"+n; hideAllClips(); document.getElementById(curClip).style.display="block"; document.getElementById(curClipNum).className="topnavon"; scrollNewsCt=n; } function fwdScroll() { stopScroll(); clip_Switch(scrollNewsCt); scrollNewsCt+=1; if (scrollNewsCt==4) { scrollNewsCt=1; } timer0=setTimeout("fwdScroll()",pauseTime); } function stopScroll() { clearTimeout(timer0); } /*财经栏目播放*/ var scrollEcCt=1; var EcpauseTime=5*1000; var timerEc; function hideAllEcClips() { for (i=1; i<6; i++){ var allEcBoxs="ecBox"+i; var ecNavNum="ecNav"+i; document.getElementById(allEcBoxs).style.display="none"; document.getElementById(ecNavNum).className="topnavoff"; } } function ecNavOn(n) { var curEcBox="ecBox"+n; var curEcNavNum="ecNav"+n; hideAllEcClips(); document.getElementById(curEcBox).style.display="block"; document.getElementById(curEcNavNum).className="topnavon"; scrollEcCt=n; } function fecScroll() { stopEcScroll(); ecNavOn(scrollEcCt); scrollEcCt+=1; if (scrollEcCt==6) { scrollEcCt=1; } timerEc=setTimeout("fecScroll()",EcpauseTime); } function stopEcScroll() { clearTimeout(timerEc); } --> </script> <h1 align="center" style="color:#FF0000;">自动滑动+鼠标滑动区域</h1> <div align="center" style="color:#FF0000;">10秒自动跳转</div> <table width="100%" border="0" cellspacing="0" cellpadding="0" class="iborder"> <tr> <td> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td class="topnavon" id="clipNum1" onMouseOver="clip_Switch(1); return false;">热点聚焦</td> <td class="topnavoff" id="clipNum2" onMouseOver="clip_Switch(2); return false;">图说新闻</td> <td class="topnavoff" id="clipNum3" onMouseOver="clip_Switch(3); return false;">经济新闻</td> </tr> </table> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td id="newsbox1" style="display:block;"><h1>新闻1</h1></td> </tr> <tr> <td id="newsbox2" style="display:none;"><h1>新闻2</h1></td> </tr> <tr> <td id="newsbox3" style="display:none;"><h1>新闻3</h1></td> </tr> </table> </td> </tr> </table> <script language="javascript">fwdScroll();</script> <div align="center" style="color:#FF0000;">5秒自动跳转</div> <table width="100%" border="0" cellspacing="0" cellpadding="0" class="iborder"> <tr> <td> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td class="topnavon" id="ecNav1" onMouseOver="ecNavOn(1); return false;">财经要闻</td> <td class="topnavoff" id="ecNav2" onMouseOver="ecNavOn(2); return false;">财经观察</td> <td class="topnavoff" id="ecNav3" onMouseOver="ecNavOn(3); return false;">独家点评</td> <td class="topnavoff" id="ecNav4" onMouseOver="ecNavOn(4); return false;">湘股在线</td> <td class="topnavoff" id="ecNav5" onMouseOver="ecNavOn(5); return false;">财富排行榜</td> </tr> </table> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td id="ecBox1" style="display:block;"><h1>财经1</h1></td> </tr> <tr> <td id="ecBox2" style="display:none;"><h1>财经2</h1></td> </tr> <tr> <td id="ecBox3" style="display:none;"><h1>财经3</h1></td> </tr> <tr> <td id="ecBox4" style="display:none;"><h1>财经4</h1></td> </tr> <tr> <td id="ecBox5" style="display:none;"><h1>财经5</h1></td> </tr> </table> </td> </tr> </table> <script language="javascript">fecScroll();</script> <h1 align="center" style="color:#FFCC00; font-size:150px; margin:0px auto;">!</h1> <p style="font-size:12px; text-align:left;"> 这个虽然效果不错,但是如果一个页面有多个这样的效果,就要针对每一部分写多个JS函数,那就太蠢了。其实只有控件名称不同而已,<span style="color:#FF0000;">求高手改进成一个通用函数或者类来调用</span>,不胜感激。 </p>
[Ctrl+A 全选 注:
引入外部Js需再刷新一下页面才能执行
]
这个虽然效果不错,但是如果一个页面有多个这样的效果,就要针对每一部分写多个JS函数,那就太蠢了。其实只有控件名称不同而已,求高手改进成一个通用函数或者类来调用,不胜感激
<style type="text/css"> <!-- body{text-align:center;} table{width:500px; margin:0px auto;} td{padding:5px; font-weight:bold; text-align:center;} .iborder{border:1px #333333 solid; margin-top:5px;} .topnavon{background:#FFCC00; cursor:pointer;} .topnavoff{background:#000000;color:#FFFFFF;} --> </style> <script type="text/javascript"> /*栏目播放*/ var scrollNo=1; var SetTime=5*1000; var SetTimer; //clip:标签ID,box:版面ID,n:当前滑动项,m:滑动总数 function hideAllClips(clip,box,n,m) { for (i=1; i<(m+1); i++){ var allClips=box.toString()+i; var clipNum=clip.toString()+i; //alert("隐藏"+allClips); //if(i=n) break; document.getElementById(allClips).style.display="none"; document.getElementById(clipNum).className="topnavoff"; } } function clip_Switch(clip,box,n,m) { var curClip=box.toString()+n; var curClipNum=clip.toString()+n; //alert("当前"+curClip); hideAllClips(clip,box,n,m); document.getElementById(curClip).style.display="block"; document.getElementById(curClipNum).className="topnavon"; scrollNo=n; } function fwdScroll(clip,box,m) { stopScroll(); clip_Switch(clip,box,scrollNo,m); scrollNo+=1; if (scrollNo==m+1){ scrollNo=1; } SetTimer=setTimeout("fwdScroll('"+clip+"','"+box+"',"+m+")",SetTime); } function stopScroll() { clearTimeout(SetTimer); } --> </script> <h1 align="center" style="color:#FF0000;">自动滑动+鼠标滑动区域</h1> <table width="100%" border="0" cellspacing="0" cellpadding="0" class="iborder"> <tr> <td> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td class="topnavon" id="clipNum1" onMouseOver="clip_Switch('clipNum','newsbox',1,3); return false;">热点聚焦</td> <td class="topnavoff" id="clipNum2" onMouseOver="clip_Switch('clipNum','newsbox',2,3); return false;">图说新闻</td> <td class="topnavoff" id="clipNum3" onMouseOver="clip_Switch('clipNum','newsbox',3,3); return false;">经济新闻</td> </tr> </table> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td id="newsbox1" style="display:block;"><h1>新闻1</h1></td> </tr> <tr> <td id="newsbox2" style="display:none;"><h1>新闻2</h1></td> </tr> <tr> <td id="newsbox3" style="display:none;"><h1>新闻3</h1></td> </tr> </table> </td> </tr> </table> <script language="javascript">fwdScroll('clipNum','newsbox',3);</script> <table width="100%" border="0" cellspacing="0" cellpadding="0" class="iborder"> <tr> <td> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td class="topnavon" id="ecNav1" onMouseOver="clip_Switch('ecNav','ecBox',1,5); return false;">财经要闻</td> <td class="topnavoff" id="ecNav2" onMouseOver="clip_Switch('ecNav','ecBox',2,5); return false;">财经观察</td> <td class="topnavoff" id="ecNav3" onMouseOver="clip_Switch('ecNav','ecBox',3,5); return false;">独家点评</td> <td class="topnavoff" id="ecNav4" onMouseOver="clip_Switch('ecNav','ecBox',4,5); return false;">湘股在线</td> <td class="topnavoff" id="ecNav5" onMouseOver="clip_Switch('ecNav','ecBox',5,5); return false;">财富排行榜</td> </tr> </table> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td id="ecBox1" style="display:block;"><h1>财经1</h1></td> </tr> <tr> <td id="ecBox2" style="display:none;"><h1>财经2</h1></td> </tr> <tr> <td id="ecBox3" style="display:none;"><h1>财经3</h1></td> </tr> <tr> <td id="ecBox4" style="display:none;"><h1>财经4</h1></td> </tr> <tr> <td id="ecBox5" style="display:none;"><h1>财经5</h1></td> </tr> </table> </td> </tr> </table> <script language="javascript">fwdScroll('ecNav','ecBox',5);</script> <table width="100%" border="0" cellspacing="0" cellpadding="0" class="iborder"> <tr> <td> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td class="topnavon" id="bcNav1" onMouseOver="clip_Switch('bcNav','bcBox',1,5); return false;">财经要闻</td> <td class="topnavoff" id="bcNav2" onMouseOver="clip_Switch('bcNav','bcBox',2,5); return false;">财经观察</td> <td class="topnavoff" id="bcNav3" onMouseOver="clip_Switch('bcNav','bcBox',3,5); return false;">独家点评</td> <td class="topnavoff" id="bcNav4" onMouseOver="clip_Switch('bcNav','bcBox',4,5); return false;">湘股在线</td> <td class="topnavoff" id="bcNav5" onMouseOver="clip_Switch('bcNav','bcBox',5,5); return false;">财富排行榜</td> </tr> </table> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td id="bcBox1" style="display:block;"><h1>财经1</h1></td> </tr> <tr> <td id="bcBox2" style="display:none;"><h1>财经2</h1></td> </tr> <tr> <td id="bcBox3" style="display:none;"><h1>财经3</h1></td> </tr> <tr> <td id="bcBox4" style="display:none;"><h1>财经4</h1></td> </tr> <tr> <td id="bcBox5" style="display:none;"><h1>财经5</h1></td> </tr> </table> </td> </tr> </table> <script language="javascript">fwdScroll('bcNav','bcBox',5);</script> <h1 align="center" style="color:#FFCC00; font-size:150px; margin:0px auto;">!</h1> <p style="font-size:12px; text-align:left;"> 改了下,能够实现了,但是第二个为什么会默认第二个项开始,第三个从第三项开始呢?而且只有最后一个自动播放,前面的都死了;并且代码还是不够精练,请高手帮忙继续修改。 </p>
[Ctrl+A 全选 注:
引入外部Js需再刷新一下页面才能执行
]
<style type="text/css"> <!-- body{text-align:center;} table{width:500px; margin:0px auto;} td{padding:5px; font-weight:bold; text-align:center;} .iborder{border:1px #333333 solid; margin-top:5px;} .topnavon{background:#FFCC00; cursor:pointer;} .topnavoff{background:#000000; color:#FFFFFF;} --> </style> <script type="text/javascript"> /*栏目播放*/ var scrollNo=0; var SetTime=5*1000; var SetTimer; function hideAllClips(clip,box,m) { for (i=1; i<(m+1); i++){ var allClips=box.toString()+i; var clipNum=clip.toString()+i; //alert("隐藏"+allClips); document.getElementById(allClips).style.display="none"; document.getElementById(clipNum).className="topnavoff"; } } function clip_Switch(clip,box,no,m) { var curClip=box.toString()+no; var curClipNum=clip.toString()+no; //alert("当前"+curClip); hideAllClips(clip,box,m); document.getElementById(curClip).style.display="block"; document.getElementById(curClipNum).className="topnavon"; scrollNo=no; } function fwdScroll(clip,box,m) { stopScroll(); clip_Switch(scrollNo); scrollNo+=0; if (scrollNo==m) { scrollNo=0; } SetTimer=setTimeout("fwdScroll(clip,box,m)",SetTime); } function stopScroll() { clearTimeout(SetTimer); } --> </script> <h1 align="center" style="color:#FF0000;">自动滑动+鼠标滑动区域</h1> <table width="100%" border="0" cellspacing="0" cellpadding="0" class="iborder"> <tr> <td> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td class="topnavon" id="clipNum1" onclick="clip_Switch('clipNum','newsbox',1,3); return false;">热点聚焦</td> <td class="topnavoff" id="clipNum2" onclick="clip_Switch('clipNum','newsbox',2,3); return false;">图说新闻</td> <td class="topnavoff" id="clipNum3" onclick="clip_Switch('clipNum','newsbox',3,3); return false;">经济新闻</td> </tr> </table> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td id="newsbox1" style="display:block;"><h1>新闻1</h1></td> </tr> <tr> <td id="newsbox2" style="display:none;"><h1>新闻2</h1></td> </tr> <tr> <td id="newsbox3" style="display:none;"><h1>新闻3</h1></td> </tr> </table> </td> </tr> </table> <script language="javascript">fwdScroll('clipNum','newsbox',3);</script> <table width="100%" border="0" cellspacing="0" cellpadding="0" class="iborder"> <tr> <td> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td class="topnavon" id="ecNav1" onclick="clip_Switch('ecNav','ecBox',1,5); return false;">财经要闻</td> <td class="topnavoff" id="ecNav2" onclick="clip_Switch('ecNav','ecBox',2,5); return false;">财经观察</td> <td class="topnavoff" id="ecNav3" onclick="clip_Switch('ecNav','ecBox',3,5); return false;">独家点评</td> <td class="topnavoff" id="ecNav4" onclick="clip_Switch('ecNav','ecBox',4,5); return false;">湘股在线</td> <td class="topnavoff" id="ecNav5" onclick="clip_Switch('ecNav','ecBox',5,5); return false;">财富排行榜</td> </tr> </table> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td id="ecBox1" style="display:block;"><h1>财经1</h1></td> </tr> <tr> <td id="ecBox2" style="display:none;"><h1>财经2</h1></td> </tr> <tr> <td id="ecBox3" style="display:none;"><h1>财经3</h1></td> </tr> <tr> <td id="ecBox4" style="display:none;"><h1>财经4</h1></td> </tr> <tr> <td id="ecBox5" style="display:none;"><h1>财经5</h1></td> </tr> </table> </td> </tr> </table> <script language="javascript">fwdScroll('ecNav','ecBox',5);</script> <h1 align="center" style="color:#FFCC00; font-size:150px; margin:0px auto;">!</h1> <p style="font-size:12px; text-align:left;"> <h1 align="center" style="color:#FF0000;">改过以后不自动播放了。</h1> </p>
[Ctrl+A 全选 注:
引入外部Js需再刷新一下页面才能执行
]
您可能感兴趣的文章:
JavaScript常见事件处理程序实例总结
Javascript的匿名函数小结
url传递的参数值中包含&时,url自动截断问题的解决方法
Javascript别踩白块儿(钢琴块儿)小游戏实现代码
兼容浏览器的js事件绑定函数(详解)
相关文章
10-19
javascript上下左右定时滚动插件
11-23
Webpack中loader打包各种文件的方法实例
11-27
Javascript实例教程(19) 使用HoTMetal(2)
10-05
javascript判断图片是否加载完成的方法推荐
11-22
在javascript中执行任意html代码的方法示例解读
JQuery
VUE
AngularJS
MSSql
MySQL
MongoDB
Redis
Linux
Tomcat
Nginx
网站首页
广告投放
联系我们
版权申明
联系站长