views:

121

answers:

3

I am trying to create a little filmstrip with images. I want to be able to scroll horizontally to view all of the images.

I have:

<div class="gallery"> 
    <div class="back" style="opacity: 0.6;"></div>  
    <div class="thumbs">      
        <ul class="ad-thumb-list"> 
            <li>
               <img id="thumb01" src="../jpeg/thumbnails/01.jpg" title="page 1"/>
            </li>
            (I have many <li>'s listed)
        </ul>    
    </div>  
    <div class="forward" style="opacity: 0.6;"></div> 
</div>

I have css stylizing the whole thing, and I have the display:hidden on the thumbs div. I just need the arrows to function but I have no idea what type of code to use. Any help would be great!

A: 

Go for a plugin if you're not too adept in javascript. How about this:

http://sorgalla.com/projects/jcarousel/

http://sorgalla.com/projects/jcarousel/examples/static_circular.html

Very easy to implement.

elduderino
I think he wants to do it himself
XGreen
Im a she :) lol But yes i do want to do it myself
Annie
A: 
$('.gallery').each(function() {
    var $images = $('.thumbs li', this);
    var $forward = $('.forward', this);
    var $back = $('.back', this);

    var numImages = $images.length;

    var index = 0;

    function update()
    {
        index = (index + numImages)%numImages;
        $images.hide().eq(index).show()
    }

    $back.click(function() {
        index--;
        update();
    });

    $next.click(function() {
        index++;
        update();
    });

    update();
});
Eric
You'll want to remove the `display:hidden` that you put on the `.thumbs` div, for compatibility reasons. The jQuery hides the others anyway.
Eric
doesnt seem to work for me
Annie
+1  A: 
<style type="text/css">
    .ad-thumb-list 
    {
        width:650px;
        }
    .ad-thumb-list li 
    {
        display:block; 
        float:left;
        width:100px;
        height:100px;
        margin-right:20px;
        border:solid 1px #ccc;
        }
    .thumbs 
    {
        overflow:hidden;
        height:120px;
        width:280px;
        }            
</style>

and js:

<script type="text/javascript">
    $(function () {

        $('.forward').click(function () {
            $('.thumbs').animate({ scrollLeft: '+=' + $('.ad-thumb-list li').width() });
        });
        $('.back').click(function () {
            $('.thumbs').animate({ scrollLeft: '-=' + $('.ad-thumb-list li').width() });
        });
    });
</script>

and html

    <div class="gallery"> 
   <div class="back" style="opacity: 0.6;">Back</div>  
      <div class="thumbs">      
         <ul class="ad-thumb-list"> 
            <li></li>
            <li></li>
            <li></li>
            <li></li>
            <li></li>
         </ul>    
      </div>  
   <div class="forward" style="opacity: 0.6;">Forward</div> 
</div>
XGreen
It seems like this would work but I can't get it to do anything.
Annie
http://jsfiddle.net/3ysgy/Doesnt seem to work, thanks though!
Annie