以大型网站为中心的视口
我正在尝试使用此模板构建一个目前为 16000px 的水平网站
http://tympanus.net/ Tutorials/WebsiteScrolling/
该网站有四个部分,每个部分宽 4000px,我试图实现一个 div,该 div 将在每个部分的浏览器视口中居中。
垂直方向上,50% 有效,但水平方向上 50% 则需要进入页面 2000 像素。
有谁知道有什么有用的吗?
我找到了一个脚本,用于将我的 #verycentre Div 放在首页上,它不是 4000px 的 50%,它是浏览器窗口的,看起来很棒。
我现在遇到的问题是我需要在每个部分锚点处有一个居中的窗口 div。
当页面滚动并点击每个部分时,我试图为每个部分实现一个可调整大小的#verycentre Div。
我现在使用的代码发布在下面,并且非常适合第 1 节中的第一个居中 div。
我认为问题可能是函数调用已进行 document.ready
,并且当时只有一个 #verycentred div窗口,但我不是 100% 确定。
如何使每个锚点处的所有 #verycentred Div 居中/可调整?
谢谢
Im trying to build a horizontal website which is at 16000px at the moment, using this template
http://tympanus.net/Tutorials/WebsiteScrolling/
the website has four sections 4000px wide each, I am trying to achieve a div that will be centred in the browsers viewport at each section.
Vertically, 50% works, but horizontally 50% would be 2000px into the page.
does anyone know anything that would work?
I have found a script for centring my #verycentre Div on the first page, it isnt 50% of 4000px, its of the browser window and looks great.
The problem I am having now is that I need a centred window div at each section anchor.
as the page scrolls across and hits each section, im trying to achieve a resizeable #verycentre Div for each section.
The code I am using at the moment is posted below and works perfectly for the first centred div in section 1.
I think the problem might be that the function call is made document.ready
and at that time there is only one #verycentred div in the window, but am not 100% sure.
how can I make all of the #verycentred Div's at each anchor point be centred/resieable?
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
通过 CSS 将其居中是一个问题,因为您的宽度会偏移窗口区域,因此您可以使用 JQuery 函数,该函数将帮助您根据窗口位置居中该 div
看看这篇文章,其中他们解释了如何使居中基于窗口区域显示的对象。
使用 jQuery 将 DIV 在屏幕上居中
It would be a problem to center it via CSS since your width offsets window area so what you could use is a JQuery function that will help you center that div based on window position
Take a look on this post, where they explain how to center a object based on window area display.
Using jQuery to center a DIV on the screen
您可以使用负左边距与设置位置:相对;
You can use negative left margin with set position:relative;