gpt4 book ai didi

javascript - 粘性导航栏在滚动时闪烁

转载 作者:行者123 更新时间:2023-11-28 03:14:21 26 4
gpt4 key购买 nike

我有一个粘性导航栏,其中的文本应该在滚动时消失。如果该文本的内容超过几行,导航栏将会闪烁。我认为这与文档高度发生重大变化的元素有关,但我不确定如何修复它。

我已将其从显示:无切换为可见性:按照上一个线程中的建议隐藏。它从所有内容都闪烁变为只有较长的段落。我还尝试添加延迟效果,但我似乎无法响应文档高度变化的实际问题,因此滚动位置发生变化,这可能会导致闪烁效果。

var $win = $(window)
var $doc = $(document)

$win.scroll(function(e) {
scrollEffects();
});

function scrollEffects() {
var limit = 85;
var scrolled = $win.scrollTop();
if ($doc.scrollTop() >= limit) {
$(".intro").addClass('inactive');
//$('#banner-contents').css('opacity', 1 - (scrolled * .00280));
// console.log('scrolled');
} else {
$(".intro").removeClass('inactive');
}
}
body {
height: 1500px;
background: tomato;
}

.nav {
background: white;
position: sticky;
top: 0px;
}

.intro {
color: $black;
font-size: 1.7rem;
text-align: center;
max-height: 7rem;
transition: max-height 0.4s ease;
}

.inactive {
max-height: 0;
overflow: hidden;
transition: max-height 0.1s ease;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="nav">
<p class="intro">
This is some text that should disappear without flickering <br> This is some text that should disappear without flickering <br> This is some text that should <strong>disappear</strong> without flickering <br> This is some text that should disappear
without flickering <br> This is some text that should disappear without flickering <br>
</p>
Other text Other text Other text Other text
</div>

<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent dapibus finibus lorem, sed pulvinar est vestibulum et. Nunc semper ligula eget urna imperdiet ullamcorper. Etiam tristique consectetur ornare. Vestibulum ipsum mi, ultrices vitae tincidunt
non, ornare sit amet dolor. Maecenas convallis sollicitudin nibh, in laoreet leo tristique eget. Donec vitae auctor risus. Integer mattis nibh ipsum, nec porttitor ligula commodo ac. Etiam pharetra elit sit amet magna hendrerit scelerisque. Nam vel
imperdiet metus. Vestibulum lectus enim, tempus sed orci ut, fermentum consectetur nisl. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Donec ut eros ex. Quisque lacinia viverra mauris sit amet convallis.
Phasellus in neque risus. Quisque rutrum lacinia erat in cursus. Praesent imperdiet et est vitae tincidunt. Nulla leo massa, tempor consequat tincidunt aliquet, blandit id libero. Nullam condimentum dapibus dictum. Sed vel magna dignissim, maximus augue
non, laoreet ante. Ut urna velit, porta vel mauris sit amet, suscipit efficitur nisi. Integer cursus bibendum tortor sit amet tempor. Proin eget turpis ipsum. Maecenas et quam ornare, imperdiet turpis mattis, fermentum diam. Mauris blandit fringilla
euismod. Fusce in nunc est. Morbi fringilla pulvinar massa, pulvinar auctor ex eleifend ut. Integer eros lorem, viverra et tincidunt nec, aliquet at erat. Morbi sed dapibus eros. Nunc tristique ullamcorper porttitor. Class aptent taciti sociosqu ad
litora torquent per conubia nostra, per inceptos himenaeos. Sed malesuada nunc tincidunt, faucibus purus eu, ultrices velit. Fusce non velit diam. Praesent ac vulputate libero, et dignissim justo. Mauris at felis efficitur dolor tincidunt hendrerit
id at lacus. Curabitur sit amet elit arcu. Donec a elit felis. Aliquam laoreet placerat velit, sed molestie nisl congue vitae. Ut aliquet aliquam tincidunt. In ultricies suscipit efficitur. Sed ultrices ligula dui, non sodales massa pulvinar in. Nulla
accumsan risus quam, sit amet mattis orci facilisis eget. Curabitur tempor porttitor nibh ac ultrices. Integer scelerisque, elit at auctor consectetur, leo enim pellentesque sem, et tristique nisl sem in magna. Aliquam vel egestas sapien. Fusce blandit
lectus vitae molestie egestas. Aliquam varius, risus et viverra dapibus, urna tellus condimentum nisi, eget vehicula sapien risus eu neque. Praesent at tristique massa, at cursus nibh. Aliquam erat volutpat. Etiam cursus consequat bibendum. Sed suscipit
ac dui vitae fermentum.
</p>

最佳答案

你只需用 .class(.nav) 上的这个 css 替换你的 css,我就会修复

.nav {
background: white;
position: fixed;
top: 0px;
left:0;
right:0;
}

关于javascript - 粘性导航栏在滚动时闪烁,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59773478/

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