zoukankan      html  css  js  c++  java
  • 简单的图片轮换

    简单的图片轮换

    首先用Css 创建简单的ui

    <style>
    ul{ list-style:none; padding:0px; margin:0px;}
    #scrollPics{ width:500px; height:200px; position:relative; overflow:hidden}
    #scrollPics img{ width:500px; height:200px;}
    #scrollPics .num{position:absolute;right:5px;bottom:5px;}
    #scrollPics .num ul{ list-style:none;}
    #scrollPics .num li{ float:left; width:20px; height:20px; border:1px #FFCC00 solid;cursor: pointer;background-color: #fff; margin-right:5px; text-align:center; font-size:12px}
    #scrollPics .num li.on{  width:20px; height:20px; border:1px #FFCC00 solid;cursor: pointer; background-color:#FF6600}
    </style>

    在boby里插入这段代码

    <div id="scrollPics">
    <ul class="slide">
    <li><img src="img/1.jpg" /></li>
    <li><img src="img/2.jpg" /></li>
    <li><img src="img/3.jpg" /></li>
    </ul>
    <ul class="num">
    <li class="on">1</li>
    <li>2</li>
    <li>3</li>
    </ul>
    </div>

    接下来就要创建jquery动画了

    <script language="javascript">
    var len = $(".num  li").length;
    var index=0;
    var adTimer;
    $(document).ready(function(){
    
      $(".num li").mouseover(function(){
      index=$(".num li").index(this);
      showimg(index);
      });
     
      $('#scrollPics').hover(function() {
            clearInterval(adTimer);
        }, function() {
            adTimer = setInterval(function() {
                showimg(index);
                index++;
                if (index == len) {       //最后一张图片之后,转到第一张
                    index = 0;
                }
            }, 3000);
        }).trigger("mouseleave");
    
     
     function showimg(index){
     var adHeight=$("#scrollPics>ul>li:first").height();
         $(".slide").stop(true,false).animate({
          "marginTop":-adHeight*index+"px"
          },1000);
     $(".num li").removeClass("on").eq(index).addClass("on");
     };
    
    });
    </script>
  • 相关阅读:
    MyEclipse:详细使用教程
    JDK安装与配置详细图文教程
    windows下python3.6版本安装pygame
    windows下如何下载并安装Python
    python的 del 函数是删对象还是删引用
    python strip()函数的用法
    python的垃圾回收机制
    python中的sort方法
    python中del函数的垃圾回收
    两个数交换
  • 原文地址:https://www.cnblogs.com/vania/p/3316577.html
Copyright © 2011-2022 走看看