jQuery - 在 div 上悬停时,在 div 中滑动并能够将鼠标悬停在新打开的 div 上

发布于 2024-10-17 06:26:56 字数 696 浏览 5 评论 0原文

我试图将鼠标悬停在底部栏上,该底部栏将在其上方的另一个 div 中滑动,我可以单击位于其中的项目,然后当我将鼠标移开时,“出现的 div”将滑开。

但是,当我从底部栏移动鼠标以单击新出现的 div(在 div 中滑动)中的某些内容时,它会重新启用该效果,我如何才能停止此操作,以便我可以将鼠标悬停在两者上(在 div 中滑动之后)启用)并了解如何重新启动效果,本质上是将其放入相同的 SlideDown/slideUp 效果的循环中。

这是我的代码:

$(".playlist").hide();
$(".player, .playlist").hover( 
    function(){ $(".playlist").slideDown(); },
    function(){ $(".playlist").slideUp(); }
);

和我的 HTML:

<div class="playlist">
<!-- This would display some content that I can click on -->
</div>

<div class="player">
<!-- This expands across the whole window and is fixed to the bottom -->
</div>

I'm trying to do hover over bottom bar, which will slide in another div just above it which I can click items located within on and then when i mouse off both the "appeared div" will slide away.

However, when I move my mouse from the bottom bar to click on something in the newly appeared div (slid in div) it re-enabled the effect, how can I stop this so I can hover over both (after the slid in div is enabled) and have it how restart the effect essentially placing it into a loop of the same slideDown/slideUp effect.

Here's my code:

$(".playlist").hide();
$(".player, .playlist").hover( 
    function(){ $(".playlist").slideDown(); },
    function(){ $(".playlist").slideUp(); }
);

And my HTML:

<div class="playlist">
<!-- This would display some content that I can click on -->
</div>

<div class="player">
<!-- This expands across the whole window and is fixed to the bottom -->
</div>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浅浅淡淡 2024-10-24 06:26:56

http://jsfiddle.net/jv25Y/

新标记

<div class="player">
    <div class="playlist">
         This would display some content that I can click on 
    </div>
    This expands across the whole window and is fixed to the bottom
</div>

新 JS

$(function(){
    $(".playlist").hide();
    $(".player").hover( 
        function(){ $(".playlist").slideDown(); },
        function(){ $(".playlist").slideUp(); }
    );
});

这样的东西有用吗?现在基本上播放列表包含在播放器中。因此,当您尝试单击播放列表中的链接时,您的鼠标不会离开播放器。如果这不太适合(由于页面上的样式等),您也可以将一个元素包裹在播放列表和播放器周围,然后在其上调用悬停,如下所示,

Markup

<div id="wrapper">
    <div class="playlist">
         This would display some content that I can click on 
    </div>
    <div class="player">
        This expands across the whole window and is fixed to the bottom
    </div>
</div>

JS

$("#wrapper").hover( 
     function(){ $(".playlist").slideDown(); },
     function(){ $(".playlist").slideUp(); }
 );

http://jsfiddle.net/jv25Y/

New Markup

<div class="player">
    <div class="playlist">
         This would display some content that I can click on 
    </div>
    This expands across the whole window and is fixed to the bottom
</div>

New JS

$(function(){
    $(".playlist").hide();
    $(".player").hover( 
        function(){ $(".playlist").slideDown(); },
        function(){ $(".playlist").slideUp(); }
    );
});

Would something like that work? Basically playlist is contained in player now. So your mouse will not leave player, when you are trying to click a link in playlist. If that doesnt quite fit (due to styling on your page etc) You can also just wrap an element around playlist and player and then call hover on it instead like this,

Markup

<div id="wrapper">
    <div class="playlist">
         This would display some content that I can click on 
    </div>
    <div class="player">
        This expands across the whole window and is fixed to the bottom
    </div>
</div>

JS

$("#wrapper").hover( 
     function(){ $(".playlist").slideDown(); },
     function(){ $(".playlist").slideUp(); }
 );
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文