JQuery鼠标悬停问题

时间:2012-07-27 20:10:14

标签: jquery mouseover

我使用以下脚本,并且有占位符div。当我鼠标悬停时,div播放按钮应该超过占位符。

我连续三个占位符。当鼠标悬停在一个特定占位符上时,将显示所有播放按钮。我需要的是当鼠标悬停在占位符上时,只显示播放图像。

希望你能理解我的问题。有人可以帮我这么做吗?

jQuery.noConflict();
       jQuery(function(){
        jQuery('.placeholder').mouseover(function(){
               jQuery('.play').show('show');
        });
        jQuery('.placeholder').mouseleave(function(){
               jQuery('.play').hide('hide');
        });
      });

HTML:

 <div class="placeholder item"><div class="play"><img src="images/play_ico.jpg"></div></div>
 <div class="placeholder item"><div class="play"><img src="images/play_ico.jpg"></div></div>
 <div class="placeholder item"><div class="play"><img src="images/play_ico.jpg"></div></div>

CSS:

.placeholder{
    width:120px;
    float:left;
    background:#ccc;
    height:67px;
    position:relative;
}

.play{
    width:120px;
    height:67px;
    position:absolute;
    top:0;
    left:0;
    display:none;
    background:#000;
    opacity:0.4;
filter:alpha(opacity=40);
}

3 个答案:

答案 0 :(得分:5)

尝试以下方法:

    jQuery('.placeholder').mouseenter(function(){
           jQuery(this).find('.play').show();
    });
    jQuery('.placeholder').mouseleave(function(){
           jQuery(this).find('.play').hide();
    });

作为替代方案,您可以使用hover方法:

    jQuery('.placeholder').hover(function() {
           jQuery(this).find('.play').show();
    }, function() {
           jQuery(this).find('.play').hide();
    })

答案 1 :(得分:2)

你确定你做得对吗,你真的需要使用noConflict吗?

jQuery(function(){
    jQuery('.placeholder').on({
        mouseenter: function(){
           jQuery('.play', this).show('slow');
        },
        mouseleave: function() {
           jQuery('.play', this).hide('slow');
        }
    });
});

或只是

jQuery('.placeholder').on('mouseenter mouseleave', function() {
    jQuery('.play', this).toggle();
});

答案 2 :(得分:0)

我不认为'show'和'hide'是有效的参数传递到节目和隐藏功能,除非你使用这些名称的自定义动画?

尝试

jQuery('.play').show();

jQuery('.play').hide();

除非您希望它们进出动画,否则请使用

jQuery('.play').show('slow');

jQuery('.play').hide('slow');

或同等的:)

http://api.jquery.com/show/

相关问题