[英]Using a Javascript function to add a background image on-top of a background color
I have a div
that is used for a piece in a game of checkers: 我有一个
div
,用于跳棋游戏:
<div class="blackCoin" ondblclick="makeKing(this)">
When, for example double clicked, I want to make the piece a king by adding a crown on top of the existing background color: 例如,当双击时,我想通过在现有背景色的顶部添加一个表冠使该作品成为国王:
function makeKing(obj){
obj.style.backgroundImage = "url('http://images.clipartpanda.com/black-crown-clipart-crown-md.png')";
}
Everything works fine with your code, the only thing you need to do is add background-size: contain;
一切都可以在您的代码上正常工作,您唯一需要做的就是添加
background-size: contain;
to the .blackCoin
class and it will work. 到
.blackCoin
类,它将起作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.