I'm trying to create a <p>
that first renders nearly invisible, then on 'mouseover' becomes visible and incrementally increases in size, to finally 1em. Then on 'mouseout' reverts to its original settings. For the delay, I'm using a sleep() function referenced from this(stackoverflow) answer(works great, thank you).
What's happening is that while the increment works fine, the <p>
doesn't appear until the end of the loop. Suddenly, rather than throughout, and I'm not sure why... The 'mouseout' event works fine. Tested in firefox, chrome and safari on OS X 10.9 same in all three.
/*jslint browser: true*/
/*global $, jQuery, alert*/
function sleep(milliseconds) {
var start = new Date().getTime(), i;
for (i = 0; i < 1e7; i++) {
if ((new Date().getTime() - start) > milliseconds) {
break;
}
}
}
var Test_MouseOver = function (event) {
var i, text_size;
$('#Test').css('background', 'rgba(0, 0, 100, 0.6)').css('color', 'rgba(100, 0, 0, 1)');
for (i = 0.2; i <= 1; i = i + 0.1) {
text_size = i.toString() + 'em';
console.info('i: ' + text_size);
$('#Test').css('font-size', text_size);
sleep(50);
}
console.info('-----');
};
var Test_MouseOut = function (event) {
$('#Test').css('background', 'rgba(0, 0, 0, 0.0)').css('color', 'rgba(100, 0, 0, 0.2)').css('font-size', '0.2em');
};
var Test = document.getElementById('Test');
Test.addEventListener('mouseover', Test_MouseOver);
Test.addEventListener('mouseout', Test_MouseOut);