Created
March 1, 2013 01:16
-
-
Save troyth/5061698 to your computer and use it in GitHub Desktop.
stubs for working with bubbles
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var bubbles = []; | |
bubbles[172] = { | |
positionx: 150, | |
positiony: 300, | |
color: "#ff00ff", | |
side: "left", | |
text: "Amato Opera...", | |
icon: "images/icons/icon1.png" | |
}; | |
var MAX_HEIGHT = 500;//max bubble height in pixels | |
function renderBubbles(index){ | |
if(bubbles[index] != undefined){ | |
var html = '<div class="bubble ' + bubbles[index].side + '" style="color:' + bubbles[index].color + '; position:absolute; top:' + bubbles[index].positiony + '; left:' + bubbles[index].positionx + '; width:0; height:0;"><div class="text" style="display:none;"">' + bubbles[index].text + '</div>'+ '<div class="icon"><img src="' + bubbles[index].icon + '</div>'+'</div>'; | |
$('body').append( html ); | |
} | |
} | |
function incrementBubbles(){ | |
$('.bubble').each(function(i){ | |
var current_width = $(this).css('width'); | |
var current_height = $(this).css('height'); | |
var current_left = $(this).css('left'); | |
if(current_height >= MAX_HEIGHT){ | |
$(this).children('.text').show(); | |
if($(this).hasClass('left')){ | |
var new_left = current_left - 10; | |
$(this).css('left', new_left); | |
if(new_left < (0 - current_width)){ | |
$(this).remove(); | |
} | |
}else{ | |
var new_left = current_left + 10; | |
//$(this).css('left', new_left); | |
$(this).animate({ | |
left: new_left | |
}, 100);//100ms | |
if(new_left > window.innerWidth){ | |
$(this).remove(); | |
} | |
} | |
}else{ | |
var new_width = current_width + 10; | |
var new_height = current_height + 10; | |
$(this).css('width', new_width); | |
$(this).css('height', new_height); | |
} | |
}); | |
} | |
function scrollSwap(event){ | |
//YOUR OTHER CODE HERE FOR SCROLL SWAP | |
//var index; | |
renderBubbles(index); | |
incrementBubbles(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment