jquery.newsticker.js

2009 blev det här scriptet till.

/*
	Made By Peter Lindblom 2009
	https://www.plweb.se
	ver 1.000
*/

(function ($) {
	
	$.fn.startNewsTicker = function (settings) {

		var config = {
			startPosition: -20, 
			stopPosition: 100,
			pausPosition: 50,
			units: "px",
			waitToStartForMS:0,
			waitOnPausPositionForMS:1000,
			animationDelayMS:25
		};
		
		return this.each(function () {
			
			this.newsTicker = function (currentHtmlObj) {
				var childElements = [],
				currentElement = 0,
				lastChildElement = 0,
				startTimer = null,
				timer = null, 
				localConfig = $.extend({}, config, settings),
				delay = localConfig.animationDelayMS,
				
				startNewsTicker = function () {
					childElements = $(currentHtmlObj).children();
					lastChildElement = (childElements.length -1);
					
					$.each($(currentHtmlObj).children(), function () {
						$(this).css("top",localConfig.startPosition + localConfig.units);
						$(this).css("position","absolute");
						$(this).hide();
					});
					
					startTimer = setTimeout(tick, localConfig.waitToStartForMS);
				},
				
				tick = function () {
											
					if( (currentElement <= lastChildElement) && ( parseInt(currentJQueryObj(currentElement).css("top"),10) !== localConfig.stopPosition ) ){
						delay = localConfig.animationDelayMS;
						currentJQueryObj(currentElement).show();
						if (localConfig.startPosition < localConfig.stopPosition) {
							currentJQueryObj(currentElement).css("top", ( parseInt(currentJQueryObj(currentElement).css("top"), 10) + 1 ) + localConfig.units  );
						}else if (localConfig.startPosition > localConfig.stopPosition) {
							currentJQueryObj(currentElement).css("top", ( parseInt(currentJQueryObj(currentElement).css("top"), 10) - 1 ) + localConfig.units  );
						}
						
						if( parseInt(currentJQueryObj(currentElement).css("top"), 10) === localConfig.stopPosition ){
							currentJQueryObj(currentElement).hide();
							currentJQueryObj(currentElement).css("top",localConfig.startPosition + localConfig.units);
							currentElement = currentElement + 1; 
							if (currentElement > lastChildElement ){
								currentElement = 0;
							}
						}
					}
					
					if( (currentElement <= lastChildElement) && ( parseInt(currentJQueryObj(currentElement).css("top"), 10) === localConfig.pausPosition ) ){						
						delay = localConfig.waitOnPausPositionForMS;						
					}
					
					timer = setTimeout(tick, delay);
					
				},
				currentJQueryObj = function (pos) {
					return $(childElements[currentElement]);
				};
				
				startNewsTicker();
			};
			
			this.newsTicker(this);
			
		});
	};
	
		
	
}(jQuery));


Publicerat av

Peter Lindblom

Mer info om mig finns på sidan https://plweb.se/om-peter-lindblom/