Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 2 of 2
  1. #1
    Senior Member Hitch - CP's Avatar
    Join Date
    Jun 2009
    Location
    London
    Posts
    120
    Member #
    19164
    Hi Guys,

    I am not a JS buff which is why I am struggling with this image slider. I have been following a tutorial (found here- http://tutorialzine....lery-slideshow/) and trying to modify for a specific site.

    The site in question can be found here: http://www.alihitch....jects/rgmotors/

    As you can see, I am trying to get each image to change when a specific menu link is clicked.

    I have done what I can to make sure that the code is right and fits with the HTML/CSS.

    Of course, I never expected this to work first time.

    The HTML , CSS and JS are as follows respectively:

    Code:
    <section class="gallery">
        
            <div id="slides">
                <div class="slide"><img src="images/gallery/image1.png" width="560px" height="220px"></div>
                <div class="slide"><img src="images/gallery/image2.png" width="560px" height="220px"></div>
                <div class="slide"><img src="images/gallery/image3.png" width="560px" height="220px"></div>
                <div class="slide"><img src="images/gallery/image4.png" width="560px" height="220px"></div>
            </div><!-- .slides -->
            
            <div id="menu">
                <ul>
                    <li class="menuItem"><a href="">1. MOT</a></li>
                    <li class="menuItem menuItem2"><a href="">2. Winter</a></li>
                    <li class="menuItem menuItem3"><a href="">3. Tyres</a></li>
                    <li class="menuItem menuItem4"><a href="">4. Offers</a></li>
                </ul>
            </div><!-- .menu -->  
                  
        </section>

    Code:
    /* GALLERY */
    
    section.home-gallery section.gallery {
        width: 560px;
        overflow: hidden;
        
        height: 260px;
        float: left;
        margin-left: 29px;        
        
        border: 1px solid white;
        
        /*CSS3 Linear Gradient */
        background-image: -moz-linear-gradient(0% 100% 90deg,#E6E7E8, #F1F2F2);
        background-image: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#E6E7E8), to(#F1F2F2));    
        
        /* CSS3 Box Shadow */
        -moz-box-shadow: 0 0 2px #777;
        -webkit-box-shadow: 0 0 2px #777;
        box-shadow: 0 0 2px #777;
        
        /*CSS3 Rounded Corners */
        -moz-border-radius-bottomleft: 4px;
        -wenbkit-border-bottom-left-radius: 4px;
        border-bottom-left-radius: 4px;
        
        -moz-border-radius-bottomright: 4px;
        -wenbkit-border-bottom-right-radius: 4px;
        border-bottom-right-radius: 4px;
    }
    
    #slides {
        /*This is the slide area*/
        height: 220px;
        
        /* jQuery changes the width later on to the sum of the widths of all the slides */
        width: 560px;
        overflow: hidden;
    }
    
    .slide {
        float: left;
    }
    
    #menu {
        /*This is the slide menu container */
        height: 40px;
    }
    
    #menu ul {
        margin: 0;
        padding: 0;
    }
    
    #menu li {
        width: 136px;
        height: 21px;
        padding-top: 7px;
        margin-top: 7px;
        display: inline-block;
        list-style: none;
        text-indent: 20px;
    }
    
    #menu a {
        font-size: 11px;
        color: #999;
    }
    
    #menu a:hover {
        font-size: 11px;
        color: #444;
        font-weight: normal;
    }
    
    #menu li.menuItem2 {
        border-left: 1px solid #BCBCBC;
    }
    
    #menu li.menuItem3 {
        border-left: 1px solid #BCBCBC;
    }
    
    #menu li.menuItem4 {
        border-left: 1px solid #BCBCBC;
    }
    
    #menu li.act, #menu li.act:hover {    
        color: #444;
        font-weight: normal;
    }
    Code:
    // JavaScript Document
    
    $(document).ready(function(){
        /* This code is execited after the DOM has been completely loaded */
        
        var totWidth=0;
        var positions = new Array();
        
        $('#slides .slide').each(function(i){
            /*Loop through all the slides and store their accumlulative widths in totWidth */
            positions[i]=totWidth;
            totWidth += $(this).width();
            
            /* The positions array contains each slide's commutative offset from the left part of the container */
            
            if(!$(this).width())
            {
                alert("Please fill in the width and height for all your images in the gallery!");
                return false;
            }
        });
        
        $('#slides').width(totWidth);
        
        /* Change the container DIV's width to the exact width of all the slides combined */
        
        $('#menu ul li a').click(function(e){
            
            /* On a menuItem click */
            $('li.menuItem').removeClass('act').addClass('inact');
            $(this).parent().addClass('act');
            
            var pos = $(this).parent().prevAll('.menuItem').length;
            
            /* Start sliding animation */
            $('#slides').stop().animate({marginLeft:-positions[pos]+'px'},450);
            
            /* Prevent the default action of the link */
            e.preventDefault();
        });
        
        /* On Page load, mark the first menuItem as active */
        $('#menu ul li.menuItem:first').addClass('act').siblings().addClass('inact');
        
    });

    Many Thanks in advance to anybody who is able to help!
    Ali
    Ali Hitch

    Portfolio & Tutorial Site
    www.alihitch.com

  2.  

  3. #2
    WDF Staff AlphaMare's Avatar
    Join Date
    Oct 2009
    Location
    Montreal, Canada
    Posts
    4,570
    Member #
    20277
    Liked
    878 times
    your link is not working - can you re-post so I can see the site?
    Good design should never say "Look at me!"
    It should say "Look at this." ~ David Craib


    http://digitalinsite.ca ~ my current site . . info@digitalinsite.ca ~ my email

    If you feel that someone's post helped you fix your problem, answered your question, or just made you feel better, feel free to "Like" their post. The "Like" link is at the bottom right of each post, along side the "reply" link. And if you are being helped here, try to help someone else - pass it on!


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 10:33 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com