views:

659

answers:

2

This is Automatic Image Slider w/ CSS & jQuery by Soh Tanaka I am trying to customize it to show .desc when the mouse hover overs the slider but it does not seem to work any help?

//Set Default State of each portfolio piece
$(".paging").show();
$(".paging a:first").addClass("active");

//Get size of images, how many there are, then determin the size of the image reel.
var imageWidth = $(".window").width();
var imageSum = $(".image_reel ul.examples").size();
var imageReelWidth = imageWidth * imageSum;

//Adjust the image reel to its new size
$(".image_reel").css({'width' : imageReelWidth});

//Paging + Slider Function
rotate = function(){    
    var triggerID = $active.attr("rel") - 1; //Get number of times to slide
    var image_reelPosition = triggerID * imageWidth; //Determines the distance the image reel needs to slide

    $(".paging a").removeClass('active'); //Remove all active class
    $active.addClass('active'); //Add active class (the $active is declared in the rotateSwitch function)

    //Slider Animation
    $(".image_reel").animate({ 
        left: -image_reelPosition
    }, 500 );

}; 

//Rotation + Timing Event
rotateSwitch = function(){      
    play = setInterval(function(){ //Set timer - this will repeat itself every 3 seconds
        $active = $('.paging a.active').next();
        if ( $active.length === 0) { //If paging reaches the end...
            $active = $('.paging a:first'); //go back to first
        }
        rotate(); //Trigger the paging and slider function
    }, 7000); //Timer speed in milliseconds (3 seconds)
};

rotateSwitch(); //Run function on launch

//On Hover
$(".image_reel").hover(function() {
    clearInterval(play); //Stop the rotation
}, function() {
    rotateSwitch(); //Resume rotation
}); 

//Hide the tooglebox when page load
$(".desc").hide();
//slide up and down when hover over heading 2
$(".image_reel").hover(function(){
// slide toggle effect set to slow you can set it to fast too.
$(this).next(".desc").slideToggle("slow");
return true;
});


//On Click
$(".paging a").click(function() {   
    $active = $(this); //Activate the clicked paging
    //Reset Timer
    clearInterval(play); //Stop the rotation
    rotate(); //Trigger rotation immediately
    rotateSwitch(); // Resume rotation
    return false; //Prevent browser jump to link anchor
}); 
+1  A: 

Hi!

I made a demo for you. But basically I had to move the description blocks outside of the image_reel block because it was being re-positioned and it would have been too much trouble to add scripting to position it properly.

So here is a summary of changes: Added CSS

.desc {
 display: none;
 position: absolute;
 top: 0;
 left: 0;
 z-index: 101;
 background: url(http://i45.tinypic.com/30w087b.png); /* 1x1 png with 70% opacity */
 color: #fff;
 font-size: 2em;
 padding: 10px;
 -moz-border-radius: 0 0 3px 0;
 -khtml-border-radius: 0 0 3px 0;
 -webkit-border-radius: 0 0 3px 0;
}

New Window Block

<div class="window">    
 <div class="image_reel">
  <a href="http://www.designbombs.com/tag/slider/"&gt;&lt;img src="reel_1.jpg" alt="" /></a>
  <a href="http://www.designbombs.com/tag/slider/"&gt;&lt;img src="reel_2.jpg" alt="" /></a>
  <a href="http://www.designbombs.com/tag/slider/"&gt;&lt;img src="reel_3.jpg" alt="" /></a>
  <a href="http://www.designbombs.com/tag/slider/"&gt;&lt;img src="reel_4.jpg" alt="" /></a>
 </div>
 <div class="descriptions">
  <div class="desc">blah blah blah 1</div>
  <div class="desc">blah blah blah 2</div>
  <div class="desc">blah blah blah 3</div>
  <div class="desc">blah blah blah 4</div>
 </div>
</div>

Script (Updated)

//slide up and down when hover over heading 2
$(".window").hover(function(){
    // slide toggle effect set to slow you can set it to fast too.
    $(".desc").eq( $('.paging a.active').attr("rel") - 1 ).slideDown("slow");
    return true;
}, function(){
    $(".desc").stop(true,true).slideUp('slow');
});
fudgey
thanks that works great but I wanted it to be the reverse where on hover it comes in and off hover it goes away. How can I change that?
Jacinto
Huh? That's what it does... but, if you hover over the paging div, it acts like you have hovered off of the image because clicking on a new page would switch it to that page, but not the description.
fudgey
I have noticed some errors with this when .desc slides down and it goes to the next image the old .desc from image goes on top of .desc of image two. Second error is if you hove over it and then take your mouse off of it and hover over it again the .desc goes crazy and goes up and down a few times. I cant figure out how to fix these got any ideas?
Jacinto
Try this update (http://jsfiddle.net/3TJrj/2/). I set the "play" object to null `play = null` when it is supposed to be cleared - when you hover over the image, it shouldn't rotate. And got rid of the slideToggle and replaced it with slideUp and slideDown. In the slideDown, I also included a `.stop(true,true)` to drop the animation que. I hope that resolves all of the issues for you! :)
fudgey
A: 

Since you don't show the HTML markup, I assume that '.desc' is a div containing some sort of caption. In any case, I don't see why you bind the hover twice, and also you need to run slideToggle in the unhover function. To do this you should change these lines:

//On Hover
$(".image_reel").hover(function() {
    clearInterval(play); //Stop the rotation
}, function() {
    rotateSwitch(); //Resume rotation
}); 

//Hide the tooglebox when page load
$(".desc").hide();
//slide up and down when hover over heading 2
$(".image_reel").hover(function(){
// slide toggle effect set to slow you can set it to fast too.
$(this).next(".desc").slideToggle("slow");
return true;
});

To this:

//Hide the tooglebox when page load
$(".desc").hide();

//On Hover
$(".image_reel").hover(function() {
    $(this).next(".desc").slideToggle("slow");
    clearInterval(play); //Stop the rotation
}, function() {
    $(this).next(".desc").slideToggle("slow");
    rotateSwitch(); //Resume rotation
}); 
mVChr