gpt4 book ai didi

Javascript onclick 只工作一次

转载 作者:太空宇宙 更新时间:2023-11-04 13:46:02 26 4
gpt4 key购买 nike

所以我做了这个,

var Coin = document.getElementById("coin");

Coin.onclick = function() {
Coin.style.webkitTransform = "rotateY(1800deg)";
Coin.style.MozTransform = "rotateY(1800deg)";
Coin.style.msTransform = "rotateY(1800deg)";
Coin.style.OTransform = "rotateY(1800deg)";
Coin.style.transform = "rotateY(1800deg)";
}

发现于:https://jsfiddle.net/dkjufqn0/

在其中,一枚硬币在旋转。但是,它只会触发一次。我第一次点击它。之后它不会再开火。帮助!

最佳答案

每次点击硬币时它都保持在 1800 度,要在每次点击时旋转它,您需要增加它的度数,如下例所示:

https://jsfiddle.net/dkjufqn0/1/

var Coin = document.getElementById("coin");
var degrees = 0;
Coin.onclick = function() {
degrees += 1800;
console.log(degrees)
Coin.style.webkitTransform = "rotateY(" + degrees + "deg)";
Coin.style.MozTransform = "rotateY(" + degrees + "deg)";
Coin.style.msTransform = "rotateY(" + degrees + "deg)";
Coin.style.OTransform = "rotateY(" + degrees + "deg)";
Coin.style.transform = "rotateY(" + degrees + "deg)";
}
body {
-webkit-transform: perspective(500px);
-webkit-transform-style: preserve-3d;
}

.coin {
background-image: url("http://coins.thefuntimesguide.com/images/blogs/presidential-dollar-coin-reverse-statue-of-liberty-public-domain.png");
background-size: 100% 100%;
border-radius: 100%;
height: 100px;
margin: 50px auto;
position: relative;
width: 100px;
-webkit-transition: 2s linear;
-webkit-transform-style: preserve-3d;
}
<div class="coin" id="coin"></div>

关于Javascript onclick 只工作一次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34946959/

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