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

时间:2020-03-09 17:44:59

标签: jquery web

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

  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)

1 个答案:

答案 0 :(得分:0)

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

var newstyle
var animate_demo = function() {
  newstyle = {
    'font-size': '250%',
    'letter-spacing': '0.5em'
  }
  $('#animations h2').animate(newstyle, 1000)
}
var 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">Click me</div>
<div id="animations">
  <h2>Text to animate</h2>
</div>