gpt4 book ai didi

html - 仅使用 CSS 滚动时如何将固定 slider 移动到顶部

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

我想在向下滚动时将我的固定导航移动到顶部。我尽了最大努力,但没能做到。

这是代码以及我正在寻找的问题。

这是 Link

#lower {
background: #c8e600;
background-image: url(images/headerimg.png);
background-repeat: no-repeat;
background-position: 40px;
width: 100%;
height: 60px;
position: fixed;
top: 0;
left: 0;
margin-top: 60px;
z-index: 100;
opacity: 0.80;
}
#lower ul li a {
background: rgba(0, 0, 0, 0) none repeat scroll 0 0;
color:#000;
font-family: "Source Sans Pro", sans-serif;
padding-left: 2px;
padding-right: 2px;
text-align: right;
padding-bottom: 16px;
padding-top: 26px;
}
#lower ul li {
padding: 10px;
list-style-type: none;
padding-left: 8px;
float: right;
list-style:none;
margin-bottom:0px;
margin-left:0px;
margin-right:0px;
margin-top:0px;
transform: rotate(-360deg);
}
#lower ul li a:hover {
background:#FFF;
transition: all 1.5s ease 0s;
}
#lower ul li:hover {
transform: rotate(0deg);
transition: transform 1.5s;
}
<div id="lower">
<ul>
<li><a href="theContact.html">the<strong>CONTACT</strong></a></li>
<li><a href="#">the<strong>BLOG</strong></a></li>
<li><a href="#">the<strong>TRAINERS</strong></a></li>
<li><a href="#">see<strong>SCHDULE</strong></a></li>
<li><a href="#">popular<strong>PROGRAMS</strong></a></li>
<li><a href="#">Our<strong>CLASES</strong></a></li>
<li><a href="#">why<strong>US</strong></a></li>
</ul>
</div>
<div style="width:100%;overflow:auto"><br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br /><br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
</div>

最佳答案

CSS 更改:

#lower
{
margin-top:0;
top:40px;

jQuery 解决方案:

<head>    
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
</head>

注意:您必须在 <head> 中添加 jQuery 库

<script>

$(document).ready(function(e) {
$(document).on('scroll',function()
{
if(window.pageYOffset>180)
{
$('#lower').css({'top':'0px'});
}else
{
$('#lower').css({'top':'40px'});
}
});
})
</script>

jQuery 演示: https://jsfiddle.net/0andyke4/3/


JavaScript 解决方案:

<script>
window.addEventListener("scroll",move);
function move()
{
if(window.pageYOffset>180)
{
document.getElementById("lower").style.top = 0;
}else
{
document.getElementById("lower").style.top =40+'px';
}
}

</script>

演示 JavaScript: https://jsfiddle.net/0andyke4/7/


关于html - 仅使用 CSS 滚动时如何将固定 slider 移动到顶部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32882415/

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