Skip to content

Instantly share code, notes, and snippets.

@jonbro
Created July 8, 2010 20:28
Show Gist options
  • Save jonbro/468569 to your computer and use it in GitHub Desktop.
Save jonbro/468569 to your computer and use it in GitHub Desktop.
var scroller = {
frame: 0,
frame2: 0.1,
amplitude1: 10,
offset: 0.2,
sinescroll: function(target){
scrolltext = $(target).text();
$(target).text("");
// write DIVs to hold characters
for (var i = 0; i < scrolltext.length; i++)
{
var appendText = scrolltext[i];
if(scrolltext[i] == " "){
appendText = "&nbsp;";
}
$(target).append('<div class="scroller_sub" id="scroller_sub_'+i+'">'+appendText+'</div>');
//position everything correctly
var last_left = 0;
$('.scroller_sub').each(function(){
$(this).css('left', last_left);
last_left += $(this).width();
}).css({position:'absolute', top:'0px'});
}
},
step: function(){
var angle = this.frame;
var offset = this.offset;
var amplitude1 = this.amplitude1;
$('.scroller_sub').each(function(){
var top = amplitude1 * Math.sin(angle);
$(this).css('top', top);
angle += offset;
});
this.frame += this.frame2;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment