[英]Toggling a absolute DIV is not working after firsttime
$('.pallete').hide();
$(document).delegate('.pick', 'click', function () {
var pos = $(this).offset();
var x = pos.left - $(window).scrollLeft() + $(this).width();
var y = pos.top - $(window).scrollTop() + $(this).height();
$('.pallete').css({
top: y + "px",
left: x + "px",
}).show();
});
$(document).delegate('.col', 'click', function () {
var pos = $(this).css('background-color');
$('.pick').css('background-color', pos);
$(this).parents('div').fadeOut();
});
这是小提琴, http://jsfiddle.net/zPNk3/5/ 。 问题是,当我第一次单击.pick
元素时,“。palette”元素正确显示。 但是,当我下次单击时,该按钮不起作用。
当您执行$(this).parents('div').fadeOut()
,您正在淡出该元素的所有 <div>
父级。 您只显示.pallete
。
尝试:
$(this).closest('.pallete').fadeOut();
查看不应该隐藏的div行,
$(document).delegate('.col', 'click', function () {
var pos = $(this).css('background-color');
$('.pick').css('background-color', pos);
//$(this).parents('div').fadeOut(); // this is wrong
$(this).parent().parent().fadeOut(); // fixed
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.