You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

170 lines
9.7 KiB

<!DOCTYPE html>
<html lang="en">
<meta charset="utf-8">
<title>YBlog - How to preload your site with style</title>
<meta name="keywords" content="web, jQuery, webdesign" />
<link rel="shortcut icon" type="image/x-icon" href="../../../../Scratch/img/favicon.ico" />
<link rel="stylesheet" type="text/css" href="/css/y.css" />
<link rel="stylesheet" type="text/css" href="/css/legacy.css" />
<link rel="alternate" type="application/rss+xml" title="RSS" href="/rss.xml" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="apple-touch-icon" href="../../../../Scratch/img/about/FlatAvatar@2x.png" />
<!--[if lt IE 9]>
<script src=""></script>
<!-- IndieAuth -->
<link href="" rel="me">
<link href="" rel="me">
<link href="" rel="me">
<link rel="pgpkey" href="../../../../pubkey.txt">
<body lang="en" class="article">
<div id="content">
<div id="header">
<div id="choix">
<span id="choixlang">
<a href="../../../../Scratch/fr/blog/2009-10-How-to-preload-your-site-with-style/">French</a>
<span class="tomenu"><a href="#navigation">↓ Menu ↓</a></span>
<span class="flush"></span>
<div id="titre">
<h1>How to preload your site with style</h1>
<div class="flush"></div>
<div id="afterheader" class="article">
<div class="corps">
<h2 id="example">Example</h2>
<p>Here is a live example of what appear while loading my pages.</p>
<script src=""></script>
<div id="demo" style="width:45%; position: relative; height: 8em; background: #333; background-position: 50% 50%; color: #fff; text-align: center; padding-top: 1em; margin-left: auto; margin-right: auto; border: solid 10px rgba(255,255,255,0.7); -webkit-border-radius: 1em; -moz-border-radius: 1em; border-radius: 1em; cursor: pointer; ">
Hello! I’ve finished loading!
Click me to see me disapear again.
<div id="todisapear" style="color: #000; position:absolute;top:0;left:0;text-align: center; padding-top: 1em; width: 100%; background-color: #eee; height: 8em;">
<p>Loading… <img style="border: none; background-color: none; background: none" src="../../../../Scratch/img/loading.gif" alt="loading logo" /></p>
function Rabbit(){
.animate({opacity: 1.0},3000)
$('#todisapear').animate({opacity: 1.0},3000).fadeOut();
<p>I first tried to integrate <a href="">queryLoader</a>, but it didn’t fill my needs.</p>
<p>The plugin add a black div to hide all the content. But as the script had to be launched at the end of the source code my website show for a small time.</p>
<p>In order to hide this small artefact, here is how I do that.</p>
<h2 id="code">Code</h2>
<p>In a first time, I added at the top of the body the div hiding all the content.</p>
<div class="sourceCode" id="cb1"><pre class="sourceCode html"><code class="sourceCode html"><a class="sourceLine" id="cb1-1" title="1">...</a>
<a class="sourceLine" id="cb1-2" title="2"><span class="kw">&lt;body&gt;</span></a>
<a class="sourceLine" id="cb1-3" title="3"><span class="kw">&lt;div</span><span class="ot"> id=</span><span class="st">&quot;blackpage&quot;</span><span class="kw">&gt;</span></a>
<a class="sourceLine" id="cb1-4" title="4"> content to display during the loading.</a>
<a class="sourceLine" id="cb1-5" title="5"><span class="kw">&lt;/div&gt;</span></a>
<a class="sourceLine" id="cb1-6" title="6">...</a></code></pre></div>
<p>and here is the associated CSS to <code>#blackpage</code>:</p>
<div class="sourceCode" id="cb2"><pre class="sourceCode css"><code class="sourceCode css"><a class="sourceLine" id="cb2-1" title="1"><span class="pp">#blackpage</span></a>
<a class="sourceLine" id="cb2-2" title="2"> top<span class="in">: 0 </span></a>
<a class="sourceLine" id="cb2-3" title="3"> left<span class="in">: 0 </span></a>
<a class="sourceLine" id="cb2-4" title="4"> width<span class="in">: 100%</span></a>
<a class="sourceLine" id="cb2-5" title="5"> height<span class="in">: 100%</span></a>
<a class="sourceLine" id="cb2-6" title="6"> margin-left<span class="in">: 0</span></a>
<a class="sourceLine" id="cb2-7" title="7"> margin-right<span class="in">: 0</span></a>
<a class="sourceLine" id="cb2-8" title="8"> margin-top<span class="in">: 0</span></a>
<a class="sourceLine" id="cb2-9" title="9"> margin-bottom<span class="in">: 0</span></a>
<a class="sourceLine" id="cb2-10" title="10"> position<span class="in">: absolute</span></a>
<a class="sourceLine" id="cb2-11" title="11"> text-align<span class="in">: center</span></a>
<a class="sourceLine" id="cb2-12" title="12"> color<span class="in">: #666</span></a>
<a class="sourceLine" id="cb2-13" title="13"> padding-top<span class="in">: 10em</span></a>
<a class="sourceLine" id="cb2-14" title="14"> background-color<span class="in">: #eee</span></a>
<a class="sourceLine" id="cb2-15" title="15"> z-index<span class="in">: 9000</span></a></code></pre></div>
<p>and the associated jQuery code:</p>
<div class="sourceCode" id="cb3"><pre class="sourceCode javascript"><code class="sourceCode javascript"><a class="sourceLine" id="cb3-1" title="1"><span class="at">$</span>(document).<span class="at">ready</span>(<span class="kw">function</span>()<span class="op">{</span></a>
<a class="sourceLine" id="cb3-2" title="2"> <span class="at">$</span>(<span class="st">'#blackpage'</span>).<span class="at">fadeOut</span>()<span class="op">;</span></a>
<a class="sourceLine" id="cb3-3" title="3"><span class="op">}</span>)<span class="op">;</span></a></code></pre></div>
<p>Yes, it is as simple as that. And, putting the <code>#blackpage</code> div at the top of my page, I ensure to hide anything while loading.</p>
<p>I hope it had helped you!</p>
<div id="afterarticle">
<div id="social">
<a href="/rss.xml" target="_blank" rel="noopener noreferrer nofollow" class="social">RSS</a>
<a href="" target="_blank" rel="noopener noreferrer nofollow" class="social">Tweet</a>
<a href="" target="_blank" rel="noopener noreferrer nofollow" class="social">FB</a>
<br />
<a class="message" href="../../../../Scratch/en/blog/Social-link-the-right-way/">These social sharing links preserve your privacy</a>
<div id="navigation">
<a href="../../../../">Home</a>
<span class="sep">¦</span>
<a href="../../../../Scratch/en/blog">Blog</a>
<span class="sep">¦</span>
<a href="../../../../Scratch/en/softwares">Softwares</a>
<span class="sep">¦</span>
<a href="../../../../Scratch/en/about">About</a>
<div id="totop"><a href="#header">↑ Top ↑</a></div>
<div id="bottom">
Published on 2009-10-03
<a href="">Follow @yogsototh</a>
<a rel="license" href="">Yann Esposito©</a>
Done with
<a href="" target="_blank" rel="noopener noreferrer nofollow"><strike>Vim</strike></a>
<a href="" target="_blank" rel="noopener noreferrer nofollow">spacemacs</a>
<span class="pala">&amp;</span>
<a href="" target="_blank" rel="noopener noreferrer nofollow"><strike>nanoc</strike></a>
<a href="" target="_blank" rel="noopener noreferrer nofollow">Hakyll</a>
<hr />
<div style="max-width: 100%">
<a href="">
<img src="../../../../Scratch/img/ada-logo.png" class="simple" style="height: 16px;
border-radius: 50%;
display:inline-block;" />
<code style="display:inline-block;
text-align: left;
vertical-align: top;
max-width: 85%;">