zoukankan      html  css  js  c++  java
  • JS+CSS实现4张图片滚动切换代码

    代码简介:

    一个JS完成的图片切换特效,手动更新,目前限制为4张图片,当然这个是可以自己修改的,如果更改此数字,那么要相应的增加图片单元,否则JS会报错或无法显示图片。本特效很小巧,代码也不是太多,因些适合二次修改。

    代码内容:

    View Code
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>JS+CSS实现4张图片滚动切换代码 - www.webdm.cn</title>
    </head>
    <style type="text/css">
    *
    {
    margin
    :3;padding:0;
    font-size
    :12px;
    }
    body
    {
    font-size
    :9pt;
    text-align
    :center;
    margin-top
    : 8px;
    }
    body *
    {text-align:center;}
    .font14
    {font-size:14px;}
    select
    {font-family: Times New Roman,arial,verdana,sans-serif;}
    table
    {
    border-collapse
    :collapse;
    }
    img
    {border:0;}
    ul
    {list-style-type:none;}
    .clear
    {clear: both;height:0;line-height:0px;font-size:14px;}
    .center
    {text-align:center;}
    .mleft0
    {margin-left:0px !important;}
    .mtop0
    {margin-top:0px !important;}
    .strong
    {font-weight: bold;}
    .sb
    {color:#009A91;font-weight: bold;}
    #i_photo_index
    {width:258px;height:256px;text-align:center;}
    #i_photo_index a.i_photo_a
    {height:180px;text-align:center;margin-left:8px;}
    #i_photo_index a.i_photo_a img
    {margin-top:10px;}
    #i_photo_index h1
    {margin-top:0 !important;margin-top:4px;margin-top:2px;height:28px;line-height:28px;text-

    align
    :center;}
    #i_photo_index h1 a
    {font-size:18px;font-weight:normal;font-family:"黑体",arial,verdana,sans-serif;}
    #i_photo_index p
    {width:96%;margin:0 2%;line-height:20px;text-align:left;text-indent:2em;}
    #i_photo_index p span
    {margin-right:30px !important;margin-right:0px;}
    a:link
    {
    text-decoration
    : none;
    }
    a:visited
    {
    text-decoration
    : none;
    }
    a:hover
    {
    color
    : #0066cc;
    text-decoration
    : underline;
    }
    #i_photo img
    {margin-left:0px;}
    .i_link2 a
    {float:center;margin:2px;padding:2px 0;display:blcok;height:22px;line-height:22px;}
    #index_page
    {float:right;display:block;height:16px;padding:1px 0;margin-right:4px;}
    #index_page *
    {float:left;display:inline;line-height:16px;border:1px solid #B6CFCD;text-

    align
    :center;padding:0;margin:0 2px;}
    #index_page strong
    {background:#009A91;color:#fff;width:16px;}
    #index_page span
    {color:#009a91;padding:3px 0 0 0;border:0;cursor:pointer;}
    #index_page a
    {width:16px;color:#009A91;text-decoration:none;}
    body,td,th
    {
    font-size
    : 12px;
    }
    a
    {
    font-size
    : 16px;
    }
    a:active
    {
    text-decoration
    : none;
    }
    .jdt
    {
    border
    : 1px solid #CCCCCC;
    }
    </style>
    <body>
    <table width="200" border="0" align="center" cellpadding="0" cellspacing="0" class="jdt">
    <tr>
    <td><script language="javascript" type="text/javascript">
    //<![CDATA[
    var _t1 = 3; //网页打开时等待图片载入的秒数
    var _t2 = 5; //切换的时间
    var _tnum = 4; //图片数
    var _tn = 1;//当前焦点,by http://www.codefans.net
    var _tl =null;
    _tt1
    = setTimeout('change_img()',_t1*1000);
    function change_img(){
    setFocus(_tn);
    _tt1
    = setTimeout('change_img()',_t2*1000);
    }
    function setFocus(i){
    if(i>_tnum){_tn=1;i=1;}
    _tl
    ?document.getElementById('focusPic'+_tl).style.display='none':'';
    document.getElementById(
    'focusPic'+i).style.display='block';
    _tl
    =i;
    _tn
    ++;
    }
    //]]>
    </script>
    <!--焦点图开始 标题不要超过13字,说明文字在30个字以内-->
    <div id="focusPic1">
    <a href="/" class="i_photo_a" target="_blank">
    <img src="http://www.webdm.cn/images/20091006/01.jpg"></a>
    <h1><a href="/" target="_blank">这里是您的标题一文字内容</a></h1>
    <div id="index_page"><span onClick="javascript:setFocus(2);">点击切换→</span>
    <strong>1</strong>
    <a href="javascript:setFocus(2);">2</a>
    <a href="javascript:setFocus(3);">3</a>
    <a href="javascript:setFocus(4);">4</a>
    </div></div>

    <div id="focusPic2" style="display:none;">
    <a href="/" class="i_photo_a" target="_blank">
    <img src="http://www.webdm.cn/images/20091006/02.jpg"></a>
    <h1><a href="/" target="_blank">这里是您的标题二文字内容</a></h1>
    <div id="index_page"><span onClick="javascript:setFocus(3);">点击切换→</span>
    <a href="javascript:setFocus(1);">1</a>
    <strong>2</strong>
    <a href="javascript:setFocus(3);">3</a>
    <a href="javascript:setFocus(4);">4</a>
    </div></div>

    <div id="focusPic3" style="display:none;">
    <a href="/" class="i_photo_a" target="_blank">
    <img src="http://www.webdm.cn/images/20091006/03.jpg"></a>
    <h1><a href="/" target="_blank">这里是您的标题三文字内容</a></h1>
    <div id="index_page"><span onClick="javascript:setFocus(4);">点击切换→</span>
    <a href="javascript:setFocus(1);">1</a>
    <a href="javascript:setFocus(2);">2</a>
    <strong>3</strong>
    <a href="javascript:setFocus(4);">4</a>
    </div></div>

    <div id="focusPic4" style="display:none;">
    <a href="/" class="i_photo_a" target="_blank">
    <img src="http://www.webdm.cn/images/20091006/04.jpg"></a>
    <h1><a href="/" target="_blank">这里是您的标题四文字内容</a></h1>
    <div id="index_page"><span onClick="javascript:setFocus(1);">点击切换→</span>
    <a href="javascript:setFocus(1);">1</a>
    <a href="javascript:setFocus(2);">2</a>
    <a href="javascript:setFocus(3);">3</a>
    <strong>4</strong>
    </div></div>
    <!--焦点图结束-->
    </td>
    </tr>
    </table>
    </body>
    </html>
    <br />
    <p><a href="http://www.webdm.cn">网页代码站</a> - 最专业的网页代码下载网站 - 致力为中国站长提供有质量的网页代码!

    </p>

    代码来自http://www.webdm.cn/webcode/ba5fdfea-5419-4606-8f9a-1ac31bae6e27.html

  • 相关阅读:
    The Future of Middleware and the BizTalk Roadmap
    FW: How to spawn a process that runs under the context of the impersonated user in Microsoft ASP.NET pages
    Strips illegal Xml characters
    luogu P2280 激光炸弹(二维前缀和)
    luogu P2704 炮兵阵地(经典状态压缩DP)
    SP1716 GSS3 Can you answer these queries III (线段树维护最大连续子段和)
    二分图判定、匹配问题
    C++语法综合 | 基于char*设计一个字符串类MyString
    luogu P1044 火车进出栈问题(Catalan数)
    C++设计模式 | 三种设计模式基础
  • 原文地址:https://www.cnblogs.com/webdm/p/2299186.html
Copyright © 2011-2022 走看看