Simple JQuery Slideshow that Refreshes Order of Pictures
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: Simple JQuery Slideshow that Refreshes Order of Pictures

  1. #1
    Join Date
    Oct 2010
    Posts
    15

    Question Simple JQuery Slideshow that Refreshes Order of Pictures

    Right now on my current website, I have it going through the pictures in the order of the array, but I would like it so whenever the user refreshes the website, the slideshow randomly shuffles the pictures in a different order.

    Code:
    <script type="text/javascript">
    var imgs = [
    'images/slideshow/001.jpg',
    'images/slideshow/002.jpg',
    'images/slideshow/003.jpg',
    'images/slideshow/004.jpg',
    'images/slideshow/005.jpg',
    'images/slideshow/006.jpg'];
    var cnt = imgs.length;
    
    $(function() {
    setInterval(Slider, 3000);
    });
    
    function Slider() {
    $('#imageSlide').fadeOut("slow", function() {
    // the source of the problem
    $(this).attr('src', imgs[Math.floor (Math.random( ) * imgs.length) % cnt]).fadeIn("slow");
    });
    
    }
    </script>
    Any help is appreciated! =]

  2. #2
    PeejAvery's Avatar
    PeejAvery is offline Super Moderator Power Poster
    Join Date
    May 2002
    Posts
    10,879

    Re: Simple JQuery Slideshow that Refreshes Order of Pictures

    There are plenty examples out there on how to sort an array randomly. Search Google for "JavaScript array random sort."
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  3. #3
    Join Date
    Oct 2010
    Posts
    15

    Re: Simple JQuery Slideshow that Refreshes Order of Pictures

    Thank you for that tip!

    I wanted to know if I could interchange JavaScript techniques with JQuery because I wanted to try and use these tips:
    http://hungred.com/how-to/tutorial-s...ay-javascript/

  4. #4
    PeejAvery's Avatar
    PeejAvery is offline Super Moderator Power Poster
    Join Date
    May 2002
    Posts
    10,879

    Re: Simple JQuery Slideshow that Refreshes Order of Pictures

    It's 3 lines of code. Why waste the resources to interact with jQuery? Since jQuery doesn't have a random sorting method included, you'd have to extend the jQuery framework which would be more work.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  5. #5
    Join Date
    Jun 2013
    Posts
    1

    Re: Simple JQuery Slideshow that Refreshes Order of Pictures

    Just to add to this here is a really basic slider I enjoy using. I like it cause the code is really easy to understand and it includes thumnails, next and previous buttons and a rotating description section too

    http://codetutorial.caroshaw.com/jqu...age_slider.php

  6. #6
    PeejAvery's Avatar
    PeejAvery is offline Super Moderator Power Poster
    Join Date
    May 2002
    Posts
    10,879

    Re: Simple JQuery Slideshow that Refreshes Order of Pictures

    Welcome to the forums alicialou!

    Please remember to keep your posts relevant. This thread is 3 years old!
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center