gpt4 book ai didi

php - 我可以知道我的页面在渲染之前是否会有滚动条吗? PHP JavaScript

转载 作者:行者123 更新时间:2023-11-28 12:08:41 24 4
gpt4 key购买 nike

我有一个header.php其中有我的 <a name='#top' />

我有一个footer.php我想做类似的事情

if ($_SERVER[' is scroll bar ']
{
echo <a href='#top'>Back to Top</a>
}

是否可以使用 PHP 或 Javascript 来做这样的事情,我可以知道我的页面是否会比渲染时间提前很长时间?

最佳答案

首先,我不确定此类代码的实际用途。我从来都不确定“返回顶部”或“跳转到顶部”链接会做什么:

  • 它只会将我带到页面顶部吗?
  • 它会把我带到顶部下方的某个 anchor 吗?
  • 它会把我带到首页页面吗?
  • 它会重新加载吗(叹气)?

不过,我确实知道按Home键会做什么,而且我怀疑如果可能的话,大多数人宁愿使用 native 控件导航页面。

尽管如此,加载页面后,您可以通过在页面调整大小时设置事件处理程序来动态切换此类链接:

var toTopLink = document.getElementById("toTopLink");

function checkLink(e) {
/*
* document.height = works in most browsers
* document.body.scrollHeight = needed in IE
*
* window.innerHeight = works in most browsers
* document.documentElement.offsetHeight = IE in compatibility mode
* document.body.offsetHeight = IE backwards compatibility
*
* In most browsers, document.height equals window.innerHeight if there is no
* scrollbar. For IE, we test whether the scrollable height is greater than the
* visible document height.
*/
if ((document.height || document.body.scrollHeight) >
(window.innerHeight || document.documentElement.offsetHeight ||
document.body.offsetHeight)) {
toTopLink.style.display = "block";
} else {
toTopLink.style.display = "none";
}
}

window.onresize = checkLink;
window.onload = checkLink;

不同的浏览器——我指的是 IE 与其他浏览器——有自己的计算高度的方法,因此上面的解释可能有点多余。

关于php - 我可以知道我的页面在渲染之前是否会有滚动条吗? PHP JavaScript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6604959/

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