gpt4 book ai didi

javascript - 避免在一个低于另一个的 div 上发生鼠标事件

转载 作者:行者123 更新时间:2023-11-29 23:17:28 26 4
gpt4 key购买 nike

我正在尝试实现“翻牌”的效果。在前面,我有一个有点击事件的元素,每次你点击它(.link)。后面什么也没有,但是当我将光标传递到前面具有 .link 类的元素处时,将执行单击事件。

enter image description here

我想将元素与后面部分的元素完全隔离。我该怎么做?

<div class="scene scene--card">
<div class="card">
<div class="card__face card__face--front">
<a class="front_button link">
text
</a>

</div>
<div class="card__face card__face--back">
back
</div>
</div>
</div>

.scene {
width: 200px;
height: 300px;
border: 1px solid #CCC;
margin: 40px 0;
perspective: 600px;
}

.card {
width: 100%;
height: 100%;
transition: transform 1s;
transform-style: preserve-3d;
position: relative;
}

.card.is-flipped {
transform: rotateY(180deg);
}

.card__face {
position: absolute;
width: 100%;
height: 100%;
line-height: 260px;
color: white;
text-align: center;
font-weight: bold;
font-size: 40px;
backface-visibility: hidden;
}

.card__face--front {
background: red;
}

.card__face--back {
background: blue;
transform: rotateY(180deg);
}

.front_button{
background:yellow;
height:200px;
width:100%;
position:absolute;
bottom:0px;
left:0px;
cursor: pointer;
}

.link{
border:1px solid red;
}

var card = document.querySelector('.card');
card.addEventListener( 'click', function() {
card.classList.toggle('is-flipped');
});


var link = document.querySelector('.link');
link.addEventListener( 'click', function() {
alert("link");
});

这是我的代码:

https://codepen.io/anon/pen/pOWONW

来自@Temani 用户的测试代码 enter image description here

最佳答案

当卡片具有类 is-flipped 时,从链接中删除指针事件。

.card.is-flipped .front_button.link {
pointer-events: none;
}

var card = document.querySelector('.card');
card.addEventListener( 'click', function() {
card.classList.toggle('is-flipped');
});


var link = document.querySelector('.link');
link.addEventListener( 'click', function(e) {
e.stopPropagation();
alert("link");
});
body { font-family: sans-serif; }

.scene {
width: 200px;
height: 300px;
border: 1px solid #CCC;
margin: 40px 0;
perspective: 600px;
}

.card {
width: 100%;
height: 100%;
transition: transform 1s;
transform-style: preserve-3d;
position: relative;
}

.card.is-flipped {
transform: rotateY(180deg);
}

.card.is-flipped .front_button.link {
pointer-events: none;
}

.card__face {
position: absolute;
width: 100%;
height: 100%;
line-height: 260px;
color: white;
text-align: center;
font-weight: bold;
font-size: 40px;
backface-visibility: hidden;
}

.card__face--front {
background: red;
}

.card__face--back {
background: blue;
transform: rotateY(180deg);
}

.front_button{
background:yellow;
height:200px;
width:100%;
position:absolute;
bottom:0px;
left:0px;
cursor: pointer;
}

.link{
border:1px solid red;
}
<div class="scene scene--card">
<div class="card">
<div class="card__face card__face--front">
<a class="front_button link">
text
</a>
</div>
<div class="card__face card__face--back">
back
</div>
</div>
</div>
<p>Click card to flip.</p>

关于javascript - 避免在一个低于另一个的 div 上发生鼠标事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52212600/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com