I've made this pretty simple web page that has a centered image. When you click it, it starts to spin.
Now I'm trying to use JavaScript to make it so that when you click it again, it starts to spin faster and faster, I've looked at multiple similar stack overflow questions on this but I just don't seem to be able to get this to work:
var img = document.querySelector("#spin")
img.addEventListener('click', onClick, false);
var deg = 360;
function onClick() {
deg += 90;
var stylesheet = document.styleSheets[0];
var spinRule = stylesheet.cssRules[0];
var spinRule_To = spinRule.cssRules[1];
var spinRule_To_Style = spinRule_To.style;
spinRule_To_Style.setProperty("transform:rotate", deg);
}
@keyframes spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
#tbl {
height: 100%;
width: 100%;
margin: 0;
padding: 0;
border: 0;
}
#tbl td {
vertical-align: middle;
text-align: center;
}
img:target {
animation-name: spin;
animation-duration: 4000ms;
animation-iteration-count: infinite;
animation-timing-function: linear;
}
<table id="tbl">
<tr>
<td>
<div>
<a href="#spin">
<img id="spin" src="http://h08.us/Hob-Cos.png" title="THE MEMES ARE BACK BOIS">
</a>
</div>
</td>
</tr>
</table>