gpt4 book ai didi

javascript - 图像淡入但覆盖了原来在 div 中的文本

转载 作者:太空宇宙 更新时间:2023-11-04 03:32:54 24 4
gpt4 key购买 nike

我有一个带有隐藏图像的 div 和其中的另一个 div。当用户向下滚动到 div 的中间点时,图像淡入。但是,我想让另一个 div 中的文本保持可见。这是一个消除任何混淆的 fiddle :http://jsfiddle.net/8eudrmcx/16/

请注意当图像淡入时文本是如何被遮盖的。我知道这是正常行为,但我对如何保持文本可见(和可选择)感到困惑。

HTML

<section>
<img src="http://www.billboard.com/files/styles/promo_650/public/stylus/2029269-marilyn-manson-Agata-Alexander-617-409.jpg" class="overlay" />
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
</section>

CSS

section {
background-color: #000;
color: #fff;
height: 500px;
width: 500px;
}

.overlay {
display: none;
position: absolute;
height: 500px;
width: 500px;
}

JS

function isScrolledIntoView($elem) {
var docViewTop = $(window).scrollTop();
var docViewBottom = docViewTop + $(window).height();

var elemTop = $elem.offset().top;
var elemMiddle = elemTop + $elem.height()/2;
return docViewBottom >= elemMiddle && docViewTop <= elemMiddle;
}
$(window).scroll(function(){
$elem = $("section"); //or what element you like
if(isScrolledIntoView($elem)){
$('.overlay').fadeIn();
}
});

最佳答案

您需要使用叠加层和部分的 z-index http://jsfiddle.net/8eudrmcx/17/

   section {
background-color: #000;
color: #fff;
height: 500px;
width: 500px;
position: relative;
z-index: 1;
}
.overlay {
display: none;
position: absolute;
height: 500px;
width: 500px;
z-index: -1;
}

关于javascript - 图像淡入但覆盖了原来在 div 中的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26048296/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com