aro*_*ooo 22 html javascript css css3 web
有没有办法(使用CSS3,JS或其他任何东西)让页面在某个点向下滚动?
我希望我的页面加载时没有最初在加载时显示的标题(意味着它高于用户的实际视口).
有一个简单/简单的方法来解决这个问题吗?
pb2*_*b2q 25
你可以使用标准的javascript : window.scroll(x, y).
考虑到你将这样做,这应该工作得很好onload,即窗口应该从(0,0)开始.四处玩,(x, y)直到你的标题到达你满意的位置.当然,你需要在标题移动时随时更改它.
例:
<body onLoad="window.scroll(0, 150)">
Run Code Online (Sandbox Code Playgroud)
Ani*_*ket 17
如果你有一个id给一个div包含头后您的内容,那么你或许可以用这样的URL加载页面,http://website.com/page#id.
这将带您到div存在的位置.
您可以window.scroll(x,y)在页面加载时使用.
Uda*_*ale 10
这些是非常简单的技巧:
创建css偏移类并分配给正文
.offset{
margin-top:-500px;
}
Run Code Online (Sandbox Code Playgroud)
因此,该主体将从顶部偏移500px
然后将以下代码添加到正文中
<body class="offset" onLoad="window.scroll(0, 150)">
Run Code Online (Sandbox Code Playgroud)然后使用jquery,在加载页面时删除偏移类
$(document).ready(function(){
$(".row").removeClass("offset");
});
Run Code Online (Sandbox Code Playgroud)bry*_*aun 10
当前的答案会导致页面显示"跳跃",或者要求您知道要跳转的确切像素数.
我想要一个跳过容器的解决方案,无论容器的大小/内容如何,这就是我想出的:
HTML
<div class="skip-me">Skip this content</div>
Run Code Online (Sandbox Code Playgroud)
CSS
// Hide the content initially with display: none.
.skip-me {
display: none;
}
.unhide {
display: block;
}
Run Code Online (Sandbox Code Playgroud)
JS
// Unhide the content and jump to the right place on the page at the same time
function restoreAndSkipContent() {
var hidden = document.querySelector('.skip-me');
hidden.classList.add('unhide');
window.scroll(0, hidden.offsetHeight);
};
restoreAndSkipContent();
Run Code Online (Sandbox Code Playgroud)
HTML - 命名锚点
您还可以使用好的旧锚.使用定义命名锚点
<a id="start">any text</a>
Run Code Online (Sandbox Code Playgroud)
这应该在必须在视野中定义.因为即使在屏幕的底部也可以看到它,你可能需要将锚点略低于要求.这样我们就可以确保不需要显示的顶部内容被很好地隐藏.一旦定义为在页面加载时向下滚动,URL应该是page.aspx #start而不是page.aspx
<a href="#start">access within the same page</a>
<a href="page.aspx#start">access from outside the page</a>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
59325 次 |
| 最近记录: |