App下載
話題 首頁(yè) > HTML5 教程 > HTML5 教程話題列表 > 詳情

HTML圖片輪播代碼怎么寫(xiě)?

精華
Shirley 2016-09-07 02:20:23 瀏覽(170675) 回復(fù)(20) 贊(9)
求html代碼做圖片輪播效果
html html5

回答(20)

291211384 精華 2017-05-24

<!DOCTYPE html>
<html>


    <head>
        <meta charset="utf-8" />
        <title>輪播圖</title>
        <style type="text/css">
            * {
                margin: 0px;
                padding: 0px;
            }

            
            #lunbotu {
                width: 1226px;
                height: 460px;
                overflow: hidden;
                position: relative;
                margin: 0px auto;
                position: relative;
            }

            
            #banner {
                height: 460px;
                width: 6130px;
                position: absolute;
                transition: 2s;
                left: 0px;
            }

            
            #banner img {
                float: left;
            }

            
            #biao {
                position: absolute;
                top: 430px;
                left: 43%;
            }

            
            #biao_1 {
                height: 20px;
                width: 20px;
                border: 1px solid #000;
                z-index: 10;
                float: left;
                list-style: none;
                border-radius: 50%;
                margin-left: 20px;
                text-align: center;
                cursor:pointer;
            }

            
        </style>
    </head>


    <body>
        <div id="lunbotu">
            <div id="banner">
                <img class="m" src="img/T1hiDvBvVv1RXrhCrK.jpg" />
                <img class="m" src="img/T1jrxjB_VT1RXrhCrK.jpg" />
                <img class="m" src="img/T1oTJjBKKT1RXrhCrK.jpg" />
                <img class="m" src="img/T1RICjB7DT1RXrhCrK.jpg" />
                <img class="m" src="img/T1vWdTBKDv1RXrhCrK.jpg" />
            </div>
            <div id="biao">
                <ul>
                    <li id="biao_1">1</li>
                    <li id="biao_1">2</li>
                    <li id="biao_1">3</li>
                    <li id="biao_1">4</li>
                    <li id="biao_1">5</li>
                </ul>
            </div>
        </div>

    
    </body>
    <script type="text/javascript">
        var slid = document.getElementById("banner");
        //var id = document.getElementById("bt");
        var imgwidth = document.getElementsByClassName("m");
        var oli=document.getElementsByTagName("li");
        //console.log(oli);
        //console.log(imgwidth );
        var i =0;
        auto();
        oli[0].style.cssText="background:#ff6700;color:#fff;";
        function auto(){

            
            time = setInterval(function(){
                i++;
            if(i <= 4) {
                slid.style.left = slid.offsetLeft - 1226 + "px";
                oli[i].style.cssText="background:#ff6700;color:#fff;";
                oli[i-1].style.cssText="background:none;color:#000;";
            } else {
                slid.style.left ="0px";
                oli[4].style.cssText="background:none;color:#000;";
                oli[0].style.cssText="background:#ff6700;color:#fff;";
                i=0;
            }
            console.log(i);

            
        }, 3000)

            
        }

        
            for(var j=0;j<=4;j++){
                //console.log(imgwidth[j].index);
            imgwidth[j].index=j;
            oli[j].index=j;
            oli[j].onmouseover=function(){
                this.style.cssText="background:#ff6700;color:#fff;"    
                this.onmouseout=function(){
                    this.style.cssText="background:none;color:#000;"
                }
            }

            
            oli[j].onclick=function(){
                clearInterval(time);
                m=this.index;
                slid.style.left=-m*1226+"px";    
                i=m;
                auto();
                console.log(i);
            }
            }    

            
    </script>


</html>
精華 2016-10-14

http://m.hgci.cn/freejquery Jquery插件小合集~需要的可以收藏個(gè),不斷更新中

小赤佬 精華 2017-12-27

網(wǎng)上看到的,希望對(duì)你有用~

HTML:


<!DOCTYPE html>
<html lang="en">


<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <link rel="stylesheet" type="text/css" href="./lunboh5.css">
    <script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.0.js"></script>
    <script type="text/javascript">
    var t = n = 0,
        count;
    $(document).ready(function() {
            // 獲取圖片標(biāo)簽長(zhǎng)度
            count = $("#banner_list a").length;
            // 不是當(dāng)前顯示的圖片隱藏
            $("#banner_list a:not(:first-child)").hide();
            // 點(diǎn)擊下面的1234按鈕,切換圖片
            $("#banner li").click(function() {
                var i = $(this).text() - 1;
                n = i;
                if (i >= count) return;
                // 淡入淡出效果
                $("#banner_list a").filter(":visible").fadeOut(500).parent().children().eq(i).fadeIn(1000);


                // 響應(yīng)點(diǎn)擊
                $(this).toggleClass("on");


                // 切換按鈕的時(shí)候讓上一個(gè)按鈕回歸原來(lái)的樣式
                $(this).siblings().removeAttr("class");
            });
            t = setInterval("showAuto()", 4000);
            $("#banner").hover(function() {
                    clearInterval(t)
                },
                function() {
                    t = setInterval("showAuto()", 4000);
                });
        })
        // 自動(dòng)輪播
    function showAuto() {
        n = n >= (count - 1) ? 0 : ++n;
        $("#banner li").eq(n).trigger('click');
    }
    </script>
</head>


<body>
    <div id="banner">
        <div id="banner_bg">
        </div>
        <div id="banner_info">
        </div>
        <ul>
            <li class="on">
                1
            </li>
            <li>
                2
            </li>
            <li>
                3
            </li>
            <li>
                4
            </li>
        </ul>
        <div id="banner_list">
            <a href="#" target="_blank">![jquery2??t?a1](http://upload-images.jianshu.io/upload_images/189984-6da57c46f1b3f07b.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)</a>
            <a href="#" target="_blank">![jquery2??t?a2](http://upload-images.jianshu.io/upload_images/189984-16081592e7683537.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)</a>
            <a href="#" target="_blank">![jquery2??t?a3](http://upload-images.jianshu.io/upload_images/189984-149067ce98381b8f.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)</a>
            <a href="#" target="_blank">![jquery2??t?a4](http://upload-images.jianshu.io/upload_images/189984-a44b79142dce57ad.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)</a>
        </div>
    </div>
</body>


</html>

CSS:


#banner {
    position: relative;
    width: 478px;
    height: 286px;
    border: 1px solid #666;
    overflow: hidden;
}


#banner_list img {
    border: 0px;
}


#banner_bg {
    position: absolute;
    bottom: 0;
    background-color: #000;
    height: 30px;
    filter: Alpha(Opacity=30);
    opacity: 0.3;
    z-index: 1000;
    cursor: pointer;
    width: 478px;
}


#banner_info {
    position: absolute;
    bottom: 0;
    left: 5px;
    height: 22px;
    color: #fff;
    z-index: 1001;
    cursor: pointer
}


#banner_text {
    position: absolute;
    width: 120px;
    z-index: 1002;
    right: 3px;
    bottom: 3px;
}


#banner ul {
    position: absolute;
    list-style-type: none;
    filter: Alpha(Opacity=80);
    opacity: 0.8;
    z-index: 1002;
    margin: 0;
    padding: 0;
    bottom: 3px;
    right: 5px;
}


#banner ul li {
    padding: 0px 8px;
    float: left;
    display: block;
    color: #FFF;
    background: #6f4f67;
    cursor: pointer;
    border: 1px solid #333;
}


#banner ul li.on {
    background-color: #000;
}


#banner_list a {
    position: absolute;
}

耀石石石 2016-11-29

貼一個(gè)超級(jí)簡(jiǎn)單的JS代碼,不需要插件

<!DOCTYPE html>
<html>
<head>
<title>圖片輪播代碼</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0,user-scalable=0">
</head>
<style type="text/css">
    body{max-width: 640px;margin: 0 auto;}
    #lunbo ul li{width:100%;list-style: none;width:640px; height:250px;background-color: #f00;text-align: center;}
    #lunbo ul li:not(:first-child){display: none;}
</style>


<body>
<div id="lunbo">
    <ul>
        <li>1</li>
        <li>2</li>
        <li>3</li>
        <li>4</li>
    </ul>
</div>
<script type="text/javascript">
    //因?yàn)槭褂昧薲ocument,所以js需要放在需要執(zhí)行的代碼下面生效才能生效
    var li=document.getElementById('lunbo').getElementsByTagName("li");
    var num=0;
    var len=li.length;


    setInterval(function(){
        li[num].style.display="none";
        num=++num==len?0:num;
        li[num].style.display="inline-block";


    },3000);//切換時(shí)間
</script>
</body>
</html>
2016-09-07

http://m.hgci.cn/jquerygroup/3krs1po2.html 這本手冊(cè)里面有各種你喜歡的輪播

humo 2017-03-09

相見(jiàn)恨晚啊

云遮夏靨 2017-01-13

簡(jiǎn)單功能不建議使用插件。不要過(guò)度依賴輪子,能自己造就自己造。

狂暴小二哈 2017-06-07

輪播圖有個(gè)swiper插件非常方便

垚垚 2017-06-20

把圖片放在一個(gè)隊(duì)列里,然后用循環(huán)定時(shí)器定時(shí)切換更改img的src......這樣應(yīng)該可以的

negivup 2016-09-28

很好的網(wǎng)址,果斷收藏了

百度一下就好,或者下個(gè)手冊(cè)。

1067358196 2017-10-15

請(qǐng)問(wèn)怎么分成HTML JS CSS 三個(gè)文件?我試了一下,發(fā)現(xiàn)會(huì)先顯示四個(gè)div。

Silence廣 2018-01-18

你們答的一點(diǎn)都對(duì)!沒(méi)有我什么需要更改的很好!

余生3053 2018-05-22

怎么設(shè)置自動(dòng)輪播

一筆荒蕪 2018-05-31

學(xué)到了,原來(lái)還可以這樣,真是難呀!!!!!!

1152696398 2018-05-31

吃瓜群眾,坐等大神來(lái)解決。。。。。

碼友1986907 2020-06-07

代碼是簡(jiǎn)單,不知圖片放哪兒,有詳細(xì)說(shuō)明怎樣寫(xiě)進(jìn)網(wǎng)頁(yè)

就好了,

要回復(fù),請(qǐng)先登錄 或者注冊(cè)