简体   繁体   English

jQuery Animate和“ easeOutBounce”的问题

[英]Problems with jQuery Animate and “easeOutBounce”

I was hoping someone could help me with the following script: 我希望有人可以通过以下脚本帮助我:

jQuery(document).ready(function($) {
  $(".infoBoxBtn a").click(function(e){
      e.preventDefault();
      $("#info-box").animate({marginTop: '67px'}, 2000, 'easeOutBounce');

      $(".infoBoxBtn a").addClass("active");
  });

  $(".infoBoxBtn a.active").click(function(e){
      e.preventDefault();
      $("#info-box").animate({marginTop: '-434px'}, 2000, 'easeOutBounce');

      $(".infoBoxBtn a").removeClass("active");
  });

});//end

This is the error I get in Safari: 这是我在Safari中收到的错误:

TypeError: 'undefined' is not a function (evaluating 'f.easing[i.animatedProperties[this.prop]](this.state,c,0,1,i.duration)')

I have read the article about jQuery Animate on the jQuery API site, and I don't know what I'm doing wrong here. 我已经在jQuery API网站上阅读了有关jQuery Animate的文章,但我不知道我在做什么错。

Thanks! 谢谢! :) :)

Regarding your original answer - You need to load the jQuery UI effects library. 关于您的原始答案-您需要加载jQuery UI效果库。

About the closing animating, I would refactor your code to check each time the anchor is clicked to check the current status. 关于结束动画,每次单击锚点以检查当前状态时,我都会重构代码以进行检查。

Consider this code: 考虑以下代码:

$(function() {
  $('.infoBoxBtn a').on('click', function (e) {
    e.preventDefault();
    t = $(this);
    if (t.hasClass('active')) {
      margin_top = '-434px';
    }
    else {
      margin_top = '67px';
    }

    $('#info-box').stop(true, true).animate({ marginTop : margin_top }, 2000, 'easeOutBounce');
    t.toggleClass('active');
  });
});

Couple of things I changed: 我改变了几件事:

  • Used .on() instead of bind()/click() 使用.on()代替bind()/ click()
  • Used .hasClass() and .toggleClass() 使用过的.hasClass()和.toggleClass()
  • Used .stop() to clear your previous animating and jump to the end. 使用.stop()清除以前的动画并跳到最后。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM