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

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

使用 Javascript vanilla 動畫元素

使用 Javascript vanilla 動畫元素

瀟湘沐 2021-11-12 15:29:57
如何使用 Javascript vanilla 為元素設(shè)置動畫?與 jquery 類似。例子:$( "button.continue" ).animate({left: "100px", top: "200px"}, 5000);我們在何處傳遞屬性、所需值和時間。在我的情況下,我需要左側(cè)和頂部位置來制作動畫和滑動。解決方案我已經(jīng)完成了@IceMetalPunk sugested 并僅在需要動畫時才通過 css 添加動畫。document.getElementById("animate").addEventListener("click", function(){  let e = document.getElementById('elementToAnimate');  e.classList.add("animate");  setTimeout(()=> e.classList.remove("animate"), 500);  e.style.top = Math.floor(Math.random() * window.innerHeight) + 'px';  e.style.left = Math.floor(Math.random() * window.innerWidth) + 'px';});document.getElementById("dontAnimate").addEventListener("click", function(){  let e = document.getElementById('elementToAnimate');  e.style.top = Math.floor(Math.random() * window.innerHeight) + 'px';  e.style.left = Math.floor(Math.random() * window.innerWidth) + 'px';});#elementToAnimate {  width: 20px;  height: 20px;  background: red;  position: absolute;  top: 0;  left: 0;}#elementToAnimate.animate {  transition: left 500ms ease-in-out, top 500ms ease-in-out;}<div id="elementToAnimate"></div><button id="animate">Animate</button><button id="dontAnimate">Dont Animate</button>
查看完整描述

3 回答

?
交互式愛情

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

嘗試使用 CSS 過渡。在 CSS 中,做這樣的事情:


button.continue {

  transition: 5s;

}

然后在 JS 中,你可以只設(shè)置左/上值:


document.querySelectorAll('button.continue').forEach(button => {

  button.style.left = '100px';

  button.style.top = '200px';

});


查看完整回答
反對 回復(fù) 2021-11-12
?
慕尼黑5688855

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

在 Firefox 中測試。


document

   .querySelector(".text.thank-you")

   .animate({ opacity: [0, 1] }, { duration: 5000, iterations: 1, easing: "ease-out" })

   .onfinish = (e) => {

        e.target.effect.target.style.opacity = 1;

   };


查看完整回答
反對 回復(fù) 2021-11-12
?
翻閱古今

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

嘗試使用WebComponents,您可以執(zhí)行只使用任何類型的動畫VanillaJS,有預(yù)定義如動畫Animate.css,但你可以通過創(chuàng)建自定義動畫關(guān)鍵幀:


<!-- Add Web Animations Polyfill :) -->

<script src="https://cdnjs.cloudflare.com/ajax/libs/web-animations/2.3.2/web-animations.min.js"></script>


<script type="module" src="https://unpkg.com/@proyecto26/animatable-component@1.0.0/dist/animatable-component/animatable-component.esm.js"></script>

<script nomodule="" src="https://unpkg.com/@proyecto26/animatable-component@1.0.0/dist/animatable-component/animatable-component.js"></script>


<animatable-component

  autoplay

  easing="ease-in-out"

  duration="1200"

  delay="300"

  animation="heartBeat"

  iterations="Infinity"

  style="display: flex;align-self: center;"

>

  <h1>Hello World</h1>

</animatable-component>


有關(guān)更多詳細信息,請查看此處:https : //github.com/proyecto26/animatable-component


查看完整回答
反對 回復(fù) 2021-11-12
  • 3 回答
  • 0 關(guān)注
  • 183 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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