Skip to content

Instantly share code, notes, and snippets.

@troyth
Created March 1, 2013 01:16
Show Gist options
  • Save troyth/5061698 to your computer and use it in GitHub Desktop.
Save troyth/5061698 to your computer and use it in GitHub Desktop.
stubs for working with bubbles
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