微智科技网
您的当前位置:首页javascript五图轮播切换实用版_javascript技巧

javascript五图轮播切换实用版_javascript技巧

来源:微智科技网
 代码如下:




测试


















































  • window.onload=function (){
    var num = document.getElementById("num");
    var num_li = document.getElementById("num").getElementsByTagName("li");
    var img_box = document.getElementById("img_box");
    var img_box_li = document.getElementById("img_box").getElementsByTagName("li");
    var bliw = img_box_li[0].offsetWidth;
    var n = 0;
    img_box.style.left = 0
    var autoscroll = setInterval(auto,3000);
    for (var i = 0;i < num_li.length;i++){
    num_li[i].onmouseover = function(){
    clearInterval(autoscroll);
    for (var i = 0;i < num_li.length;i++){
    num_li[i].style.background = "";
    if(num_li[i]==this){
    this.style.background = "#f00";
    slide(i);
    }
    }
    }
    num_li[i].onmouseout = function(){
    for (var i = 0;i < num_li.length;i++){
    if(num_li[i]==this){
    n = i;
    autoscroll = setInterval(auto,3000)
    }
    }
    }
    }
    function slide(i){
    img_box.style.left = -bliw*i + "px";
    }
    function auto(){
    n++;
    if(n == img_box_li.length){
    n =0;
    }
    for (var i =0;i < num_li.length;i++){
    num_li[i].style.background = "";
    }
    num_li[n].style.background = "#f00";
    slide(n);
    }
    }



    显示全文