캐러셀 효과를 얻는 방법

一个新手
풀어 주다: 2017-09-29 10:01:49
원래의
1378명이 탐색했습니다.

html 인터페이스


                            
                                
                                    死兆星礼包
                                    死兆星皮肤上架
                                    LSPL11日赛程
                                    周边上架
                                    五折促销
로그인 후 복사

CSS 코드


#content6 {
                float: left;
                background: url(img/主页图片/adv_01.jpg);
                width: 533px;
                height: 280px;
            }
            /*.span3 li{clear: both;}*/
            
            .content6-1 {
                width: 533px;
                height: 40px;
                background: #353535;
                position: relative;
                top: 240px;
                /*left: -20px;*/
            }
로그인 후 복사

정적 웹페이지 렌더링

jQuery 구현

으로 타이머 효과


function a() {
//alert(j);
                            
                            if(j > 4) {
                                j = 0;
                            }
//                            alert(j);
                    $("#content6").css("background","url(img/主页图片/adv_0" + (j+1) + ".jpg)");//轮播广告,替换当前广告
                    t = setTimeout(a, 1000);//定时器
                    $(".content6-1 ul li").each(function(i,e){ //遍历每一个并获取下标
                        if(i==j)
                        {
                            $(e).css("background","#D52D02");//改变当前选中项的背景颜色
                        }
                        else
                        {
                            $(e).css("background","#353535");
                        }
                    })
                    
                    
                    
                    j++;
                }
                a();//在开始加载时调用代码
로그인 후 복사

정지 효과 달성


$(".content6-1 ul li").mouseenter(function(){
                        j=$(this).index();
                        
                        $("#content6").css("background","url(img/主页图片/adv_0" + (j+1)+ ".jpg)");
                         $(this).css("background","#D52D02")
                         .siblings().css("background","#353535");                         
                            clearTimeout(t);//定时器停止在当前选中的项
//                        alert(j);
                            })
로그인 후 복사

움직이는 효과 구현


$(".content6-1 ul li").mouseleave(function(){
                          j++;                         
                        setTimeout(a, 1000);                            
                        })
로그인 후 복사

JS 스크립트 구현

타이머 효과 구현


                var menus = document.querySelectorAll(".content6-1 ul li");
                function a() {
                    j++;
                    if(j > 5) {
                        j = 1;
                    } //                alert(i);                
                    //                    $("#content6").css({ "background": "url(img/主页图片/adv_0" + j + ".jpg)" });
                    document.querySelector("#content6").style.background = "url(img/主页图片/adv_0" + j + ".jpg)";                    for(var i = 0; i < menus.length; i++) {
                        menus[i].onmouseenter = enter;
                        menus[i].onmouseleave = leave;
                    }
                    for(var i = 0; i < menus.length; i++) {
                        if(i + 1 == j) {

                            menus[i].style.background = "#D52D02";
                        } else {
                            menus[i].style.background = "#353535";
                        }
                    }
                    t = setTimeout(a, 1000);
                }
                a();
로그인 후 복사

서스펜션 효과


function enter() {
                    for(var i = 0; i < menus.length; i++) {

                        if(this == menus[i]) {
                            j = i + 1;
                            menus[i].style.background = &#39;#D52D02&#39;;                            document.querySelector("#content6").style.background = "url(img/主页图片/adv_0" + j + ".jpg)";
                        } else {
                            menus[i].style.background = &#39;#353535&#39;;                        }

                    }
                    clearTimeout(t);
                }
로그인 후 복사

움직이는 효과


function leave() {
                    j--;
                    a();
                }
로그인 후 복사

렌더링

위 내용은 캐러셀 효과를 얻는 방법의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

관련 라벨:
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!