gpt4 book ai didi

javascript - 不需要的元素突出显示

转载 作者:太空宇宙 更新时间:2023-11-04 00:36:19 25 4
gpt4 key购买 nike

所以我有一个点导航,但是当我在第三个点下方或三个点的左侧单击一次时,有一个红色框突出显示,我已经尝试过 user-select: none 或即使是 ::selection 属性并将背景颜色设置为透明,但突出显示仍然存在,是否有任何其他 css 属性或方法可以取消它?

$(document).ready(() => {
document.getElementById("event").addEventListener("click", e => {
const allItems = $('#event > li');

for (let i = 0; i < allItems.length; i++) {
allItems[i].classList.remove("is-active");
}
e.target.classList.add("is-active");
})
});
html{
user-select: none;
}

::selection{
background-color: transparent;
}

.is-active{
transform: scale(1.2);
background: red !important;
}

#vertical-nav {
position: fixed;
z-index: 3;
right: 15px;
bottom: 0;
margin: auto 0;
height: 100%;
display: flex;
align-items: center;
}
#vertical-nav ul > li {
background: black;
width: 13px;
height: 13px;
margin-bottom: 15px;
border-radius: 50%;
transition: 0.4s ease-in-out;
}
#vertical-nav ul > li a {
display: none;
float: right;
color: black;
margin-right: 13px;
margin-top: -5px;
font-size: 10px;
transition: 0.4s ease-in-out;
padding: 3px;
border-radius: 10px;
}
#vertical-nav ul > li:hover {
cursor: pointer;
transform: scale(1.2);
background: lightgrey;
}
#vertical-nav ul > li:hover a {
//opacity: 1;
}
#vertical-nav ul > li:hover a {
//opacity: 1;
}

ul > li {
list-style-type: none;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<nav id="vertical-nav">
<ul id="event">
<li>
<a data-number="1">Home</a>
</li>
<li>
<a data-number="2">About</a>
</li>
<li>
<a data-number="3">Contact</a>
</li>
</ul>
</nav>

最佳答案

因为你是在给整个容器添加事件监听器。你应该只瞄准子弹。由于您使用的是 jQuery,因此您还可以简化代码:

$(document).ready(() => {
$("#event > li").click(function() {
$('#event > li').removeClass('is-active')

$(this).addClass("is-active");
})
});
html {
user-select: none;
}

::selection {
background-color: transparent;
}

.is-active {
transform: scale(1.2);
background: red !important;
}

#vertical-nav {
position: fixed;
z-index: 3;
right: 15px;
bottom: 0;
margin: auto 0;
height: 100%;
display: flex;
align-items: center;
}

#vertical-nav ul>li {
background: black;
width: 13px;
height: 13px;
margin-bottom: 15px;
border-radius: 50%;
transition: 0.4s ease-in-out;
}

#vertical-nav ul>li a {
opacity: 0;
float: right;
color: black;
margin-right: 13px;
margin-top: -5px;
font-size: 10px;
transition: 0.4s ease-in-out;
padding: 3px;
border-radius: 10px;
}

#vertical-nav ul>li:hover {
cursor: pointer;
transform: scale(1.2);
background: lightgrey;
}

#vertical-nav ul>li:hover a {
//opacity: 1;
}

#vertical-nav ul>li:hover a {
//opacity: 1;
}

ul>li {
list-style-type: none;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<nav id="vertical-nav">
<ul id="event">
<li>
<a data-number="1">Home</a>
</li>
<li>
<a data-number="2">About</a>
</li>
<li>
<a data-number="3">Contact</a>
</li>
</ul>
</nav>

关于javascript - 不需要的元素突出显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59333772/

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