Animating a scene with a tracking shot in html and javascript (jquery) Have you ever thought to make dolly for your site, but the idea you seem too complex, too resource intensive, or you feel compelled to go through flash? Think again! Making a dolly full screen is easy! And this lends itself to many uses as possible. Whether as background entertainment or as part of a push interactivity, it is now easy to make a dolly with Javascript.
I personally use jQuery library, which can animate the elements of the DOM with amazingly simple. So how is it used? This is the subject of this micro tutorial.
Ideally you should create a basic structure for his site with some divs. The div containers that are default are positioned one above the other. Here there is no issue to bother with the placement of div. There are only two! The first div is actually a global container, it is inside of it that will produce the animation of traveling. Its role is to create a zone of visibility (here equal to the total size of the window). Here
style css:
position: absolute; / * block has a fixed position * /
width: 100%; / * it occupy the full width of the window * /
height: 100%; / * and * full height /
overflow: hidden / * all that exceed the size of the window is hidden, and there will not lift * /
Inside we will find another div, the one that directly contain the background image. It is this div to be animated and give the impression of traveling.
css style:
position: relative / * needed for the animation works * /
Inside this div, we will insert our image with the img tag. The image that you place will have a substantial length (mine is 2560 long is double my screen width).
That nothing more for the items, if we have 2 summarizes blocks and an image. Being nested within each other which gives us something like this:
div div img
/ div
/ div
Here I suggest you also set the style for your body {
margin: 0;
padding: 0;}
This will prevent them have black borders on the sides of your browser.
Now place the animation!
The animation will be done through a small jQuery script. I suggest you take a look at this javascript library that is full of tricks nice.
First, it must be sure you download the. Jquery js, and you Rangiers though carefully not far from your html page to access it with the tag script type = "text / javascript" src = "js/jquery-1.4.4.js"
Following is the javascript code that will move your sets (typing inside script tag of course):
$ (document). ready (function () {
jQuery.fx.interval = 20;
$ ('# bkgd'). animate ({
left: '-= 100%'
}, 2000);
});
Ahhh what does this mean (for the uninitiated, p)
jQuery.fx.interval = 20 / * performance issue, I limit the number of frames per seconds 50 img / sec (1000/20 = 50) * /
$ ('# bkgd'). animate is the method to animate jQuery, here we asked our div containing the image and whose id property equal to "bkgd" to translate to the left, the equivalent width of the browser window: left: '-= 100%' in 2 seconds.
Here then of course, this explanation is that decrypt all this, and it may be that you do not succeed to make it functional with a tracking shot, otherwise you're good and good for you: p
I invite you to take a look
sources, and you realize for yourself the kind of record that can be obtained. Good luck