[英]Link to element`s id and centering screen
I have link to section like this: 我有链接到这样的部分:
<a href="#section3">Section 3</a>
How i can to center (vertically) the screen, and section to be in the middle of screen not to the top. 我如何才能将屏幕居中(垂直),并使部分位于屏幕中间而不是顶部。
Thank`s 感谢`s
I don't really think that what you want is possible without using Javascript. 我真的认为如果不使用Javascript,您想要的东西是不可能的。
If you are able to use js, you could use this code: 如果您能够使用js,则可以使用以下代码:
function scrollToElement(selector, time, verticalOffset) {
time = typeof(time) != 'undefined' ? time : 1000;
verticalOffset = typeof(verticalOffset) != 'undefined' ? verticalOffset : 0;
element = $(selector);
offset = element.offset();
offsetTop = offset.top + verticalOffset;
$('html, body').animate({
scrollTop: offsetTop
}, time);
} }
如果我正确地可视化,我将无法相信。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.