简体   繁体   English

更改未点击按钮的按钮不透明度

[英]Change button opacity of buttons that are not clicked

Hi I've got a question in how I would change the opacity of a list of buttons where if a button is clicked, the opacity of the rest of the buttons would change to 0.5.嗨,我有一个问题,我将如何更改按钮列表的不透明度,如果单击按钮,则按钮的 rest 的不透明度将更改为 0.5。 And the one that was clicked would remain at 1.并且被点击的那个将保持在 1。

So far I've got the below where I can change the opacity of the button that's clicked but struggling to achieve what I've said above.到目前为止,我已经获得了以下内容,我可以在其中更改单击的按钮的不透明度,但努力实现我上面所说的。 In jquery I know you can use.not(this) but not sure how to do this is JS.在 jquery 我知道你可以使用.not(this) 但不知道如何做到这一点是 JS。

EDIT: In my buttons I also have a span tag which holds the copy.编辑:在我的按钮中,我还有一个保存副本的 span 标签。 When you click on the span tag this looks to cause issues with the opacity as well.当您单击跨度标签时,这看起来也会导致不透明度问题。

Button would like this, my apologies for not adding this in at the start Button 想要这个,我很抱歉没有在一开始就添加这个

 <button class="variantClass"> <span>Button</span> </button

 var buttonSelector = document.querySelectorAll('button.variantClass'); buttonSelector.forEach(function (el){ el.addEventListener("click", function(){ this.style.opacity = "0.5"; }) });
 .variantClass { background: black; color: white; padding: 30px;}
 <button class="variantClass"> Button </button> <button class="variantClass"> Button </button> <button class="variantClass"> Button </button> <button class="variantClass"> Button </button> <button class="variantClass"> Button </button> <button class="variantClass"> Button </button>

 var buttonSelector = document.querySelectorAll('button.variantClass'); buttonSelector.forEach(function (el){ el.addEventListener("click", function(ev){ buttonSelector.forEach(function(button) { button.style.opacity = '0.5' }) this.style.opacity = 1 }) });
 .variantClass { background: black; color: white; padding: 30px;}
 <button class="variantClass"> <span>Button</span> </button> <button class="variantClass"> <span>Button</span> </button> <button class="variantClass"> <span>Button</span> </button> <button class="variantClass"> <span>Button</span> </button> <button class="variantClass"> <span>Button</span> </button> <button class="variantClass"> <span>Button</span> </button>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 更改单击的li元素的不透明度 - change opacity of clicked li element 单击时更改按钮 - Change Buttons when Clicked 一旦使用CSS单击单个按钮,如何更改其他两个按钮的不透明度背景颜色 - How to change the opacity background color of other two buttons once we click on a single button using css 在 React 中的一组按钮,如何在单击后更改颜色,同时还记录单击了哪些按钮/按钮? - in React for an array of buttons, how to change color after click while also record which button/buttons is/are clicked? 如何更改传单上缩放按钮的不透明度? - how to change opacity of zoom buttons on leaflet? 如何使用javascript和按钮更改图像的不透明度? - How to change opacity of images with javascript and buttons? 单击时更改按钮的类别 - Change class of buttons when clicked 更改一个按钮的背景颜色onClick并将以前单击的按钮恢复为默认背景(8个按钮) - Change one button background color onClick and revert previously clicked button to default background (8 Buttons) 单击按钮时,使用 reactjs 更改单击按钮的类名以及该组中的其他按钮 - on clicking button, change classname of the clicked button as well as other buttons in that group using reactjs 勾选以在按钮上显示按钮,并在单击时降低其不透明度 - tick to be displayed button on button and to reduce its opacity when it's clicked
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM