輪播效果

html界面     

複製代碼
<div id="content6">
                            <div class="content6-1">
                                <ul>
                                    <li>死兆星禮包</li>
                                    <li>死兆星皮膚上架</li>
                                    <li>LSPL11日賽程</li>
                                    <li>周邊上架</li>
                                    <li>五折促銷</li>
                                </ul>
                            </div>
</div>                      
複製代碼

 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實現

 實現定時器效果css

複製代碼
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();//在開始加載時調用代碼
複製代碼

實現懸浮效果html

 

複製代碼
$(".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);
                            })
複製代碼

實現移開效果this

$(".content6-1 ul li").mouseleave(function(){
                          j++;                         
                        setTimeout(a, 1000);                            
                        })

JS腳本實現

  實現定時器效果url

複製代碼
                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();
複製代碼

懸浮效果spa

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

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

                    }
                    clearTimeout(t);
                }
複製代碼

移開效果code

function leave() {
                    j--;
                    a();
                }

效果圖

相關文章
相關標籤/搜索