【问题标题】:jquery animate() method is not smoothjquery animate() 方法不流畅
【发布时间】:2020-01-26 08:39:58
【问题描述】:

$(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属性,但结果是一样的。我应该怎么做才能使动画流畅?

【问题讨论】:

  • 我觉得够流畅了!你还有什么期待?
  • 您可以在没有 jquery animate 功能的情况下实现这一点。使用 css transition 属性并在 hover 上应用相同的样式。

标签: javascript jquery html css


【解决方案1】:

当你想使用 animate.css 时,你应该以正确的方式使用属性,例如在 CSSmargin-top: 20px 工作但在 css.animate 中它不是工作,你应该这样写marginTop: '20px'

注意:
在 animate.css 中,您不应该在属性名称中使用 "" 或 '',而只在值中使用它。

所以你应该使用这个:

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

这是你的代码工作。 JSfiddle

【讨论】:

  • @Pedram 在 css.animate 中你应该以它的方式使用属性,例如在 css margin-top: 20px 工作但在 css.animate 这不起作用,你应该这样写 marginTop: '20px'
  • 动画还是不流畅!
猜你喜欢
  • 2023-02-09
  • 1970-01-01
  • 2012-05-15
  • 1970-01-01
  • 2018-07-28
  • 1970-01-01
  • 1970-01-01
  • 2011-07-09
  • 1970-01-01
相关资源
最近更新 更多