Reputation: 1848
This may seem like a slightly general question, but I thought of no better place to ask it.
How can I achieve an effect like the text seemingly exploding at http://philmartinezdesign.com/ ?
I'm aware it's done using stellar and background images but I was wondering if anyone can see how the animation is done?
Upvotes: 1
Views: 1464
Reputation: 324750
I'm assuming you're referring to the big "PM" at the top? That's just two images:
(source: philmartinezdesign.com)
(source: philmartinezdesign.com)
All it does is replace one image with the other when the scroll reaches a certain point. There's nothing special about it.
(By the way, that site is filled with HORRIBLE design choices. Do NOT use it as inspiration for your own work, no matter how "cool" you think it is)
Upvotes: 1
Reputation: 75327
//explosion! I'll probably be making a plugin for sequencing like this soon...
var siteUrl = $('#siteUrl').html();
var $path = siteUrl + 'assets/img/explosion';
var explosion = [];
var $frameNum;
var $spacing = 40;
var $frames = 25;
//add all the frames into an array
for( var s = 0; s < $frames; s++ ) {
explosion[s] = $path + '/' + s +'.jpg';
}
explosion.shift();
//cache
$('body').append('<div id="cache"></div>');
$('#cache').hide();
$(explosion).each(function() {
$('<img />').attr('src', this).appendTo('#cache');
});
//on scroll swap the images
$(window).scroll(function(){
var $scrollTop = $(window).scrollTop() -40;
$frameNum = Math.ceil( $scrollTop / $spacing );
if( $frameNum <= $frames ) {
$('#explosion img').attr('src' , explosion[$frameNum] );
}
});
He has 25 images, each of which is a frame of the explosion. When you scroll (or when he forces a scroll by you clicking a link), he rotates through the images in quick succession to create the effect.
Upvotes: 3