得到名为'notebutt'vith'oncklick'func
的按钮功能非常简单,用户点击按钮,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状态?
答案 0 :(得分:0)
在您的示例中,notediv已经是一个jquery对象:
function hideorshow(div){
if (div.is(':visible')) { //replace $(div) by div
//hide if visible
div.fadeOut();
} else {
div.offset({top: posT-47});
div.fadeIn();
}
};