Plusieurs Slidershow sur une même page
Bonsoir;
En commençant, je dois reconnaître que je suis un big novice en Js/jQuery...
Donc, voilà, j'ai pris un code d'un Slidershow que j'ai trouvé sur la toile, voilà le lien du tuto:
http://sixrevisions.com/tutorials/ja...comment-145069
J'ai essayé par la suite de le modifier afin qu'il soit possible de mettre plusieurs Sliders sur une même page. Mais mes essaies ont échoués !
1 - En essayant de changer les ids des div et adapter la fonction js pour ça...J'ai dû utiliser une variable "prefix" qui va différer entre nos Sliders dans la page HTML...
Ex:
Pour le slider 1, je prends le préfixe "s1_" ==> <div id="s1_slideshow">; <div id="s1_slidesContainer">...etc.
Pour le slider 2, "s2_" ==>div id="s2_slideshow">; <div id="s2_slidesContainer">...etc.
.
.
.
.
etc.
2- Puis en appelant une fonction slider(prefix) pour chaque préfixe.
3- ça ne marche, j'ai l’impression comme si le script s’exécute qu'une seule fois et sur le même slider en mélangeant le contenu des deux slider ( comme j'ai mis que deux sliders dans ma page)
Je mets le code initial:
1/Pour le Js
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
| $(document).ready(function(){
var currentPosition = 0;
var slideWidth = 560;
var slides = $('.slide');
var numberOfSlides = slides.length;
// Remove scrollbar in JS
$('#slidesContainer').css('overflow', 'hidden');
// Wrap all .slides with #slideInner div
slides
.wrapAll('<div id="slideInner"></div>')
// Float left to display horizontally, readjust .slides width
.css({
'float' : 'left',
'width' : slideWidth
});
// Set #slideInner width equal to total width of all slides
$('#slideInner').css('width', slideWidth * numberOfSlides);
// Insert controls in the DOM
$('#slideshow')
.prepend('<span class="control" id="leftControl">Clicking moves left</span>')
.append('<span class="control" id="rightControl">Clicking moves right</span>');
// Hide left arrow control on first load
manageControls(currentPosition);
// Create event listeners for .controls clicks
$('.control')
.bind('click', function(){
// Determine new position
currentPosition = ($(this).attr('id')=='rightControl') ? currentPosition+1 : currentPosition-1;
// Hide / show controls
manageControls(currentPosition);
// Move slideInner using margin-left
$('#slideInner').animate({
'marginLeft' : slideWidth*(-currentPosition)
});
});
// manageControls: Hides and Shows controls depending on currentPosition
function manageControls(position){
// Hide left arrow if position is first slide
if(position==0){ $('#leftControl').hide() } else{ $('#leftControl').show() }
// Hide right arrow if position is last slide
if(position==numberOfSlides-1){ $('#rightControl').hide() } else{ $('#rightControl').show() }
}
}); |
2/ Pour l'HTML (juste l'utile)
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| <div id="slideshow">
<div id="slidesContainer">
<div class="slide">
<h2>Web Development Tutorial</h2>
<p><a href="http://sixrevisions.com/tutorials/web-development-tutorials/using-xampp-for-local-wordpress-theme-development/"><img src="img/img_slide_01.jpg" alt="An image that says Install X A M P P for wordpress." width="215" height="145" /></a>If you're into developing web apps, you should check out the tutorial called "<a href="http://sixrevisions.com/tutorials/web-development-tutorials/using-xampp-for-local-wordpress-theme-development/">Using XAMPP for Local WordPress Theme Development</a>" which shows you how to set up a local testing server for developing PHP/Perl based applications locally on your computer. The example also shows you how to set up WordPress locally!</p>
</div>
<div class="slide">
<h2>Grunge Brushes, Anyone?</h2>
<p><a href="http://sixrevisions.com/freebies/brushes/sr-grunge-free-high-resolution-photoshop-grunge-brushes/"><img src="img/img_slide_02.jpg" width="215" height="145" alt="A thumbnail image that says S R grunge photoshop brushes 6 high resolution grunge brushes by six revisions." /></a>In this layout, I used <a href="http://sixrevisions.com/freebies/brushes/sr-grunge-free-high-resolution-photoshop-grunge-brushes/">SR Grunge</a>, which is a free set of high-resolution Photoshop brushes you can download here on Six Revisions.</p>
<p>
</div>
<div class="slide">
<h2>How About Some Awesome Grunge Textures?</h2>
<p><a href="http://sixrevisions.com/freebies/textures/grunge-extreme-15-high-resolution-grunge-textures/"><img src="img/img_slide_03.jpg" width="215" height="145" alt="A thumbnail image that says grunge extreme 15 free high resolution grunge textures six revisions." /></a>The texture used in this web page is from the Grunge Extreme Textures freebie set by JC Parmley released here on Six Revisions.</p>
<p>You can head over to the <a href="http://sixrevisions.com/freebies/textures/grunge-extreme-15-high-resolution-grunge-textures/">Grunge Extreme</a> page to download the texture set or check out Six Revisions' <a href="http://sixrevisions.com/category/freebies/">freebie section</a> for even more goodies!</p>
</div>
<div class="slide">
<h2>'Tis the End, My Friend.</h2>
<p><a href="http://sixrevisions.com/tutorials/photoshop-tutorials/how-to-create-a-slick-and-clean-button-in-photoshop/"><img src="img/img_slide_04.jpg" width="215" height="145" alt="Thumbnail image that says sleek button using photoshop that links to a Photoshop tutoril." /></a>This is the last slide. Hit the left arrow control to go back to the other slides.</p>
<p>Alternatively, you may want to check out the tutorial on how to create a simple and cool button in Photoshop called "<a href="http://sixrevisions.com/tutorials/photoshop-tutorials/how-to-create-a-slick-and-clean-button-in-photoshop/">How to Create a Slick and Clean Button in Photoshop</a>" which was inspired by the <a href="http://www.campaignmonitor.com/designer/?utm_source=sixrevisions&utm_medium=banner&utm_term=2&utm_content=0003&utm_campaign=Apr09Banners">Campaign Monitor</a> web interface.</p>
</div>
</div>
</div> |
Ps : Juste votre avis: ça fait beau (utile?) de mettre plus d'un slider sur une même page?
Merci pour vos réponses :)