【发布时间】:2012-11-02 23:35:22
【问题描述】:
通过“oncklick”函数获得了名为“notebutt”的按钮
功能很简单,用户点击按钮,div为fadeIn(),再次点击,div必须fadeout();
notebutt.bind("click", function () {
var notediv = $(this).parent().find("div.notediv");
// checking is notediv exist already, if not, creating one and do fadeIn(150);
if (!notediv) {
notediv = $('<div class="notediv" contenteditable="true"></div>');
notediv.appendTo($(this).parent());
notediv.offset({top: posT-47}).fadeIn(150);
} else {
// if got notediv created before, i must show or hide it with hideorshow(notediv);
hideorshow(notediv);
}
});
// func that check's is div was showned or not
function hideorshow(div){
if ($(div).is(':visible')) {
//hide if visible
div.fadeOut();
} else {
div.offset({top: posT-47});
div.fadeIn();
}
};
乍一看它应该可以正常工作,但是在单击按钮 5 到 10 次后都会出错, div 在单击时随机闪烁,就像fadeIn 和fadeOut 同时运行或彼此运行一样 有什么方法可以让一些适当的触发器来检查 div 状态吗?
【问题讨论】:
-
使用 toggle() - api.jquery.com/toggle
-
我需要类似 var status = 0;
-
稍后使用 if (status == 1) { do something and hide div} else { do other things} 但我不知道如何使其工作
标签: jquery fadein fadeout eventtrigger