Home > Web Front-end > JS Tutorial > body text

jQuery implements carousel chart (width full screen and height fixed)

巴扎黑
Release: 2017-07-24 14:27:47
Original
2212 people have browsed it

html部分




 

 

        
       
  •  
       
  •  
       
  •  
       
  •  
     
 
 
     
     
     
     
     
       
       
     
     


    css部分

    1 * {
    2     margin: 0;
    3     padding: 0;
    4
    }

    5 .cm-banner {
    6     width: 100%;
    7     height: 300px;
    8     overflow: hidden;
    9     cursor: pointer;
    10     position: relative;
    11
    }

    12 13 .cm-banner-in {
    14     width: 1100px;
    15     height: 300px;
    16     position: absolute;
    17     top: 0;
    18     left: 50%;
    19     margin-left: -550px;
    20
    }

    21 22 #cm_banner_list li {
    23     display: none;
    24     position: absolute;
    25     top: 0;
    26     left: 0;
    27
    }

    28 29 .cm-banner-num {
    30     width: 100%;
    31     position: absolute;
    32     bottom: 0;
    33     text-align: center;
    34     z-index: 2;
    /*如果没有在这里设置层次小圆点的点击效果无法触发*/
    35
    }

    36 37 .cm-banner-num li {
    38     width: 10px;
    39     margin: 10px 3px;
    40     height: 10px;
    41     background-color: #fff;
    42     border-radius: 5px;
    43     -webkit-border-radius: 5px;
    44     display: inline-block;
    45     opacity: 0.7;
    46
    }

    47 48 .cm-banner-num .active {
    49     background-color: #3982de;
    50
    }

    51 52 .cm-banner-arrow {
    53     position: absolute;
    54     top: 50%;
    55     margin-top: -22px;
    56     opacity: 0.5;
    57     display: none;
    58
    }

    59 60 #cm_prev {
    61     left: 0;
    62
    }

    63 64 #cm_next {
    65     right: 0;
    66
    }

    js部分

     1 $(function(){ 2     //鼠标移入显示箭头按钮 3     $('.cm-banner').hover(function(){ 4         $('.cm-banner-arrow').show(); 5         clearInterval(cm_timer); 6     },function(){ 7         $('.cm-banner-arrow').hide(); 8         cm_timer = setInterval(function(){ 9             i++;10             if(i > cm_length - 1){11                 i = 0;12             }13             $('#cm_banner_list li').eq(i).fadeIn(800).siblings().fadeOut(800);14             cm_toggle(i);15         },2500);16     });17 18     //鼠标移入箭头按钮高亮19     $('.cm-banner-arrow').hover(function(){20         $(this).css('opacity','1');21     },function(){22         $(this).css('opacity','0.5');23     });24 25     //初始化必要变量26     var i = 0;27     var cm_length = $('#cm_banner_list li').length;28     var cm_toggle = function(point){29         $('#cm_banner_num li').eq(point).addClass('active').siblings().removeClass('active');30     };31 32     //动态添加小圆点33     for(j = 0;j < cm_length;j++){34         $('#cm_banner_num').append('<li></li>');35     }36 37     //给第一个小圆点添加样式38     $('#cm_banner_num li').first().addClass('active');39 40     //给第一张图片添加样式41     $('#cm_banner_list li').first().css('display','block');42 43     //鼠标点击左箭头切换44     $('#cm_prev').click(function(){45         i--;46         if(i < 0){47             i = cm_length - 1;48         }49         $(&#39;#cm_banner_list li&#39;).eq(i).fadeIn(800).siblings().fadeOut(800);50         cm_toggle(i);51     });52 53     //鼠标点击右箭头切换54     $(&#39;#cm_next&#39;).click(function(){55         i++;56         if(i > cm_length - 1){57             i = 0;58         }59         $('#cm_banner_list li').eq(i).fadeIn(800).siblings().fadeOut(800);60         cm_toggle(i);61     });62 63     //鼠标点击圆点切换64     $('#cm_banner_num li').click(function(){65         var cm_index = $(this).index();66         $('#cm_banner_list li').eq(cm_index).fadeIn(800).siblings().fadeOut(800);67         i = cm_index;68         cm_toggle(cm_index);69     });70 71     //自动播放72     cm_timer = setInterval(function(){73         i++;74         if(i > cm_length - 1){75             i = 0;76         }77         $('#cm_banner_list li').eq(i).fadeIn(800).siblings().fadeOut(800);78         cm_toggle(i);79     },2500);80 });
    Copy after login

     

    The above is the detailed content of jQuery implements carousel chart (width full screen and height fixed). For more information, please follow other related articles on the PHP Chinese website!

    Related labels:
    source:php.cn
    Statement of this Website
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
    Popular Tutorials
    More>
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template