Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

How does this work ?

Featured Replies

Hei Guys... :D

 

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:

 

logo-sprites.png

 

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 by Greeb

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.

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 by Skateside

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.