我希望能够单击并用png
切掉来更改背景(div)的颜色。
<body>
<div style="border: 1px solid red; width: 650px; height: 500px; margin: 0px auto; pointer-events: none; ;">
<div class="frame" style="background-color: blue; -webkit-mask-image: url('./assets/Layer1.png'); z-index: 0"></div>
<div class="frame" style="background-color: red; -webkit-mask-image: url('./assets/Layer2.png'); z-index: 1"></div>
<div class="frame" style="background-color: grey; -webkit-mask-image: url('./assets/Layer3.png'); z-index: 2"></div>
<div class="frame" style="background-color: yellow; -webkit-mask-image: url('./assets/Layer4.png'); z-index: 3"></div>
</div>
<style>
.frame {
position: absolute;
pointer-events: auto;
width: 640px;
height: 490px;
padding: 1px;
margin: 0px auto;
box-sizing: border-box;
}
</style>
</body>
答案 0 :(得分:1)
将ID添加到父div,并在其上单击处理程序。
let parent = document.getElementById('parent')
parent.addEventListener('click', function() {
parent.style.backgroundColor = event.target.style.backgroundColor;
})