第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

輪播圖的制作原理?

輪播圖的制作原理?

如上圖設(shè)計原型,網(wǎng)上找不到類似的輪播插件。嘗試自己制作,沒有較好的js思路。畢竟它跟大多數(shù)的輪播圖有點(diǎn)差距:1、首屏顯示了三張圖片。2、左右圖片僅顯示一部份,如左圖隱藏了左邊部分,右圖隱藏了右邊部份。3、每張圖片之間均有一定的間距。4、中間的大圖比兩邊的圖片顯示尺寸變大。(所有圖片都是16:9)
查看完整描述

1 回答

?
萬千封印

TA貢獻(xiàn)1891條經(jīng)驗 獲得超3個贊

唉~ 寫了半天~ 累啊

<!DOCTYPE html><html>

<head>

  <meta http-equiv="Cache-Control" content="no-transform " /> 

  <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">

  <meta http-equiv="X-UA-Compatible" content="chrome=1" />

  <meta name="renderer" content="webkit" />

  <meta name="viewport" content="width=device-width, initial-scale=1.0" />

  <title>輪播圖 | 杰凱寇贊</title>

  <style>

  html,body {height: 100%}

  html {background: #222;color:#fff;} body {margin: 0;font-family: Roboto,Helvetica,Arial,Microsoft JhengHei,sans-serif}


  .viewport {width: 944px;height:283px;position: relative;overflow: hidden;}

  .father {width:3000%;height:100%;padding: 20px 0;box-sizing: border-box;transition: transform 0.6s ease-in-out;transform: translate3d(0,0,0);background: #ff5252;}

  .father.moving {transition-duration: 0s;}

  .father > div {width: 432px;height: 243px;margin: 0 20px;opacity:0.6;transition: all 0.6s ease-in-out;background: #2dbe60;float: left;}

  .father.moving > div {transition-duration: 0s;}

  .father > div.showing {opacity: 1;transform: scale3d(1.1, 1.1, 1);}


  .left, .right {width: 30px;height: 100%;line-height: 283px;user-select:none;text-align: center;cursor: pointer;background: rgba(0,0,0,0.15);position: absolute;top: 0;}

  .left {left: 0;} .right {right: 0;}

  </style>

</head>

<body>

  <div class="viewport">

    <div class="father" id="father">

      <div>A</div><!-- 1 -->

      <div>B</div>

      <div>C</div><!-- 3 -->

      <div>D</div>

      <div>E</div><!-- 5 -->

      <div>F</div>

      <div>G</div><!-- 7 -->

<!-- ^…^ -->

      <div>A</div><!-- 1 -->

      <div>B</div>

      <div>C</div><!-- 3 -->

      <div>D</div>

      <div>E</div><!-- 5 -->

      <div>F</div>

      <div>G</div><!-- 7 -->

<!-- Counting is too hard. -->

      <div>A</div><!-- 1 -->

      <div>B</div>

      <div>C</div><!-- 3 -->

      <div>D</div>

      <div>E</div><!-- 5 -->

      <div>F</div>

      <div>G</div><!-- 7 -->

    </div>

    <div class="left" id="left">:-o</div>

    <div class="right" id="right">:-)</div>

  </div>

<script type="text/javascript">

var father=document.getElementById("father"),

  sons=father.children,

  sonsLength=sons.length/3,

  showWidth=432+20*2, //432: width; 20*2: margin*2

  showingId=parseInt(sonsLength/2)+sonsLength-1,

  transform=-showingId*showWidth+showWidth/2,

  checkTime=new Date()


father.style.transform=`translate3d(${transform}px, 0, 0)`

sons[showingId].className="showing"


function go(nowShowingId, direction) {

  // Direction: "-1" stands for left, "1" stands for right.

  //+ Avoid continuous sliding

  if(new Date()-checkTime<700)return

  checkTime=new Date()

  //+ Standard show change

  sons[nowShowingId].className=""

  //- Change here

  nowShowingId=nowShowingId+direction

  showingId=nowShowingId;

  transform=nowShowingId*showWidth-showWidth/2

  father.style.transform=`translate3d(-${transform}px, 0, 0)`

  sons[nowShowingId].className="showing"

  //+ Special show change

  if(nowShowingId==1){

    showingId=sonsLength*2+1 // How does it works?

  }

  else if(nowShowingId==sonsLength*2+2){

    showingId=1+1 // Imagine the answer. (Use DevTools!

  }

  else {return}

  //- change here

  setTimeout(function(){

    father.classList.add("moving")

    sons[showingId].className="showing"

    setTimeout(function(){

      father.style.transform=`translate3d(-${showingId*showWidth-showWidth/2}px, 0, 0)`

      sons[nowShowingId].className=""

      setTimeout(function(){

        father.classList.remove("moving")

      },50) // =1.

    },530) // =2.

  },100) // =3. /= 1,2,3: Specified like that because of setTimeout's time error

}


document.getElementById("left").onclick=function (){go(showingId, -1)}

document.getElementById("right").onclick=function (){go(showingId, 1)}

</script>

</body></html>

原理可以參考隨后這篇文章新貨!如何制作一個高效輪播圖?

查看完整回答
反對 回復(fù) 2018-11-15
  • 1 回答
  • 0 關(guān)注
  • 700 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號