2
Contributors
7
Replies
8
Views
6 Years
Discussion Span
Last Post by benjaminFowl87
0

I've tried setting the auto to true all over my code

I've now set the defaults associative array everywhere.
This is what i've got

(function($) {

	$.fn.slider = function(options){
		// default configuration properties
		var defaults = {			
			prevId: 		'prevBtn',
			prevText: 		'Previous',
			nextId: 		'nextBtn',	
			nextText: 		'Next',
			controlsShow:	true,
			controlsBefore:	'',
			controlsAfter:	'',	
			controlsFade:	true,
			firstId: 		'firstBtn',
			firstText: 		'First',
			firstShow:		false,
			lastId: 		'lastBtn',	
			lastText: 		'Last',
			lastShow:		false,				
			vertical:		false,
			speed: 			600,
			auto:			true,
			pause:			900,
			continuous:		true
		}; 
		var options = $.extend(defaults, options);  
				
		this.each(function() {  
			var obj = $(this); 				
			var s = $("li", obj).length;
			var w = $("li", obj).width(); 
			var h = $("li", obj).height(); 
			obj.width(w); 
			obj.height(h); 
			obj.css("overflow","hidden");
			var ts = s-1;
			var t = 0;
			$("ul", obj).css('width',s*w);			
			if(!options.vertical) $("li", obj).css('float','left');
			
			if(options.controlsShow){
				var html = options.controlsBefore;
				if(options.firstShow) html += '<span id="'+ options.firstId +'"><a href=\"javascript:void(0);\">'+ options.firstText +'</a></span>';
				html += ' <span id="'+ options.prevId +'"><a href=\"javascript:void(0);\">'+ options.prevText +'</a></span>';
				html += ' <span id="'+ options.nextId +'"><a href=\"javascript:void(0);\">'+ options.nextText +'</a></span>';
				if(options.lastShow) html += ' <span id="'+ options.lastId +'"><a href=\"javascript:void(0);\">'+ options.lastText +'</a></span>';
				html += options.controlsAfter;						
				$(obj).after(html);										
			};
	
			$("a","#"+options.nextId).click(function(){		
				animate("next",true);
				var defaults = {			
					prevId: 		'prevBtn',
					prevText: 		'Previous',
					nextId: 		'nextBtn',	
					nextText: 		'Next',
					controlsShow:	true,
					controlsBefore:	'',
					controlsAfter:	'',	
					controlsFade:	true,
					firstId: 		'firstBtn',
					firstText: 		'First',
					firstShow:		false,
					lastId: 		'lastBtn',	
					lastText: 		'Last',
					lastShow:		false,				
					vertical:		false,
					speed: 			600,
					auto:			true,
					pause:			900,
					continuous:		true
				};
			});
			$("a","#"+options.prevId).click(function(){		
				animate("prev",true);
				var defaults = {			
					prevId: 		'prevBtn',
					prevText: 		'Previous',
					nextId: 		'nextBtn',	
					nextText: 		'Next',
					controlsShow:	true,
					controlsBefore:	'',
					controlsAfter:	'',	
					controlsFade:	true,
					firstId: 		'firstBtn',
					firstText: 		'First',
					firstShow:		false,
					lastId: 		'lastBtn',	
					lastText: 		'Last',
					lastShow:		false,				
					vertical:		false,
					speed: 			600,
					auto:			true,
					pause:			900,
					continuous:		true
				};				
			});	
			$("a","#"+options.firstId).click(function(){		
				animate("first",true);
				var defaults = {			
					prevId: 		'prevBtn',
					prevText: 		'Previous',
					nextId: 		'nextBtn',	
					nextText: 		'Next',
					controlsShow:	true,
					controlsBefore:	'',
					controlsAfter:	'',	
					controlsFade:	true,
					firstId: 		'firstBtn',
					firstText: 		'First',
					firstShow:		false,
					lastId: 		'lastBtn',	
					lastText: 		'Last',
					lastShow:		false,				
					vertical:		false,
					speed: 			600,
					auto:			true,
					pause:			900,
					continuous:		true
				};
			});				
			$("a","#"+options.lastId).click(function(){		
				animate("last",true);
				var defaults = {			
					prevId: 		'prevBtn',
					prevText: 		'Previous',
					nextId: 		'nextBtn',	
					nextText: 		'Next',
					controlsShow:	true,
					controlsBefore:	'',
					controlsAfter:	'',	
					controlsFade:	true,
					firstId: 		'firstBtn',
					firstText: 		'First',
					firstShow:		false,
					lastId: 		'lastBtn',	
					lastText: 		'Last',
					lastShow:		false,				
					vertical:		false,
					speed: 			600,
					auto:			true,
					pause:			900,
					continuous:		true
				};				
			});		
			
			function animate(dir,clicked){
				var defaults = {			
					prevId: 		'prevBtn',
					prevText: 		'Previous',
					nextId: 		'nextBtn',	
					nextText: 		'Next',
					controlsShow:	true,
					controlsBefore:	'',
					controlsAfter:	'',	
					controlsFade:	true,
					firstId: 		'firstBtn',
					firstText: 		'First',
					firstShow:		false,
					lastId: 		'lastBtn',	
					lastText: 		'Last',
					lastShow:		false,				
					vertical:		false,
					speed: 			600,
					auto:			true,
					pause:			900,
					continuous:		true
				};
				var ot = t;				
				switch(dir){
					case "next":
						t = (ot>=ts) ? (options.continuous ? 0 : ts) : t+1;						
						break; 
					case "prev":
						t = (t<=0) ? (options.continuous ? ts : 0) : t-1;
						break; 
					case "first":
						t = 0;
						break; 
					case "last":
						t = ts;
						break; 
					default:
						break; 
				};	
				
				var diff = Math.abs(ot-t);
				var speed = diff*options.speed;						
				if(!options.vertical) {
					p = (t*w*-1);
					$("ul",obj).animate(
						{ marginLeft: p }, 
						speed
					);				
				} else {
					p = (t*h*-1);
					$("ul",obj).animate(
						{ marginTop: p }, 
						speed
					);
					var defaults = {			
						prevId: 		'prevBtn',
						prevText: 		'Previous',
						nextId: 		'nextBtn',	
						nextText: 		'Next',
						controlsShow:	true,
						controlsBefore:	'',
						controlsAfter:	'',	
						controlsFade:	true,
						firstId: 		'firstBtn',
						firstText: 		'First',
						firstShow:		false,
						lastId: 		'lastBtn',	
						lastText: 		'Last',
						lastShow:		false,				
						vertical:		false,
						speed: 			600,
						auto:			true,
						pause:			900,
						continuous:		true
					};				
				};
				
				if(!options.continuous && options.controlsFade){					
					if(t==ts){
						$("a","#"+options.nextId).hide();
						$("a","#"+options.lastId).hide();
					} else {
						$("a","#"+options.nextId).show();
						$("a","#"+options.lastId).show();					
					};
					if(t==0){
						$("a","#"+options.prevId).hide();
						$("a","#"+options.firstId).hide();
					} else {
						$("a","#"+options.prevId).show();
						$("a","#"+options.firstId).show();
					};
					var defaults = {			
						prevId: 		'prevBtn',
						prevText: 		'Previous',
						nextId: 		'nextBtn',	
						nextText: 		'Next',
						controlsShow:	true,
						controlsBefore:	'',
						controlsAfter:	'',	
						controlsFade:	true,
						firstId: 		'firstBtn',
						firstText: 		'First',
						firstShow:		false,
						lastId: 		'lastBtn',	
						lastText: 		'Last',
						lastShow:		false,				
						vertical:		false,
						speed: 			600,
						auto:			true,
						pause:			900,
						continuous:		true
					};					
				};				
				
				if(clicked){
					clearTimeout(timeout);
					var defaults = {			
						prevId: 		'prevBtn',
						prevText: 		'Previous',
						nextId: 		'nextBtn',	
						nextText: 		'Next',
						controlsShow:	true,
						controlsBefore:	'',
						controlsAfter:	'',	
						controlsFade:	true,
						firstId: 		'firstBtn',
						firstText: 		'First',
						firstShow:		false,
						lastId: 		'lastBtn',	
						lastText: 		'Last',
						lastShow:		false,				
						vertical:		false,
						speed: 			600,
						auto:			true,
						pause:			900,
						continuous:		true
					};
				};
				if(options.auto && dir=="next" && !clicked){;
					timeout = setTimeout(function(){
						animate("next",false);
					},diff*options.speed+options.pause);
					var defaults = {			
						prevId: 		'prevBtn',
						prevText: 		'Previous',
						nextId: 		'nextBtn',	
						nextText: 		'Next',
						controlsShow:	true,
						controlsBefore:	'',
						controlsAfter:	'',	
						controlsFade:	true,
						firstId: 		'firstBtn',
						firstText: 		'First',
						firstShow:		false,
						lastId: 		'lastBtn',	
						lastText: 		'Last',
						lastShow:		false,				
						vertical:		false,
						speed: 			600,
						auto:			true,
						pause:			900,
						continuous:		true
					};
				};
				
			};
			// init
			var timeout;
			if(options.auto){;
				timeout = setTimeout(function(){
					animate("next",false);
				},options.pause);
			};		
		
			if(!options.continuous && options.controlsFade){					
				$("a","#"+options.prevId).hide();
				$("a","#"+options.firstId).hide();				
			};				
			
		});
	  
	};

})(jQuery);

$(document).ready(function(){	
	$("#sliding-quotes").slider({
		auto: true,
		vertical: true,
		continuous: true 
	});
});
0

That won't have any effect. What you could do is remove the if on line 317 so the timeout is always set, regardless of the auto setting.

0

ok, have managed to do it

I did it by removing the if(clicked)

on line 263

Thanks for your help pritaeas

Next question is, what sort of thing would i be needing to look at to say that if a user is hovering over the text or image that the slider will not slide?

1

Have done it so thought I would post it here for anyone else who wants to achieve this.

(function($) {

	$.fn.slider = function(options){
		// configuration
		var settings = {			
			prevId: 		'prevBtn',
			prevText: 		'Previous',
			nextId: 		'nextBtn',	
			nextText: 		'Next',
			controlsShow:	true,
			controlsBefore:	'',
			controlsAfter:	'',	
			controlsFade:	true,				
			vertical:		false,
			speed: 			1,
			auto:			true,
			pause:			2500,
			continuous:		true,
			continueScroll: false
		}; 

		var options = $.extend(settings, options);  
			
		this.each(function() {  
			var obj = $(this);			
			var s = $("li", obj).length;
			var w = $("li", obj).width(); 
			var h = $("li", obj).height(); 
			obj.width(w); 
			obj.height(h); 
			obj.css("overflow","hidden");
			var ts = s-1;
			var t = 0;
			$("ul", obj).css('width',s*w);			
			if(!options.vertical) $("li", obj).css('float','left');
			
			if(options.controlsShow){
				var html = '';
				html += ' <span id="'+ options.prevId +'"><a href=\"javascript:void(0);\">'+ options.prevText +'</a></span>';
				html += ' <span id="'+ options.nextId +'"><a href=\"javascript:void(0);\">'+ options.nextText +'</a></span>';
				html += '';					
				$(obj).after(html);										
			};
			
			$("a","#"+options.nextId).click(function(){		
				animate("next",true);
			});
			$("a","#"+options.prevId).click(function(){		
				animate("prev",true);			
			});		
			
			function animate(dir,clicked){
				var ot = t;				
				switch(dir){
					case "next":
						t = (ot>=ts) ? (options.continuous ? 0 : ts) : t+1;						
						break; 
					case "prev":
						t = (t<=0) ? (options.continuous ? ts : 0) : t-1;
						break; 
					default:
						break; 
				};	
				
				var diff = Math.abs(ot-t);
				var speed = diff*options.speed;						
				if(!options.vertical) {
					p = (t*w*-1);
					$("ul",obj).animate(
						{ marginLeft: p }, 
						speed
					);				
				} else {
					p = (t*h*-1);
					$("ul",obj).animate(
						{ marginTop: p }, 
						speed
					);			
				};
				
				if(!options.continuous && options.controlsFade){					
					if(t==ts){
						$("a","#"+options.nextId).hide();
					} else {
						$("a","#"+options.nextId).show();					
					};
					if(t==0){
						$("a","#"+options.prevId).hide();
					} else {
						$("a","#"+options.prevId).show();
					};				
				};				
				
				if(clicked){
					if(options.continueScroll){
						clearTimeout(timeout);
					};
				};
				
				if(options.auto && dir=="next" && !clicked){;
					timeout = setTimeout(function(){
						animate("next",false);
					},diff*options.speed+options.pause);
				};
				
				
			};
			
			obj.mouseenter(function(){clearTimeout(timeout);});
			
			obj.mouseleave(function(){animate("next",false);});
			
			// initialise timeout
			var timeout;
			if(options.auto){;
				timeout = setTimeout(function(){
					animate("next",false);
				},options.pause);
			};				
		});
	};

})(jQuery);

$(document).ready(function(){	
	$("#sliding-quotes").slider({
		auto: true,
		vertical: true,
		continuous: true 
	});
});
Votes + Comments
Thanks for sharing
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.