1

我有一个带有叠加层的图像列表。当我将鼠标悬停在图像上时,文本和叠加层应该会使用 JQuery 消失。当我将鼠标悬停在图像上时,该特定图像的覆盖消失,这是正确的。问题是文本。当我将鼠标悬停在图像上时,该图像和所有其他图像上的文本都会消失。我只希望隐藏该特定图像的文本和叠加层。这似乎是一个小问题,因为我让叠加层正常工作。先谢谢朋友。

这是JQuery:

//Hides the screen and text on mouseover
$('.screen').mouseover(function() {
    $('.screen_text').hide();
    $(this).slideUp(400);

});
//Shows the screen and text on mouseout
$('.portfolio img').mouseout(function() {
    $('.screen_text').show();
    $('.screen').slideDown(400);

});
4

3 回答 3

3

without seeing your html mockup, my assumption is that your jquery selector brings back all the text element (because you are doing $('.screen_text') ) I think what you want to do is something like:

$('.screen_text',this).hide();

which should only bring back the elements that has a class name screen_text in the context of this

于 2012-06-13T19:30:50.570 回答
2

类选择器匹配太多。

//Hides the screen and text on mouseover
$('.screen').mouseover(function() {
    $(this).find('.screen_text').hide();
    $(this).slideUp(400);

});
//Shows the screen and text on mouseout
$('.portfolio img').mouseout(function() {
    $('.screen_text').show();
    $('.screen').slideDown(400);

});

使用 jQuery.find()搜索.screen_text作为悬停的后代.screen

于 2012-06-13T19:30:44.540 回答
2

The issue is that you are hiding every element which has the class name "screen_text" when you perform $('.screen_text').hide();. You should find a better way to select or differentiate them.

There is no way to provide any more support without seeing an example of the DOM. Although there may be a logical error in the execution of this jQuery, there is nothing wrong syntactically.

于 2012-06-13T19:31:32.747 回答