Jquery UI SlideUp 和 SlideDown
我正忙着通过单击按钮来显示和隐藏一些框。它运行良好,但我第一次想隐藏一个框时必须单击两次?
这是我的 JS 代码:
$(function() {
$('.title .hide').showContent();
});
$.fn.showContent = function() {
return this.each(function() {
var box = $(this);
var content = $(this).parent().next('.content');
box.toggle(function() {
content.slideDown(400);
}, function() {
content.slideUp(400);
});
});
};
和 de HTML
<div class="box">
<div class="title">
Title
<span class="hide"></span>
</div>
<div class="content">Content</div>
</div>
这是为什么?有人可以帮助我吗?
这是一个演示: http://jsfiddle.net/wq7PF/ (单击黑色按钮。当第一次单击时它什么也不做,但第二次单击时内容将崩溃。)
I am busy to show and hide some boxes with a click on a button. It is working well but i must click 2 times the first time i want to hide a box?
This is my JS code:
$(function() {
$('.title .hide').showContent();
});
$.fn.showContent = function() {
return this.each(function() {
var box = $(this);
var content = $(this).parent().next('.content');
box.toggle(function() {
content.slideDown(400);
}, function() {
content.slideUp(400);
});
});
};
And de HTML
<div class="box">
<div class="title">
Title
<span class="hide"></span>
</div>
<div class="content">Content</div>
</div>
Why is this? Can somewone help me?
And here is a demo: http://jsfiddle.net/wq7PF/ (click on the black button. When you click the first time it is doing nothing, but the second time then the content will collapse.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
反转你的功能
Reverse your functions