简体   繁体   English

向下滑动并与不同的div向上滑动

[英]slide down and slide up with different div's

I have a div named first , and another div named second ,both are independent div's.what i need is to be able to slide down div second when the user's mouse hovers over div first,and keep it that way if the user is hovering over div second ,otherwise slide up div second. 我有一个名为first的div,另一个名为second的div,都是独立的div。我需要的是在用户的鼠标悬停在div上时能够将div向下滑动,并在用户将鼠标悬停在div上时保持这种方式。 div秒,否则向上滑动div秒。

$("#first").hover(function(e)
{
    $("#second").slideDown(1000);
},function(e){
    $("#second").slideUp(1000);
});

This is my current code,but it slides up div second ,when i hover over it. 这是我当前的代码,但是当我将鼠标悬停在它上面时,它会每秒滑动div。

You want to display the div#second even user is hovering over it. 您要显示div#second即使用户将hovering在它上面。 So you should also handle hover for div#second too. 因此,您也应该将鼠标悬停在div#second And additionally you should use .stop() to clear up the animation queue every time before a new animation starts. 另外,您应该在每次开始新动画之前使用.stop()清除动画队列。

Try, 尝试,

$("#first,#second").hover(function(e)
{
    $("#second").stop().slideDown(1000);
},function(e){
    $("#second").stop().slideUp(1000);
});

DEMO DEMO

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM