I'm trying to get planets to orbit around a sun (like our solar system) but pause when you hover over them. I have tried using IDs and classes but with no success. Here is my code (Done for all planets):
var divs = document.getElementsByClassName("planet");
if(true == true) {
for(var i = 0; i < divs.length; i++){
divs.onmouseover = function() {mouseOver(i)}
divs.onmouseout = function() {mouseOut(i)}
}
}
function mouseOver(d) {
var orbitOver = document.getElementById(d.id + "-orbit");
orbitOver.style.animation-play-state = paused;
}
function mouseOut(d) {
var orbitOut = document.getElementById(d.id + "-orbit");
orbitOut.style.animation-play-state = running;
}
#jupiter {
position: absolute;
top: 0;
left: 50%;
height: 50px;
width: 50px;
margin-left: -25px;
margin-top: -25px;
border-radius: 50%;
background: -moz-linear-gradient(top, #a39f68 1%, #e2e2e2 13%, #e2e2e2 13%, #96875e 28%, #ededed 44%, #96875e 59%, #96875e 59%, #a39f68 78%, #96875e 100%);
background: -webkit-linear-gradient(top, #a39f68 1%,#e2e2e2 13%,#e2e2e2 13%,#96875e 28%,#ededed 44%,#96875e 59%,#96875e 59%,#a39f68 78%,#96875e 100%);
background: linear-gradient(to bottom, #a39f68 1%,#e2e2e2 13%,#e2e2e2 13%,#96875e 28%,#ededed 44%,#96875e 59%,#96875e 59%,#a39f68 78%,#96875e 100%);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#a39f68', endColorstr='#96875e',GradientType=0 );
}
#jupiter-orbit {
position: absolute;
top: 50%;
left: 50%;
width: 400px;
height: 400px;
margin-top: -200px;
margin-left: -200px;
border-width: 2px;
border-style: dotted;
border-color: white;
border-radius: 50%;
-webkit-animation: spin-right 26s linear infinite;
-moz-animation: spin-right 26s linear infinite;
-ms-animation: spin-right 26s linear infinite;
-o-animation: spin-right 26s linear infinite;
animation: spin-right 26s linear infinite;
}
@-webkit-keyframes spin-right {
100% {
-webkit-transform: rotate(360deg);
-moz-transform: rotate(360deg);
-ms-transform: rotate(360deg);
-o-transform: rotate(360deg);
transform: rotate(360deg);
}
}
@keyframes spin-right {
100% {
-webkit-transform: rotate(360deg);
-moz-transform: rotate(360deg);
-ms-transform: rotate(360deg);
-o-transform: rotate(360deg);
transform: rotate(360deg);
}
}
<body>
<script type="text/javascript" src="planethover.js"></script>
<p class="einfo">
(Not to scale)<br>
By marloso2
</p>
<div id="sun"></div>
<div id="jupiter-orbit">
<div id="jupiter" class="planet"></div>
</div>
</body>