tags:

views:

194

answers:

2

Hey, i wan't to make a cool effect on my page, and i'm thinking, how about to hide everything while loading and show each div with effect one by one? if its a bad idea, can you help me with a better idea?

EDIt: Using the $("div").each() jQuery function. EDIT2: Children by children.

EDIT3:

<div id="loader"><table cellpadding="0" cellspacing="0" width="100%" height="100%"><tr><td><img src='/assets/images/ajax-loader.gif' border=0 alt=""><br><br>A carregar, aguarde...</td></tr></table></div>

    <!-- start #menu -->
    <div class="wrapper" id="menu">
        <div class="center_div">
            <h1 class="logo"><a href="/pagprincipal" title="Microdual">Microdual</a></h1>
            <ul class="sf-menu"><li class="active"><a href="empresa/perfil" title="Empresa" ><span class="menuicon" id="empresa"></span>Empresa</a><ul><li class="active"><a href="/empresa/perfil" title="Perfil" >Perfil</a></li>
<li><a href="/empresa/politica-qualidade" title="Política de Qualidade" >Política de Qualidade</a></li>
<li><a href="/empresa/novidades" title="Novidades" >Novidades</a></li>

<li><a href="/empresa/portfolio" title="Portfólio" >Portfólio</a></li>
<li class="last"><a href="/empresa/contactos" title="Contactos" >Contactos</a></li>
</ul></li>
<li><a href="/produtos" title="Produtos" ><span class="menuicon" id="produtos"></span>Produtos</a><ul><li><a href="/produtos/alojamento-web" title="Alojamento Web" >Alojamento Web</a></li>
</ul></li>
<li><a href="/servicos" title="Serviços" ><span class="menuicon" id="servicos"></span>Serviços</a><ul><li><a href="/servicos/assistencia-tecnica" title="Assistência Técnica" >Assistência Técnica</a></li>
</ul></li>
<li class="last"><a href="/suporte" title="Suporte" ><span class="menuicon" id="suporte"></span>Suporte</a><ul><li><a href="/suporte/suporte-empresas" title="Suporte Técnico Empresas" >Suporte Empresas</a></li>
<li><a href="/suporte/suporte-home" title="Suporte Técnico Home" >Suporte Home</a></li>

<li><a href="/suporte/suporte-tecnico-web" title="Suporte Técnico Web" >Suporte Web</a></li>
<li class="last"><a href="/suporte/area-de-downloads" title="Área de Downloads" >Área de Downloads</a></li>
</ul></li>
</ul>
        </div>
    </div>
    <!-- end #menu -->

<!-- start #main -->
    <div class="wrapper" id="header_page">
        <div class="center_div">

            <div id="right">
<p style="text-align: center;"><img src="assets/images/perfil-top.jpg" alt="" width="590" height="200" /></p>
<h3>A Nossa Miss&atilde;o</h3>
<p>A Microdual tem a miss&atilde;o de desenvolver solu&ccedil;&otilde;es tecnol&oacute;gicas inovadoras,
que permitam satisfazer todas as necessidades dos clientes, parceiros e
empresas, atrav&eacute;s de produtos e servi&ccedil;os de elevada qualidade, que os tornam
mais eficientes. </p>
<h3>A Nossa Vis&atilde;o</h3>
<p>Acreditamos
que atrav&eacute;s da inova&ccedil;&atilde;o tecnol&oacute;gica actual iremos encontrar as solu&ccedil;&otilde;es
necess&aacute;rias para enfrentar os desafios do futuro. Da tecnologia adv&eacute;m a
oportunidade para as empresas crescerem, para os cidad&atilde;os em mercados
emergentes prosperarem entrando na Economia digital, e para as pessoas adaptarem
novas possibilidades.</p>

<h3>Os Nossos Valores</h3>
<p>A nossa conduta deve refletir os mais altos padr&otilde;es de &eacute;tica;<br />A nossa comunica&ccedil;&atilde;o deve ser clara e precisa;<br />O nosso gerenciamento deve ser em equipa, consistente e focado;<br />O nosso relacionamento com clientes e colaboradores deve ser transparente e baseado na responsabilidade e confian&ccedil;a entre as partes.</p>
<ul class="post_list">
</ul>
<h3>O Nossos Objetivo</h3>
<p>Melhorar continuamente o que fazemos, para assim contribuir
para o desenvolvimento sustent&aacute;vel, acrescentando vantagem competitiva.</p>

            </div>
            <div id="left">
<ul class="sf-submenu"><li class="active"><a href="/empresa/perfil" title="Perfil" >Perfil</a></li>
<li><a href="/empresa/politica-qualidade" title="Política de Qualidade" >Política de Qualidade</a></li>
<li><a href="/empresa/novidades" title="Novidades" >Novidades</a></li>
<li><a href="/empresa/portfolio" title="Portfólio" >Portfólio</a></li>
<li class="last"><a href="/empresa/contactos" title="Contactos" >Contactos</a></li>
</ul>
            </div>

        </div>
    </div>
    <!-- end #main -->



    <!-- start #footer -->
    <div class="wrapper" id="footer">
            <div id="footer_contents">
                <p>©Microdual 2010 - <a href="empresa/termos-e-condicoes-utilizacao" title="">Termos de Utilização</a> - <a href="empresa/politica-privacidade" title="">Privacidade</a> - <a href="empresa/compatibilidade-do-website" title="">Compatibilidade</a> - <a href="mapasite" title="">Mapa do Site</a> - <a href="empresa/contactos" title="">Contactos</a>  |</p>

                <ul>
                    <li><a href="#" title=""><img src="/assets/templates/default/img/network_icons/feed.gif" alt="Feed" /></a></li>
                    <li><a href="#" title=""><img src="/assets/templates/default/img/network_icons/twitter.gif" alt="Twitter" /></a></li>
                    <li><a href="#" title=""><img src="/assets/templates/default/img/network_icons/facebook.gif" alt="Facebook" /></a></li>
                </ul>
                <form action="" method="get">
                    <div>
                        <input class="input_search" name="search_field"  type="text">
                        <input value="Procurar" class="button_search" type="submit">

                    </div>
                </form>
            </div>
    </div>

thanks to all José Moreira

+1  A: 

You could use something like this:

$(function() {
    // Start showing the divs
    showDiv();
});

function showDiv() {
    // If there are hidden divs left
    if($('div:hidden').size() > 0) {
        // Fade the first of them in
        $('div:hidden:first').fadeIn();
        // And wait one second before fading in the next one
        setTimeout(showDiv, 1000);
    }
}

That find the next hidden div and fade it in every second. Just hide the divs you want to show using CSS's display: none; beforehand.


If you for some weird reason have to use the each function, this might work.. kinda.

$(function() {
    $('div:hidden').each(function(index) {
        setTimeout(function(el) {
            el.fadeIn();
        }, index * 1000, $(this));
    });
});
Tatu Ulmanen
liked this one :Dcan you use $.each() jQuery function please?
CuSS
Why would you have to use the `each` function if this works? You can do everything you can do in an `each` loop inside the `showDiv` function also. `Each` just complicates things.
Tatu Ulmanen
i know how to do with the each function, but i can't do it because i need to do it children by children, and i don't know how to do it. thanks for your answer :D
CuSS
i have to use each to do the children by children process, for example, we have a div inside a div that is inside other div, i wan't to make it by order. thanks for the sympathy
CuSS
You're welcome for my sympathy. I added an example that uses `each`, perhaps that's what you're looking for? Both methods should traverse the DOM tree in correct order, using `each` doesn't matter as it is the `$()` part that does the fetching.
Tatu Ulmanen
it doesn't work for me :s , it call's the function, one by one, but the div's doesn't do the effectEDIT: THANKS, it's working now :D
CuSS
You could also use the animation completion callback of `fadeIn` instead of `setTimeout` like this: `$('div:hidden:first').fadeIn(500, showDiv);`
Michael Kessler
It (`$('div:hidden:first').fadeIn(500, showDiv);`) could, even, be the only line in the `showDiv` function.
Michael Kessler
@Michael, that's true but it would cause the divs to fire right after each other. In my example, the animation is 500ms-ish and the interval 1000ms, so there's a pause of 500ms after every fade in.
Tatu Ulmanen
i tried your script on FF 3.5 and it works like a charm, but on IE 7, it takes a break with coffee :/it hides everything, but it doesn't show anything. :/
CuSS
A: 

Try the next code:

$('div').hide().each(function(index, domElement) {
      $(this).slideDown("slow");
      // Wait for the end of the animation somehow...
    })
Michael Kessler
it do all the divs in the same time, doesn't do the children by children effect. thanks for your answer.
CuSS
I know that. That's why I wrote the `// Wait for the end of the animation somehow...` line. I provided you the jquery (the main part) - now add your JS for waiting half a second after each div appearance...
Michael Kessler
I see that the wait/sleep in JS is impossible. It leaves us with the accepted answer. Notice my additions for that answer...
Michael Kessler