May 31
This explain how can do whe do with a simple animation in JavaScript without script.aculo.us, moo.fx etc. Thought I highly recommend both these libraries and I really like animations done through them and I myself use script.aculo.us! I thought that it would also be good to know how they do it.
So let us start. We a are first making a simple HTML page with an image and a link to shrink that image we are also including a simple CSS file, prototype so that our code can be shorter and logic.js.
HTML:
Our CSS file just includes padding and margin declarations for the body. Our JS file looks something like this:
JAVASCRIPT:
-
Event.observe( window, 'load', function(){
-
$(’link’).onclick = shrinkImage;
-
});
-
shrinkImage = function(){
-
domID = ‘rails’;
-
var dimensions = $(domID).getDimensions();
-
function shrink(){
-
if(dimensions.height<0 || dimensions.width<0){
-
$(domID).hide();
-
return;
-
}
-
$(domID).height = $(domID).height-5;
-
setTimeout(shrink, 50)
-
}
-
setTimeout(shrink, 50)
-
}}
Recent Comments