gpt4 book ai didi

html - 相对于设备大小滚动

转载 作者:太空宇宙 更新时间:2023-11-04 06:56:14 25 4
gpt4 key购买 nike

我正在制作一个网站,您可以在其中单击一个按钮,它会向下滚动到下面的信息。我的问题是打开屏幕的大小是相对于设备屏幕的。这意味着固定滚动条在不同设备上可能太远或不够远。总而言之,我的问题是:如何跳转确切的设备屏幕高度?这是我的代码:`

<div id='textPage1'>

<div id='leesMeer'>
<a href="#page2" class='leesMeer'type="button" value='Lees Meer'>LEES MEER</a>
</div>

</div>

<div id='page2'>

<div id='textPage2'>
<p>hi</p>
</div>

</div>

还有我的CSS:

#textPage1  {
float: right;
margin-right: 100px;
z-index: -1;
}

#beschrijving {
font-family: agency;
font-size: 20px;
color: #f2f2f2;
letter-spacing: 2px;
transform: scale(1, 1.1);
line-height: 30px;
z-index: 1;
margin-left: 50px;
}

.leesMeer {
font-family: agency;
font-size: 30px;
color: #f2f2f2;
border: 5px solid #f2f2f2;
border-radius: 15px;
padding: 12px 40px 12px 40px;
text-decoration: none;
-webkit-transition-duration: 0.5s;
position: absolute;
}

最佳答案

您可以使用 Javascript 来指定向下滚动,如下例所示:

HTML:

<div class="first"><button type="button" onclick="smoothScroll(document.getElementById('second'))">Click Me!</button></div>
<div class="second" id="second">Hi</div>

CSS:

.first {
width: 100%;
height: 1000px;
background: #ccc;
}

.second {
width: 100%;
height: 1000px;
background: #999;
}

Javascript:

window.smoothScroll = function(target) {
var scrollContainer = target;
do { //find scroll container
scrollContainer = scrollContainer.parentNode;
if (!scrollContainer) return;
scrollContainer.scrollTop += 1;
} while (scrollContainer.scrollTop == 0);

var targetY = 0;
do { //find the top of target relatively to the container
if (target == scrollContainer) break;
targetY += target.offsetTop;
} while (target = target.offsetParent);

scroll = function(c, a, b, i) {
i++; if (i > 30) return;
c.scrollTop = a + (b - a) / 30 * i;
setTimeout(function(){ scroll(c, a, b, i); }, 20);
}
// start scrolling
scroll(scrollContainer, scrollContainer.scrollTop, targetY, 0);
}

这是jsfiddle中的代码http://jsfiddle.net/rjSfP/

关于html - 相对于设备大小滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52425067/

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