7.17 JS实现商品轮播

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title></title>
        <style>
            .border{width: 400px;height: 100px;}
            #pic1{height: 400px;width: 400px;}
            .pic2{width: 90px;height: 90px;}
            #PICU{width: 440px;left: 0px;padding:0px;margin:0px}
            .LI1{
                padding: 5px;
                float: left;
                width: 90px;
                height: 90px;
                list-style: none;
                background-color: gray;
                cursor: pointer;
            }
        </style>
    </head>
    <body>
        <img id="pic1" src="img/1.jpg" onmouseover="Picstop();"   onmouseout="Pgo()"/>
        </div>
        <div class="border">
            <ul id="PICU">
                <li class="LI1" onmouseover="Pstop(1);" onmouseout="Pgo()" style="background-color: red;"><img class="pic2" src="img/1.jpg" ></li>
                <li class="LI1" onmouseover="Pstop(2);" onmouseout="Pgo()"><img class="pic2" src="img/2.jpg" ></li>
                <li class="LI1" onmouseover="Pstop(3);" onmouseout="Pgo()"><img class="pic2" src="img/3.jpg" ></li>
                <li class="LI1" onmouseover="Pstop(4);" onmouseout="Pgo()"><img class="pic2" src="img/4.jpg" ></li>
            </ul>
        </div>
        <script>
            var n=0;
            var showImg =document.getElementById("pic1");
            var picNum=document.getElementsByClassName("LI1");
            console.log(picNum[0]);
            window.onload = function(){
                inter = window.setInterval("change()",1500);
            }
            function change(){
                if(n==4){
                    picNum[n-1].style.backgroundColor="gray";
                    n=0;    
                }
                for(var a=1;a<5;a++){
                    if(a!=(n))picNum[a-1].style.backgroundColor="gray";
                }
                showImg.src='img/'+(n+1)+'.jpg';
                if(n>0)picNum[n-1].style.backgroundColor="gray";
                picNum[n].style.backgroundColor="red";
                n++;
                
            }
            function Picstop(){
                window.clearInterval(inter);
            }
            function Pstop(i){
                console.log(i);
                picNum[i-1].style.backgroundColor="red";
                for(var a=1;a<5;a++){
                    if(a!=(i))picNum[a-1].style.backgroundColor="gray";
                }
                showImg.src='img/'+i+'.jpg';
                window.clearInterval(inter);
            }
            function Pgo(){
                inter = setInterval("change()",1500);
            }
        </script>
    </body>
</html>

效果如下:

gifhome_520x644_4s.gif
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容