jQuery tricks 1: automatic-wslider
This time I’ll post some actual code. A client wanted me to write an “image slider”. You’ve probably seen lot’s of them online – and a whole lot of them is in flash – why? There is no need to involve flash in such a trivial task, and jQuery is more than up to the job :-) I used jQuery with the wslide plugin, it’s simple and quite neat. But it does not slide on it’s own. But thanks to it’s simplicity I was able add the functionality I needed in just a few lines of clean code. I used the timer plugin to “click” on the slider at some interval and voila – the birth of an automatic jquery image slider. Anyways, here’s thecode:
-
var canDo = true;
-
/** plugin @author: http://www.webinventif.fr/wslide-plugin/ */
-
$(document).ready(function(){
-
-
$('#slidermenu, #slider, .cube').mouseover(function(){
-
canDo = false;
-
}).mouseout(function(){
-
canDo = true;
-
});
-
-
$('#slider').wslide({
-
width: 900,
-
height: 200,
-
pos: 1,
-
fade: true,
-
horiz: true,
-
autolink: 'slidermenu',
-
speed:300
-
});
-
-
$.timer(5000, function (timer) {
-
if(canDo){
-
if($('#slidermenu a:last').hasClass('wactive')){
-
$('#slidermenu a:first').click();
-
}else{
-
$('#slidermenu .wactive').next().click();
-
}
-
}
-
});
-
});

January 20th, 2010 at 21:43
Hej
Ten skrypt nie działa ?
January 20th, 2010 at 22:18
W takiej postaci (dodana została obsługa “zatrzymywania” na rollover) jest umieszczony na humac.pl i sprawuje się dobrze. Czy na pewno masz dobrze ponadawane id pól oraz masz plugin do jQuery “jQuery Timer plugin v0.1″?
Dodałem fragment do “zatrzymywania on rollover” teraz, reszta kodu jest bez zmian.
Pozdrawiam
January 21st, 2010 at 20:55
Ok już działa, nie wiem czemu wslide dodaje # przed id i powoduje ten problem.
btw fajny pomysl z tym automatycznym przesuwaniem, bardzo prosty a zarazem efektywny.