var newImageZIndex = 1; // To make sure newly-loaded images land on top of images on the table
var loaded = false; // Used to prevent initPhotos() running twice
// When the document is ready, fire up the table!
$( init );
// When the wooden table image has loaded, start bringing in the photos
function init() {
var woodenTable = $('#wooden-table img');
woodenTable.load( initPhotos );
// Hack for browsers that don't fire load events for cached images
if ( woodenTable.get(0).complete ) $(woodenTable).trigger("load");
}
// Set up each of the photos on the table
function initPhotos() {
// (Ensure this function doesn't run twice)
if ( loaded ) return;
loaded = true;
// The table image has loaded, so bring in the table
$('#lighttable').fadeIn('fast');
// Process each photo in turn...
$('#lighttable img').each( function(index) {
// Set a random position and angle for this photo
var left = Math.floor( Math.random() * 1000 + 50 );
var top = Math.floor( Math.random() * 250 + 50 );
var angle = Math.floor( Math.random() * 40 - 20 );
$(this).css( 'left', left+'px' );
$(this).css( 'top', top+'px' );
$(this).css( 'transform', 'rotate(' + angle + 'deg)' );
$(this).css( '-moz-transform', 'rotate(' + angle + 'deg)' );
$(this).css( '-webkit-transform', 'rotate(' + angle + 'deg)' );
$(this).css( '-o-transform', 'rotate(' + angle + 'deg)' );
// Make the photo draggable
$(this).draggable( { containment: 'parent', stack: '#lighttable img', cursor: 'pointer' } );
// Hide the photo for now, in case it hasn't finished loading
$(this).hide();
// When the photo image has loaded...
$(this).load( function() {
// (Ensure this function doesn't run twice)
if ( $(this).data('loaded') ) return;
$(this).data('loaded', true);
// Record the photo's true dimensions
var imgWidth = $(this).width();
var imgHeight = $(this).height();
// Make the photo bigger, so it looks like it's high above the table
$(this).css( 'width', imgWidth * 1.5 );
$(this).css( 'height', imgHeight * 1.5 );
// Make it completely transparent, ready for fading in
$(this).css( 'opacity', 0 );
// Make sure its z-index is higher than the photos already on the table
$(this).css( 'z-index', newImageZIndex++ );
// Gradually reduce the photo's dimensions to normal, fading it in as we go
$(this).animate( { width: imgWidth, height: imgHeight, opacity: .95 }, 1200 );
} );
// Hack for browsers that don't fire load events for cached images
if ( this.complete ) $(this).trigger("load");
How do I randomize the order of the images? Is it done in the lighttable div? in a function further up?
Please keep in mind I will not know where to place any code/answer in index.html, I know nothing about javascript or html apart from adjusting values to alter the outcome.
I use web expression 4 free version.
Bookmarks