jQuery toggle()方法的问题 [英] Issue with jQuery toggle() Method

查看:73
本文介绍了jQuery toggle()方法的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您能否看一下以下链接,让我知道为什么toggle()在代码中不起作用?

http://jsfiddle.net/GISMan/ZNkKZ/1/

这也是代码,

function fluctuate(bar) {
var hgt = Math.random() * 10;
hgt += 1;
var t = hgt * 30;
bar.animate({
    height: hgt
}, t, function() {
    fluctuate($(this));
});
}
$(".bar").each(function(i) {
fluctuate($(this));
});

$("button").toggle(function(){
$(".bar").stop();},
function(){
$(".bar").fluctuate();}
);

感谢您的评论

解决方案

演示 -已修复.

更改:

$(".bar").fluctuate();

收件人:

fluctuate($(".bar"));

Can you please take a look at following link and let me know why the toggle() is not working in the code?

http://jsfiddle.net/GISMan/ZNkKZ/1/

here is the code as well,

function fluctuate(bar) {
var hgt = Math.random() * 10;
hgt += 1;
var t = hgt * 30;
bar.animate({
    height: hgt
}, t, function() {
    fluctuate($(this));
});
}
$(".bar").each(function(i) {
fluctuate($(this));
});

$("button").toggle(function(){
$(".bar").stop();},
function(){
$(".bar").fluctuate();}
);

​ Thanks for your comments

解决方案

DEMOFixed.

Change:

$(".bar").fluctuate();

to:

fluctuate($(".bar"));

这篇关于jQuery toggle()方法的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆