zoukankan      html  css  js  c++  java
  • 无缝滚动轮播图

    代码:

     1 $(function() {
     2     var index = 1;
     3     var index1 = 0;
     4     $('.right').click(function() {// 点击显示下一张
     5         index++;
     6         index1++;
     7         if (index1 > 4) {
     8             index1 = 0;
     9         }
    10         // console.log(-100*index+'%');
    11         $('#img').animate({
    12             left: -100 * index + '%'
    13         }, 100, function() {
    14             if (index === 6) {
    15                 index = 1;
    16                 $(this).css('left', '-100%');
    17             }
    18         });
    19         $('ol li').eq(index1).addClass('bg').siblings().removeClass('bg');
    20     });
    21 
    22     $('.left').click(function() {//点击显示上一张;
    23         index--;
    24         index1--;
    25         if (index1 < 0) {
    26             index1 = 4;
    27         }
    28         console.log(-100 * index + '%');
    29         $('#img').animate({
    30             left: -100 * index + '%'
    31         }, 100, function() {
    32             if (index === 0) {
    33                 index = 5;
    34                 $(this).css('left', '-500%');
    35             }
    36         });
    37         $('ol li').eq(index1).addClass('bg').siblings().removeClass('bg');
    38     });
    39     $('ol li').click(function() {// 下面的按钮
    40         $(this).addClass('bg').siblings().removeClass("bg");
    41         index1 = $(this).index();
    42         index = index1 + 1;
    43         $('#img').animate({
    44             left: -100 * index + '%'
    45         }, 100);
    46     });
    47     setInterval(run, 5000);
    48 
    49     function run() {//自动显示下一张
    50         index++;
    51         index1++;
    52         if (index1 > 4) {
    53             index1 = 0;
    54         }
    55         // console.log(-100*index+'%');
    56         $('#img').animate({
    57             left: -100 * index + '%'
    58         }, 100, function() {
    59             if (index === 6) {
    60                 index = 1;
    61                 $(this).css('left', '-100%');
    62             }
    63         });
    64         $('ol li').eq(index1).addClass('bg').siblings().removeClass('bg');
    65     }
    66 });
  • 相关阅读:
    第五章:数组 结构体 和联合体
    第四章:用户自定义和枚举数据类型
    第三章:systemverilog文本值和数据类型
    阶段一:读几本经济学书
    第二章:systemverilog声明的位置
    数据结构-B树
    UDP的崛起
    vim使用
    sudo apt-get update
    计算机组成原理——浮点数表示方法
  • 原文地址:https://www.cnblogs.com/ade-Java/p/6623906.html
Copyright © 2011-2022 走看看