为什么我的代码无法运行我的jquery代码?

问题描述 投票:0回答:1

嗨,我不知道我的代码有什么问题,有人可以帮助我吗?

animate_demo = function() {
newstyle = {
  'font-size': '250%',
  'letter-spacing': '0.5em'
}
setup = function() {
  jQuery('#demo').click(animate_demo)

  jQuery('#animations h2').animate(newstyle, 1000)
}
jQuery(document).ready(setup)
jquery jquery-animate
1个回答
0
投票

您需要在.animate上呼叫click。检查以下代码:

let newstyle
let animate_demo = function() {
  newstyle = {
    'font-size': '250%',
    'letter-spacing': '0.5em'
  }
  $('#animations h2').animate(newstyle, 1000)
}
let setup = function() {
  $('#demo').click(animate_demo)
}
$(document).ready(setup)
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="demo">demo</div>
<div id="animations">
  <h2>Text to animate</h2>
</div>
© www.soinside.com 2019 - 2024. All rights reserved.