Tuesday, October 28, 2014

onload Priority for Chrome, Safari, Firefox and Internet Explorer

I always wonder how the location of the placement of onload event listener will affect the behavior of my Javascript on various browsers. I use the following codes to check out this small doubt of me: <html> <head> <script> window.onload = function() {  alert("window.onload in the head"); } </script> </head> <body onload="alert('body begins onload')"> <br><br><br><br><br><br> <script>  alert("body...
Read More »

Monday, October 13, 2014

Javascript to Simulate Shaking an Object

I know this is trivial but also fun at the same time. Just in case you need something fun for your school projects. You need to modify it to suit your need as the codes in the following is very minimal: <html> <script> var x = 10; var y = 10; var myTimer; function startshake() {  setTimeout(function() {moveElemX("shakeObject",x-(Math.floor(Math.random()*6)));},10);  setTimeout(function() {moveElemX("shakeObject",x+(Math.floor(Math.random()*7)));},25);  setTimeout(function()...
Read More »

Monday, October 6, 2014

Fixed DIV for Browsers (Including IE and Tablets) using CSS

Without using Javascript, CSS is enough to do the job: <!DOCTYPE HTML> <html> <style type="text/css"> #fixit { position: absolute; left: 10px; top: 10px; } div > div#fixit { position: fixed; } </style> <body> <div> <div id="fixit" style="border:2px solid #333;background-color:#ddd;text-align:center;padding:10px;"> Hello </div> </div> <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br> </body> </html> Try...
Read More »