gpt4 book ai didi

jquery - 当我添加模糊背景时,它会模糊页面的其余部分

转载 作者:行者123 更新时间:2023-11-28 14:20:18 25 4
gpt4 key购买 nike

同一个问题的所有答案都不适用于我,因为使用 jQuery 制作的动画淡入淡出。如果我把{position: fixed;左:0; right: 0;} 对于背景类和内容类,淡入淡出动画不起作用。我还尝试将 {filter: none;} 添加到背景类以外的所有内容中。

$(function(){ 
$('.intro').fadeIn('slow');
});

$(document).ready(function() {
$(window).scroll( function(){
$('.article').each( function(i){
var bottom_of_object = $(this).position().top + $(this).outerHeight();
var bottom_of_window = $(window).scrollTop() + $(window).height();
if( bottom_of_window > bottom_of_object ){
$(this).animate({'opacity':'1'},1500);

}

});

});

});
#main-container{
height: 2000px;
background-image: url('https://i.postimg.cc/43V74cv9/Screenshot-2019-03-19-at-6-29-57-PM.jpg');
filter: blur(5px);
background-position: center;
background-repeat: no-repeat;
background-size: cover;
z-index: -1;
}


.article{
background-color: blue;
margin: 50px;
padding: 50px;
z-index: 0;
opacity: 0;
}
h1{
text-align: center;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<html>
<body>
<div class="bg">
<div id="main-container">
<h1>TITLE PLACEHOLDER</h1>
<div id="intro">intro stuff</div>
<div class="article">other stuff</div>
<div class="article">other stuff</div>
<div class="article">other stuff</div>
<div class="article">other stuff</div>
</div>
</div>

最佳答案

主容器包装了您的其余代码。当然,当您对其应用 blur-filter 时,它会模糊包装器中存在的其他元素。尝试添加另一个 div,如编辑后的代码所示,具有绝对定位。这将解决您的问题。

$(function(){ 
$('.intro').fadeIn('slow');
});

$(document).ready(function() {
$(window).scroll( function(){
$('.article').each( function(i){
var bottom_of_object = $(this).position().top + $(this).outerHeight();
var bottom_of_window = $(window).scrollTop() + $(window).height();
if( bottom_of_window > bottom_of_object ){
$(this).animate({'opacity':'1'},1500);

}

});

});

});
#main-container{
height: 2000px;
position: relative;
}

.main-image {
position: absolute;
width: 100%;
height: 100%;
background-image: url('https://i.postimg.cc/43V74cv9/Screenshot-2019-03-19-at-6-29-57-PM.jpg');
background-position: center;
background-repeat: no-repeat;
background-size: cover;
z-index: -1;
filter: blur(5px);
}

.article{
background-color: blue;
margin: 50px;
padding: 50px;
z-index: 0;
opacity: 0;
}
h1{
text-align: center;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<html>
<body>
<div class="bg">
<div id="main-container">
<div class="main-image"></div>
<h1>TITLE PLACEHOLDER</h1>
<div id="intro">intro stuff</div>
<div class="article">other stuff</div>
<div class="article">other stuff</div>
<div class="article">other stuff</div>
<div class="article">other stuff</div>
</div>
</div>

关于jquery - 当我添加模糊背景时,它会模糊页面的其余部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55281350/

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