简体   繁体   English

元素不应该褪色,而是

[英]Element shouldn't be fading but is

Just like the title says, I have an element that shouldn't be fading but is. 就像标题中所说的那样,我有一个元素不应该淡化,而应该淡化。 The element in question is text on top of an image that fades when you move your mouse over it. 有问题的元素是图像上方的文本,当您将鼠标移到图像上方时,该文本会淡化。

HTML: HTML:

<div id="image-wrapper">
<ul id="team-members">
    <li class="tile-wrapper fade">
        <div class="tile">
            <img src="http://placehold.it/158x210" />
             <h3 class="bio bio-header" style="display:none;">Header</h3>
            <p class="bio bio-footer" style="display:none;">Information</p>
        </div>
    </li>
</ul>

jQuery jQuery的

$(document).ready(function () {
$('.fade').mouseenter(function (ev) {
    $(this).fadeTo(150, 0.5);
    $(this).find('img').siblings().fadeIn(150);
}).mouseleave(function () {
    $(this).fadeTo(150, 1);
    $(this).find('img').siblings().fadeOut(150);
});
});

Fiddle: https://jsfiddle.net/oLckb6h3/4/ 小提琴: https : //jsfiddle.net/oLckb6h3/4/

Fade the img rather than the .fade element... 淡入img而不是.fade元素...

 $(document).ready(function() { $('.fade').mouseenter(function(ev) { $(this).find('img').fadeTo(150, 0.5).siblings().fadeIn(150); }).mouseleave(function() { $(this).find('img').fadeTo(150, 1).siblings().fadeOut(150); }); }); 
 ul { list-style-type:none; } .bio { padding:15px; } .bio-header { margin-top:-150px; } .tile { width:158px; height:210px; border: 1px solid black; } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <div id="image-wrapper" > <ul id="team-members"> <li class="tile-wrapper fade"> <div class="tile"> <img src="http://placehold.it/158x210"/> <h3 class="bio bio-header" style="display:none;">Header</h3> <p class="bio bio-footer" style="display:none;">Information</p> </div> </li> </ul> </div> 

A suggestion: 一条建议:

HTML HTML

<div id="image-wrapper" >
    <ul id="team-members">
        <li class="tile-wrapper fade">
            <div class="tile">
                <div class="doFade">&nbsp;</div>
                <div class="info">
                    <h3 class="bio bio-header">Header</h3>
                    <p class="bio bio-footer">Information</p>
                </div>
                <img src="http://placehold.it/158x210"/>
            </div>
        </li>
    </ul>
</div>

CSS CSS

ul {
    list-style-type:none;
}

.bio {
    padding:15px;
}

.tile {
    width:158px;
    height:210px;
    border: 1px solid black;
    position: relative;
}

.doFade {
    position: absolute;
    left: 0;
    background: #fff;
    top: 0;
    right: 0;
    bottom: 0;
    opacity: 0.5;
    display: none;
}

.info {
    position: absolute;
    left: 0;
    background: transparent;
    top: 0;
    right: 0;
    bottom: 0;
    display: none;
}

jQuery jQuery的

$(document).ready(function() {
    $('.fade').mouseenter(function(ev) {
        $('.doFade', this).add( $('.info', this) ).fadeIn(150);
    }).mouseleave(function() {
        $('.doFade', this).add( $('.info', this) ).fadeOut(150);
    });
});

DEMO DEMO

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

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