<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          用jquery實(shí)現(xiàn)輪播圖的效果

          共 1802字,需瀏覽 4分鐘

           ·

          2021-02-06 10:12


          今天分享的是一個(gè)簡(jiǎn)單的輪播圖,這個(gè)輪播圖的特效很簡(jiǎn)單,能夠進(jìn)行圖片的輪播以及點(diǎn)擊相應(yīng)圖片,圖片能夠跳轉(zhuǎn)到相應(yīng)位置,首先書寫的div部分:
          <div id="scrollPics"> <ul class="slider"> <li><img src="../images/1.jpg" alt="">li> <li><img src="../images/2.jpg" alt="">li> <li><img src="../images/3.jpg" alt="">li> <li><img src="../images/7.jpg" alt="">li> <li><img src="../images/5.jpg" alt="">li> ul> <ul class="num">ul>div>
          然后書寫style樣式部分
          <style> *{ margin: 0px; padding: 0px; } ul{ list-style: none; } #scrollPics{ height: 420px; width: 790px; margin-bottom: 10px; overflow: hidden; position: relative; top: 100px; left:400px; } .slider{ margin-top: 0px; } .slider img{ width: 100%; } .num{ position: absolute; right: 5px; bottom: 5px; } .num li{ float: left; color: #ff7300; text-align: center; line-height: 16px; width: 16px; height: 16px; cursor: pointer; overflow: hidden; margin: 3px 1px; border: 1px solid #ff7300; background-color: white; border-radius: 50%; } .num li.active{ color: #fff; line-height: 21px; width: 21px; height: 21px; font-size: 16px; margin: 0 1px; border: 0; background-color: #ff7300; font-weight: bold; border-radius: 50%; cursor: pointer; }style>
          最后是script部分
          <script> $(function () { var slider =$("#scrollPics .slider"); //獲取圖片 var imgCon =$("#scrollPics .slider li"); //除第一張其余的圖片全部隱藏 imgCon.not(imgCon.eq(0)).hide(); //定義頁碼 var num =$("#scrollPics .num") //獲取li標(biāo)簽的長(zhǎng)度 //find()方法返回備選元素的后代元素 var len =slider.find("li").length; var html_page =""; index=0; //添加頁碼 for (var i=0;i if (i===0){ html_page+="
        2. "+(i+1)+"
        3. "
          } else { html_page +="
        4. "+(i+1)+"
        5. "
          } } //輸出原點(diǎn) num.html(html_page) //顯示索引對(duì)應(yīng)的圖片 function showPic(index) { imgCon.eq(index).show().siblings("li").hide(); num.find("li").eq(index).addClass("active").siblings("li").removeClass("active") } //原點(diǎn)點(diǎn)擊事件 $(".num li").click(function () { index=$(this).index() showPic(index) }) //圖片輪播 $("#scrollPics").hover(function () { clearInterval(window.timer) },function () { window.timer =setInterval(function () { showPic(index); index++; if (index ===len){ index =0 } },2000) }).trigger("mouseleave")//觸發(fā)備選元素的指定事件 })script>
          最后因?yàn)槭怯胘query書寫的代碼,還要導(dǎo)入? ? 。
          最后是完整代碼?
          <html lang="en"><head> <meta charset="UTF-8"> <title>JQ輪播圖title> <script src="../js/jquery-2.2.3.js">script> <style> *{ margin: 0px; padding: 0px; } ul{ list-style: none; } #scrollPics{ height: 420px; width: 790px; margin-bottom: 10px; overflow: hidden; position: relative; top: 100px; left:400px; } .slider{ margin-top: 0px; } .slider img{ width: 100%; } .num{ position: absolute; right: 5px; bottom: 5px; } .num li{ float: left; color: #ff7300; text-align: center; line-height: 16px; width: 16px; height: 16px; cursor: pointer; overflow: hidden; margin: 3px 1px; border: 1px solid #ff7300; background-color: white; border-radius: 50%; } .num li.active{ color: #fff; line-height: 21px; width: 21px; height: 21px; font-size: 16px; margin: 0 1px; border: 0; background-color: #ff7300; font-weight: bold; border-radius: 50%; cursor: pointer; }style>head><body>
          <div id="scrollPics"> <ul class="slider"> <li><img src="../images/1.jpg" alt="">li> <li><img src="../images/2.jpg" alt="">li> <li><img src="../images/3.jpg" alt="">li> <li><img src="../images/7.jpg" alt="">li> <li><img src="../images/5.jpg" alt="">li> ul> <ul class="num">ul>div><script> $(function () { var slider =$("#scrollPics .slider"); //獲取圖片 var imgCon =$("#scrollPics .slider li"); //除第一張其余的圖片全部隱藏 imgCon.not(imgCon.eq(0)).hide(); //定義頁碼 var num =$("#scrollPics .num") //獲取li標(biāo)簽的長(zhǎng)度 //find()方法返回備選元素的后代元素 var len =slider.find("li").length; var html_page =""; index=0; //添加頁碼 for (var i=0;i if (i===0){ html_page+="
        6. "+(i+1)+"
        7. "
          } else { html_page +="
        8. "+(i+1)+"
        9. "
          } } //輸出原點(diǎn) num.html(html_page) //顯示索引對(duì)應(yīng)的圖片 function showPic(index) { imgCon.eq(index).show().siblings("li").hide(); num.find("li").eq(index).addClass("active").siblings("li").removeClass("active") } //原點(diǎn)點(diǎn)擊事件 $(".num li").click(function () { index=$(this).index() showPic(index) }) //圖片輪播 $("#scrollPics").hover(function () { clearInterval(window.timer) },function () { window.timer =setInterval(function () { showPic(index); index++; if (index ===len){ index =0 } },2000) }).trigger("mouseleave")//觸發(fā)備選元素的指定事件
          })script>body>html>

          推薦閱讀
          用vue實(shí)現(xiàn)一個(gè)仿簡(jiǎn)書的輪播圖效果
          JavaScript實(shí)現(xiàn)無縫輪播效果的思路
          原生js實(shí)現(xiàn)輪播圖實(shí)例教程

          本文完?

          瀏覽 33
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          分享
          舉報(bào)
          評(píng)論
          圖片
          表情
          推薦
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          分享
          舉報(bào)
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  免费黄色成人视频 | 久久深沈爱| 99人人操 | 成人先锋AV | 又粗又大又黄 |