.slideToggle悬停在div jquery上

时间:2013-04-24 21:07:34

标签: jquery hover slidetoggle

我希望能够在悬停时滑动切换div,但它无法正常工作..以下是代码:

<div class='slide-header'>
        header....
</div>

<div class='slide-content'>
       Content..................
</div>

<script>
$(".slide-header").hover(function () {
    $(".slide-content").slideToggle("slow");
});
</script>

<style><!-- initially, I don't want to display .slide-content -->
    .slide-content { display:none; }
</style>

我怎么能在悬停时滑动?滑动?谢谢!

2 个答案:

答案 0 :(得分:6)

试试这个

$(".slide-header").hover(function () {
    $(".slide-content").stop().slideDown("slow");
}, function(){
    $(".slide-content").stop().slideUp("slow");
});

答案 1 :(得分:2)

将其包裹在document ready函数中:

$(function(){
    $(".slide-header").hover(function () {
        $(".slide-content").slideToggle("slow");
    });
});