August 9, 201214 yr Hei Guys... So i was on this Website and saw when i came on that the logo was animated. i was just wondering if it's flash or a gif or whatever. Then i saw this: This is the animation in frames! isn't it ? when you look at the console (css) while you reload the page you see that the margin-left is changing fast... if someone could explain me that ? or tell me how that method is named so i can learn this i would be glad. p.s: if you uncheck the overflow you can see how it works really cool Thanks. Edited August 9, 201214 yr by Greeb
August 9, 201214 yr You do not see it about in the wild much, it's jQuery animation. Here are some demos.
August 9, 201214 yr Heya, As first it looked like CSS3 animation, but its actually done with javascript. The sprite sheet is positioned inside the logo div (which only shows a single frame at a time) and as the margin-left counts down, its essentially moving to the next frame of the animation. Then at the end it seems to load in a sepererate logo of just the first frame.
August 9, 201214 yr It's really hard to explain without pictures so you'll just have to try to follow this. There is an <img> inside a <div>. That <div> has overflow: hidden; and a small width so it's acts as a clipping mask. By epic coincidence, or a very small amount of planning, that width is the same as one of those frames. Every few milliseconds (probably every 40), the margin-left is reduced by the width of the <div> until the last frame is showing. The technique's really simple, code do do that is just something like this: var div = document.querySelector('div'), img = document.querySelector('img'), width = img.style.width, // this line is actually much harder than that, look it up. unit = 24, // pixels animation = setInterval(function () { img.style.marginLeft -= unit; if (Math.abs(parseInt(img.style.marginLeft)) === width - unit) { clearInterval(animation); } }, 40); Edited August 9, 201214 yr by Skateside
Create an account or sign in to comment