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

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

用于在頁面上逐步滑動點的對象內(nèi)的復合值

用于在頁面上逐步滑動點的對象內(nèi)的復合值

繁華開滿天機 2021-11-04 15:58:11
我無法讓變量作為我對象中的 translateX 值正常運行。每次單擊下一個按鈕時,我都想讓點在頁面上滾動。我的代碼只能在第一步來回移動它。我是動畫 API 的新手,我已經(jīng)使用 CSS 轉換完成了這項工作,但我正在嘗試很好地處理 API。html:<div class="progress__container">                <div class="progress__bar">                        <div id="progress__fill" class="step1"></div>                        <div class="circ" id="circ__1"></div>                        <div class="circ" id="circ__2"></div>                        <div class="circ" id="circ__3"></div>                        <div class="circ" id="circ__4"></div>                        <div id="progress__dot" class="prog__1"></div>                    </div>            <div class="backBar"></div>            <div class="flexrow">                    <span class="stepName">Account</span>                    <span class="stepName">Frequency</span>                    <span class="stepName">Amount</span>                    <span class="stepName">Taxes</span>                </div>            <div class="button__container">                <button class="buttonStep" id="back">Back</button>                <button class="buttonStep is-active" id="next">Next</button>            </div>    </div>js:// give a starting value for the transformationvar startVal = 0;// define the keyframesvar moveDot = [    { transform: `translateX(${startVal}px)`},    { transform: `translateX(${startVal + 190}px)`}  ];// definte the timingvar dotTiming = {    duration: 400,      fill: "forwards",      easing: 'ease-in',} // make the animation happenvar movingDot = document.getElementById("progress__dot").animate(    moveDot,    dotTiming  );//  pause the animation until calledmovingDot.pause();    // on click fire the animationdocument.getElementById('next').addEventListener('click', function() {    movingDot.playbackRate = 1;    if (startVal <= 380) {        movingDot.play();        startVal += 190;    } });按照我的設置方式,我希望 translateX 值根據(jù)單擊事件偵聽器而增加或減少,這將使圓圈在頁面上滑動。實際發(fā)生的是,只有第一步有效。它不會超過第一個停止點。如果我在控制臺中記錄 moveDot,它會給我我期望的值,但它只會在 0 和 190 處啟動/停止。后退按鈕的功能相同。
查看完整描述

1 回答

?
繁星淼淼

TA貢獻1775條經(jīng)驗 獲得超11個贊

它每次都在同一個地方進行動畫處理。將 的定義移動moveDot到事件偵聽器中:


// give a starting value for the transformation

var startVal = 0;


// definte the timing

var dotTiming = {

  duration: 400,

  fill: "forwards",

  easing: 'ease-in',

}


// on click fire the animation

document.getElementById('next').addEventListener('click', function() {

  if (startVal > 380){return;}


  // define the keyframes

  var moveDot = [{transform: `translateX(${startVal}px)`},

    {transform: `translateX(${startVal + 190}px)`}];


  // make the animation happen

  var movingDot = document.getElementById("progress__dot").animate(

    moveDot,

    dotTiming

  );


  movingDot.playbackRate = 1;



  movingDot.play();

  startVal += 190;




});



document.getElementById('back').addEventListener('click', function() {

  movingDot.playbackRate = -1;

  if (startVal >= 0) {

    movingDot.play();

    startVal -= 190;

  }


});


查看完整回答
反對 回復 2021-11-04
  • 1 回答
  • 0 關注
  • 171 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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