I am trying to animate the following in css. I've read previous posts, but the settimeout
doesn't seem to be working, or it doesn't seem to be giving me the intended result.
I am trying to do a simple animation whereby it changes the line height by 0.5 each time, I've tried in a loop, and I've tried manually, but neither works. It just shows me the "final" result, and then if I push the button, doesn't even change anything. Here is an example:
$(document).ready(function() {
$("#linespace001").click(function() {
var crap = 0;
// this for some stupid reason DOESNT work
for (i = 1; i <= 3; i++) {
crap += 1000;
setTimeout(function() {
$("#poop").css("line-height", i * 0.5);
}, crap);
// this for some stupid reason works
setTimeout(function() {
$("#poop").css("line-height", 0.5);
}, 1000);
setTimeout(function() {
$("#poop").css("line-height", 1);
}, 2000);
setTimeout(function() {
$("#poop").css("line-height", 1.5);
}, 3000);
}
});
});
<input type=button id=linespace001 value="Animate button!">
<div id="poop">
This is a sample test/changing the line height/spacing
<br>This is a sample test/changing the line height/spacing
<br>This is a sample test/changing the line height/spacing
<br>This is a sample test/changing the line height/spacing
<br>This is a sample test/changing the line height/spacing
<br>This is a sample test/changing the line height/spacing
<br>
</div>