admin管理员组文章数量:1279083
How do I do the following pseudo code in JQuery?
$(document).ready(function(){
$(".btn-slide").click(function(){
$("#divToSlide").slideToggle("fast");
if ($(this).isToggled) { // <---- DOESN'T WORK -------
// do something when toggled
} else {
// do something different when not toggled
}
});
});
How do I do the following pseudo code in JQuery?
$(document).ready(function(){
$(".btn-slide").click(function(){
$("#divToSlide").slideToggle("fast");
if ($(this).isToggled) { // <---- DOESN'T WORK -------
// do something when toggled
} else {
// do something different when not toggled
}
});
});
Share
Improve this question
edited Apr 23, 2010 at 5:47
Timj
asked Apr 23, 2010 at 5:42
TimjTimj
14.2k3 gold badges19 silver badges9 bronze badges
2
-
$(this)
is referring to$(".btn-slide")
which is not toggled.... am i lost??? – Reigel Gallarde Commented Apr 23, 2010 at 5:55 -
I believe you might be having a problem with the fact that it is an animation and possibly still in progress when you get to the
isToggled
part of the code. – SeanJA Commented Apr 23, 2010 at 5:58
4 Answers
Reset to default 4Or you could just use the toggle function: http://api.jquery./toggle/
$('#target').toggle(function() {
alert('First handler for .toggle() called.');
}, function() {
alert('Second handler for .toggle() called.');
});
Note: You can have as many toggles as you want, just add more functions:
$('#target').toggle(function() {
alert('1 handler for .toggle() called.');
}, function() {
alert('2 handler for .toggle() called.');
}, function() {
alert('3 handler for .toggle() called.');
}, function() {
alert('4 handler for .toggle() called.');
}, function() {
alert('5 handler for .toggle() called.');
});
[EDIT]
$('a.toggleButton').toggle(function() {
$("#divToSlide").slideDown("fast");
// do something when toggled
}, function() {
$("#divToSlide").slideUp("fast");
// do something when toggled });
});
Try using a callback function for slideToggle
$(document).ready(function(){
$(".btn-slide").click(function(){
$("#divToSlide").slideToggle("fast", function(){
if ($(this).is(":visible")) { // <---- DOESN'T WORK -------
// do something when toggled
}
else {
// do something different when not toggled
}
});
});
});
$(document).ready(function(){
$(".btn-slide").click(function(){
if ('#divToSlide').is(':visible')) {
// do something when toggled
} else {
// do something different when not toggled
}
});
});
try:
$(document).ready(function(){
$(".btn-slide").click(function(){
$("#divToSlide").toggle(
function() {
// do something when toggled
$(this).slideUp();
},
function(){
// do something different when not toggled
$(this).slideDown();
}
);
});
本文标签: javascriptJQuery How do I determine if a slideToggle has been toggledStack Overflow
版权声明:本文标题:javascript - JQuery: How do I determine if a slideToggle has been toggled? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741296641a2370857.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论