检查鼠标是否悬停在任何对象上

发布于 2024-10-31 19:18:45 字数 548 浏览 0 评论 0原文

我有一个 jQuery 动画示例http://jsfiddle.net/p7Eta/

如果鼠标根本不在容器 div 内,我希望弹出所有标题。我尝试做类似的事情:

$("#container").mouseout(

     function() {
    //slides spans up
    $('.popup').stop().animate({
        bottom: 0 + 'px'
    });

});

但它不适用于之前的动画。达到这种效果的正确方法是什么?

编辑:我想要类似的东西:http://jsfiddle.net/RE3XK/ 但在鼠标悬停时,我希望像第一个示例中那样弹出各个跨度标题,而不是让它们全部消失

I have a jQuery animation example here: http://jsfiddle.net/p7Eta/

I would like all the titles to pop out if the mouse is not within the container div at all. I have tried to do something like:

$("#container").mouseout(

     function() {
    //slides spans up
    $('.popup').stop().animate({
        bottom: 0 + 'px'
    });

});

But it does not work with the prior animations. What is the correct way to achieve this effect?

EDIT: I'd like something similar to this: http://jsfiddle.net/RE3XK/ but on mouseover I'd like the individual span titles to pop up like in the first example instead of having them all dissapear

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

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

发布评论

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

评论(5

送君千里 2024-11-07 19:18:45

你的意思是这样的。

检查工作示例 http://jsfiddle.net/p7Eta/8/

更新

$("#slider div.popup").hover(
function() {

    //slides spans up
    $('span', this).animate({
        bottom: 0 + 'px'
    });
}, function() {

    //slides spans down
    $('span', this).animate({
        bottom: '-' + 200 + 'px'
    });
});

$(document).mouseover(
function(e) {
    e.stopPropagation()
    $('#slider div.popup').find(' span').animate({
        bottom: 0
    });
});

You mean like this.

Check working example http://jsfiddle.net/p7Eta/8/

Update

$("#slider div.popup").hover(
function() {

    //slides spans up
    $('span', this).animate({
        bottom: 0 + 'px'
    });
}, function() {

    //slides spans down
    $('span', this).animate({
        bottom: '-' + 200 + 'px'
    });
});

$(document).mouseover(
function(e) {
    e.stopPropagation()
    $('#slider div.popup').find(' span').animate({
        bottom: 0
    });
});
仅冇旳回忆 2024-11-07 19:18:45

最后,jsFiddle 合作了......

我正在做一些 hacky 的事情,但这是我让它工作的唯一方法。我必须向当前悬停的元素添加一个 .hover 类,因为如果没有它,我的代码将无法正常工作。
只要不看代码,它就会看起来很好!

这是一个工作示例: http://jsfiddle.net/p7Eta/41/

代码:

// JavaScript Document

//When div.popup is moused over moused over
$("#slider div.block").hover(

function() {

    //slides spans up
    $(this).addClass('hovered');
    $(this).find('span').stop().animate({
        bottom: '0px'
    });
}, function() {
$(this).removeClass('hovered');
    //slides spans down
    $(this).find('span').stop().animate({
        bottom: '-200px'
    });
});

$('#container').hover(function() {
    $('#slider div.block:not(.hovered) span').animate({
        bottom: '-200px'
    });
}, function() {
    $('#slider div.block span').stop().animate({
        bottom: '0px'
    });
});

Finally, jsFiddle cooperated...

I'm doing something hacky, but it's the only way that I could get it to work. I had to add a .hover class to the currently hovered element, as my code doesn't work properly without it.
Just don't look at the code, and it'll look nice!

Here's a working example: http://jsfiddle.net/p7Eta/41/

And the code:

// JavaScript Document

//When div.popup is moused over moused over
$("#slider div.block").hover(

function() {

    //slides spans up
    $(this).addClass('hovered');
    $(this).find('span').stop().animate({
        bottom: '0px'
    });
}, function() {
$(this).removeClass('hovered');
    //slides spans down
    $(this).find('span').stop().animate({
        bottom: '-200px'
    });
});

$('#container').hover(function() {
    $('#slider div.block:not(.hovered) span').animate({
        bottom: '-200px'
    });
}, function() {
    $('#slider div.block span').stop().animate({
        bottom: '0px'
    });
});
李不 2024-11-07 19:18:45

我的猜测是,您正在寻找类似于这个的东西,对吗?我尝试的方式的唯一问题是您输入的元素也会向下滑动(我猜它不应该)。

My guess is that you're going for something along the lines of this one, am I right? The only issue with the way I tried it, is that the element you're entering on, also slides down (which it shouldn't, I guess).

愿与i 2024-11-07 19:18:45

或者类似的东西......它实际上在重置动画之前停止动画。 http://jsfiddle.net/NDtMW/

Or something like this... which actually stops the animations before resetting it. http://jsfiddle.net/NDtMW/

夏末 2024-11-07 19:18:45

请澄清您的要求。您

  • 是否希望动画连续播放,以便在不悬停时它们会持续运动?
  • 希望它们在没有悬停时处于向上运动状态?

顺便说一句,你的原始脚本只能在 IE 中运行。如果您只关心一种浏览器,请在以后说明。 IE 用户可能是 SO 上的少数。

Please clarify what you're asking for. Do you

  • want the animations to continuously so they're in constant motion whenever they're not hovered on?
  • want them to be at the motion-up state whenever they're not hovered on?

BTW, your original script only works in IE. If you're only concerned with one browser, please say so in the future. IE users are probably the minority on SO.

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