簡體   English   中英

jquery animate() 方法不流暢

[英]jquery animate() method is not smooth

 $(document).ready(function() { $(".first").hover(function() { $(this).animate({ 'font-size': '20px', 'margin-top': '12px', 'font-weight': '600' }, 500) }) })
 .first { font-size: 16px; margin-top: 10px; }
 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> <link rel="stylesheet" href="style.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"> </script> </head> <body> <p class="first">Hello</p> </body> </html>

我嘗試使用 jquery animate() 方法為文本設置動畫。 但是動畫並不流暢。 我試圖延遲動畫並在css中使用transition屬性,但結果是一樣的。 我應該怎么做才能使動畫流暢?

當您想使用animate.css您應該以正確的方式使用屬性,例如在CSS margin-top: 20px is working 但在css.animate 中它不起作用,您應該像這樣寫marginTop: '20px'

筆記:
在 animate.css 中,您不應在屬性名稱中使用 "" 或 '',而應在值中使用它。

所以你應該使用這個:

$(document).ready(function() {
  $(".first").hover(function() {
    $(this).animate({
      fontSize: '20px',
      marginTop: '12px',
      fontWeight: '600'
    }, 500)
  })
})

這是你的代碼工作。 JSfiddle

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM