【发布时间】:2011-01-13 01:27:25
【问题描述】:
在 Safari 中使用 Webkit 的 CSS3;我有一个按钮,单击该按钮会导致 div 淡入。该 div 只是一个填充的大矩形,其中有几个按钮,其中一个会导致相同的 div 淡出。
问题是这样的:当元素淡出时(不透明度:0),并且我单击其中一个按钮所在的位置,onClick 仍然被触发。换句话说,即使看不到按钮(不透明度:0),它仍然存在并且是事件模型的一部分。我不想要那个。
按钮调用以下函数:
// This displays the overlay (popup)
function showCategoryPopup() {
// Was playing with the following, but with no success.
// popupCategory.style.display = "block";
// popupCategory.style.visibility = "visible";
// Change the attributes that will be animated.
popupCategory.style.opacity = 1;
popupCategory.style.webkitTransform = "scale(1.0)";
}
function hideCategoryPopup() {
// Change the animated attributes
popupCategory.style.opacity = 0;
popupCategory.style.webkitTransform = "scale(0.7)";
// Even if opacity is 0, we still get mouse events. So, make it hidden?
// popupCategory.style.visibility = "hidden";
// popupCategory.style.display = "none";
}
叠加层的 CSS 类是这样的:
.popupContainer {
opacity: 0;
-webkit-transform: scale(0.7);
-webkit-transition-duration: 0.3s;
-webkit-transition-timing-function: ease-in-out;
-webkit-transition-delay: initial;
}
如果我根本不使用可见性或显示设置,则动画很好,但是会为不可见的项目触发 mouseClick 事件。
如果我使用积木,它会在没有动画的情况下打开/关闭。
如果我使用显示样式,那么它会起作用,但不是立即显示动画,而是仅在页面中的其他事件被触发时触发,例如页面上其他位置的另一个按钮。
我想可能会在隐藏后将“指针事件:无”添加到弹出 div 使用的样式中,但我所要求的似乎是你经常遇到的不透明度,所以它必须是一个半常见的问题。
想法?
【问题讨论】: