简体   繁体   English

jQuery动画-扩展正确的文本内容?

[英]jQuery animate - expanding the right text content?

Hi I am trying to animate or give any slide effect for toggling the class (the actual expanding), as it is a bit simple at the moment 嗨,我正在尝试制作动画或提供任何幻灯片效果来切换课程(实际的扩展),因为目前这有点简单

Here is the fiddle I am working on with your help at the moment, but it is not doing anything and cannot figure it out 这是我目前正在您的帮助下进行的小提琴 ,但是它什么也没做,无法解决。

$(document).ready(function(){
  $(".gamewrapper").click(function(){
    $(".game-name", this).toggleClass("black");
    $(this).toggleClass("expand", 1000);
  });
});

Any help appreciated please, 任何帮助,请,

Thanks in advance 提前致谢

jQuery's .toggleClass() method only takes 1 parameter, the 1000 you've got in there isn't doing anything. jQuery的.toggleClass()方法仅使用1个参数,您在其中获得的1000参数不执行任何操作。

If you want to animate the css changes between having the expand class and not, you have to: 如果要动画化在具有expand类与不具有expand类之间的css更改,则必须:

1) Use CSS transitions on those properties: 1)在这些属性上使用CSS过渡:

http://www.w3schools.com/css3/css3_transitions.asp http://www.w3schools.com/css3/css3_transitions.asp

2) Use another plugin. 2)使用其他插件。 jQueryUI has a switchClass plugin that does that. jQueryUI有一个switchClass插件可以做到这一点。

http://jqueryui.com/switchClass/ http://jqueryui.com/switchClass/

I agree with Nicholas, 我同意尼古拉斯,

CSS3 Transitions, jQueryUI or you could also animate all individual styles using jQuery.animate. CSS3 Transitions,jQueryUI或您也可以使用jQuery.animate为所有样式设置动画。

Eg 例如

$('.classname').animate({'width':'100px','height':'100px'},200)

The jQuery UI toggleClass method is a built-in jQuery method override: jQuery UI toggleClass方法是内置的jQuery方法重写:

jQuery UI overrides several built-in jQuery methods in order to provide additional functionality. jQuery UI覆盖了几种内置jQuery方法,以提供其他功能。 When using these overrides, it's important to make sure that jQuery UI is loaded. 使用这些替代时,确保已加载jQuery UI非常重要。 If jQuery UI is not loaded, the methods will still exist, but the expected functionality will not be available, resulting in bugs that may be hard to track down 如果未加载jQuery UI,则这些方法将仍然存在,但是预期的功能将不可用,从而导致可能难以跟踪的错误。

the method accept an easing parameter as you are doing: 该方法在执行操作时接受一个缓动参数:

easing (default: swing) Type: String A string indicating which easing function to use for the transition. 缓动(默认值:swing)类型:字符串一个字符串,指示用于过渡的缓动功能。

the problem in your fiddle is that you are not including the jQuery UI library. 摆弄的问题是您不包括 jQuery UI库。

Working animation fiddle: http://jsfiddle.net/YqxAR/53/ 工作动画小提琴: http : //jsfiddle.net/YqxAR/53/

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

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