All pastes #755901 Raw Edit

Mine

public text v1 · immutable
#755901 ·published 2007-10-30 23:58 UTC
rendered paste body
YDN.HeadlineScroller = Class.create();
YDN.HeadlineScroller.prototype = {
	
	initialize: function(id, speed, delay) {
		//Set the variables that are passed in to be instance variables
		this.id = id;
		this.speed = speed;
		this.delay = delay;
		
		this.scroller = $(this.id);
		
		//Set styles
		Element.setStyle(this.scroller, {position: 'relative', overflow: 'hidden'});
		
		//Create inner scrolling div
		this.scroller.innerHTML = "<div id=\"" + id + "_inner\">" + this.scroller.innerHTML + "</div>";
		
		//Set style of inner
		this.inner = $(id + "_inner");
		this.scrollerDimensions = this.scroller.getDimensions();
		Element.setStyle(this.inner, {position: 'absolute', left: "0px", top: this.scrollerDimensions.height + "px", width: this.scrollerDimensions.width});
		
		//Calculate the height limit
		this.limit = this.inner.getElementsBySelector('div').length * parseInt(this.scrollerDimensions.height);
		
		//Show the scroller
		Element.setStyle(this.scroller, {display: 'block'});
		
		//Execute the helper function
		this.bind(setTimeout("this.doScroll();", parseInt(this.speed)));
	},
	doScroll : function() {
		
		nextTick = this.speed;
		
		//Move the div
		if (parseInt(this.inner.getStyle('top')) < -this.limit) {
			Element.setStyle(this.inner, {top: parseInt(this.scrollerDimensions.height) + "px"});
		}
		else {
			Element.setStyle(this.inner, {top: (parseInt(this.inner.getStyle('top'))-1) + "px"});
		}
		
		//Get inner's top and scroller's height
		innerTop = this.inner.getStyle('top');
		scrollerHeight = this.scroller.getHeight();
		
		if (!(parseInt(innerTop) == parseInt(scrollerHeight)) &&
			!(parseInt(innerTop) == -parseInt(this.limit)) &&
			(parseInt(innerTop) % parseInt(scrollerHeight)) == 0)
		{
			nextTick = this.delay;
		}
		this.bind(setTimeout("this.doScroll();", parseInt(nextTick)));
	}
};
var scroller = new YDN.HeadlineScroller("headlinescroller", 20, 4000);