views:

3841

answers:

2

Hi all! 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"&gt;
<html xmlns="http://www.w3.org/1999/xhtml"&gt;
<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>
A: 

Are you supposed to start the cycling when the document becomes ready? I'm unfamiliar with the cycler, but try this instead:

<script type="text/javascript">
    $(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>

Perhaps you were trying to run a cycler on an element that didn't exist yet because the document wasn't ready. Also, I think the syntax for creating elements requires them to be self-closing, i.e., you should have .before('<ul id="nav" />').cycle()..., but I'm not very familiar with the ins and outs of jQuery yet.

Cory Larson
I included it in my code, still doesn't work.
Shimmy
+1  A: 

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>
Gordian Yuan
Nope :(still doesn't work
Shimmy
I copy your code and add <ul>, It's works well.You can download the sample code and checked. http://gordianyuan.cn/ex.7z
Gordian Yuan
You should open a new question for this. :) I have update my answer.
Gordian Yuan
it's not the adding of the ul, it's the style, once I remove the style (it's from their site) I can see the pager, still I am willing to have a pretier thing.
Shimmy
I add the style that is OK too. Do i miss something? You can download the sample code and checked. http://gordianyuan.cn/ex2.7z
Gordian Yuan