如何制作类似于Apple Mac页面的页面预加载器
如果您查看 Apple 网站上的 Mac 页面。 http://www.apple.com/mac/ 页面加载时,它们的“主体”在中心显示图像。页面完全加载后,它们的内容会淡入。如果您使用 Chrome 或 Safari 并打开 Element Inspector,您会看到它们的正文在页面加载时获得 class="loaded displayed"
。这会触发内容淡入。如果删除类,内容就会淡出。
我正在为我的网站寻找类似的东西。我不希望整个内容不显示,我仍然想显示页眉和页脚。所以基本上我希望 div#content_area
在文档准备好时向下滑动...唯一的问题是,他们不使用任何类型的 display:none;
身体。他们对此更加小心,因为如果 JS 文件失败,内容仍然会显示。
我怎样才能做到这一点?他们的做法必须是轻量级的,因为任何人都可以编写类似的内容。
$(document).ready(function() {
$('div#content_area').attr(class, loaded revealed);
});
我需要做的就是添加 .slide()
函数并隐藏内容,直到页面加载。
If you have a look at Apple's Mac page on their website. http://www.apple.com/mac/
Their "body" displays an image in the center while the page is loading. After the page is fully loaded, their content fades in. If you use Chrome or Safari and open the Element Inspector, you'll see their body gets the class="loaded revealed"
when the page is loaded. And that triggers the content to fade in. If you remove the classes, the content will fade out.
I'm looking for something similar to this for my website. I don't want the whole entire content to not display, I still want to display the header and footer. So basically I want the div#content_area
to slide down on document ready... The only problem is, they don't use any kind of display:none;
for their body. They're a bit more careful about that, because if the JS file fails, the content will still display.
How can I make this? They way they do it must be lightweight because anybody can write something like
$(document).ready(function() {
$('div#content_area').attr(class, loaded revealed);
});
All I need to do is add the .slide()
function and hide the content until the page loads.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在您想要的位置设置您的内容 DIV...在顶部设置您想要作为占位符的图像(如果可能/必要,则使用绝对)。
在 CSS 中,使用
z-index
属性将图像保持在其他图像之上。然后你要做的就是使 IMG 成为一个
display:none;
属性,然后当页面加载时你可以使用 jQuery 打开它......所以使用 JS 占位符会显示并位于上面......如果没有 JS,图像占位符是不可见的,用户只能在加载时看到内容 DIV。这有道理吗?
Setup your DIV of content right where you want it... setup the image you want to be a placeholder right over the top (with absolute if possible/necessary).
In CSS use the
z-index
property to keep the image above the other.What you do then is make the IMG a
display:none;
property, and then as they page is loading you can turn it on with jQuery... so with JS the placeholder shows and sits above... without JS, the image placeholder is invisible, and the user simply sees the content DIV as it loads.That make sense?
发现Apple将所有元素的不透明度设置为0。在主体加载上,它将类添加到主体并使用一些基本的CSS,如下所示这
是我的版本,http://jsfiddle.net/dqUaX/1/
它的优点是:
非常棒不是吗?
您必须将脚本放在
结束标记的末尾之前...
Have found out that Apple has all it's elements opacity set to 0. And on the body load, it adds the classes to the body and uses some basic CSS like this
Here's my version, http://jsfiddle.net/dqUaX/1/
What's great about it is:
Pretty awesome no?
You must put the script before the end of the
<body>
closing tag...