Search code examples
javascriptjqueryjquery-pluginscycleimage-rotation

Problem using jQuery cycle plugin as image rotator and a pager


I am trying to use jQuery in order to make a pager for tumbs and large images and I don't succeed.

I am using this example from jQuery's site, I think I followed the direction but it doesn't seem to be worknig.

I do see only the first image and not all of them, but no pager. Am I missing something?

So here is my HTML:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>

    <script src="jquery-1.3.2.js" type="text/javascript"></script>

    <script src="jquery.cycle.all.js" type="text/javascript"></script>

    <script type="text/javascript">
        $(document).ready(function() {
            $('#slideshow').before('<ul id="nav">').cycle({
                fx: 'turnDown',
                speed: 'fast',
                timeout: 0,
                pager: '#nav',

                // callback fn that creates a thumbnail to use as pager anchor 
                pagerAnchorBuilder: function(idx, slide)
                {
                    return '<li><a href="#"><img src="' + slide.src + '" width="50" height="50" /></a></li>';
                }
            });
        });
    </script>

    <style type="text/css">
#slideshow { left: 20px }
#nav { width: 300px; margin: 15px }
#nav li { width: 50px; float: left; margin: 8px; list-style: none }
#nav a { width: 50px; padding: 3px; display: block; border: 1px solid #ccc; }
#nav a.activeSlide { background: #88f }
#nav a:focus { outline: none; }
#nav img { border: none; display: block }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div id="slideshow" >
        <img src="http://www.freefoto.com/images/12/13/12_13_4---Flowers-in-a-Garden-Border_web.jpg" />
        <img src="http://www.cssnz.org/flower.jpg" />
        <img src="http://www.global-b2b-network.com/direct/dbimage/50322257/Sun_Flowers.jpg" />
    </div>
    </form>
</body>
</html>

Solution

  • You need to add a container

    Ex

    <body>
       <form id="form1" runat="server">
          <ul id="nav"></ul>  <!-- You need this -->
          <div id="slideshow">
             <img src="http://www.freefoto.com/images/12/13/12_13_4---Flowers-in-a-Garden-Border_web.jpg" />
             <img src="http://www.cssnz.org/flower.jpg" />
             <img src="http://www.global-b2b-network.com/direct/dbimage/50322257/Sun_Flowers.jpg" />
          </div>
       </form>
    </body>
    

    Update:

    For horizontal on the bottom of the page underneath the slideshow

    You need add this CSS

    #nav li{
      float: left;
    }
    

    And HTML change to

       <form id="form1" runat="server">
          <div id="slideshow">
             <img src="http://www.freefoto.com/images/12/13/12_13_4---Flowers-in-a-Garden-Border_web.jpg" />
             <img src="http://www.cssnz.org/flower.jpg" />
             <img src="http://www.global-b2b-network.com/direct/dbimage/50322257/Sun_Flowers.jpg" />
          </div>
          <ul id="nav"></ul>  <!-- You need this -->
       </form>