Javascript Jquery自动图像滑块w/CSS&;jQuery

Javascript Jquery自动图像滑块w/CSS&;jQuery,javascript,jquery,image,slider,Javascript,Jquery,Image,Slider,这是Soh Tanaka的自动图像滑块w/CSS&jQuery,我正在尝试对其进行自定义,以便在鼠标悬停在滑块上时显示.desc,但似乎没有任何帮助 //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

这是Soh Tanaka的自动图像滑块w/CSS&jQuery,我正在尝试对其进行自定义,以便在鼠标悬停在滑块上时显示.desc,但似乎没有任何帮助

//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
}); 
我为你做的。但基本上我不得不将描述块移到
image\u-revel
块之外,因为它正在被重新定位,要添加脚本来正确定位它会太麻烦

下面是变化的总结: 添加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;
}
新窗口块

<div class="window">    
 <div class="image_reel">
  <a href="http://www.designbombs.com/tag/slider/"><img src="reel_1.jpg" alt="" /></a>
  <a href="http://www.designbombs.com/tag/slider/"><img src="reel_2.jpg" alt="" /></a>
  <a href="http://www.designbombs.com/tag/slider/"><img src="reel_3.jpg" alt="" /></a>
  <a href="http://www.designbombs.com/tag/slider/"><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>

由于没有显示HTML标记,我假设“.desc”是一个
div
,包含某种标题。在任何情况下,我都不明白为什么要绑定两次悬停,还需要在unhover函数中运行
slideToggle
。为此,应更改以下行:

//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;
});
为此:

//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
}); 

我开发了一个非常简单的jQuery插件来实现您的目标,它被称为-如果您决定使用它并且有任何问题,只要在Github页面上问一个问题,我就会帮您解决。

谢谢,这很好,但我希望它与悬停时的输入和悬停时的输出相反。我怎么能改变呢?这就是它的作用。。。但是,如果您将鼠标悬停在paging div上,就好像您已将鼠标悬停在图像上,因为单击新页面会将其切换到该页面,而不是描述。我注意到当.desc向下滑动并转到下一个图像时,会出现一些错误。旧的.desc from image位于图像2的.desc之上。第二个错误是,如果你在它上面,然后把鼠标从上面拿下来,再把鼠标悬停在它上面。desc会发疯,会上下几次。我不知道如何修复这些问题。有什么想法吗?请尝试此更新()。我将“play”对象设置为null
play=null
,当它应该被清除时-当您将鼠标悬停在图像上时,它不应该旋转。摆脱了滑动切换,取而代之的是slideUp和slideDown。在slideDown中,我还包括了一个
.stop(true,true)
来删除动画。我希望这能为您解决所有问题!:)
//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
});