How to place a gif before displaying the site page

Asked

Viewed 9,290 times

3

I would like to put a gif of loading on my website. When I access the page before opening the site, I would first open the gif and stay for 1.5 seconds or so. This is possible?

Note: I want something like this http://ivang-design.com/chronos/videoyt/

  • 1

    http://answall.com/questions/8581/mostrar-gif-enquanto-p%C3%A1gina-carrega

  • @Lucas friend so this way that Voce sent on the link does not serve to min want so http://ivang-design.com/chronos/videoyt/

  • 1
  • You have not chosen any answer. None satisfies you?

4 answers

3

Doing this is extremely simple and can be done for as long as 1.5 seconds, or just disappear when you finish charging.

<img src='loading.gif' id='loader'/>

<script>setTimeout(function(){ loader.style.display='none'; },1500);</script>

The setTimeout event defines that after the time "1500" millisigundos = 1.5 seconds, the image will disappear. For declaring that the object (by its id) "Loader" receives the style method, which has the display parameter with its attribute 'None', which is invisible.

Or for the same shipment:

<img src='loading.gif' id='loader'/>

<script>window.onload= function(){ loader.style.display='none'; }</script>

The window.onload event will execute the function assigned to it.

  • You can assign the image style="position:Fixed;z-index:10000;left:44%;top:43%;", right after the ID to position it in the center and above the objects. depending on the size of the image and/or browser this may vary. this is an example, need to test and validate with your image if the position is suitable.

1

The plugin you want is the Royal Pre Loader.

One tip I give is to search the code of the site, in my case I use Chrome, I enter in Dev Tools, I go to the Source tab and look in the Javascript related folders, in your case it is in the folder "/js".

The other browsers also have this feature to inspect elements, so whenever you find a different effect, first of all take a look at the code of the site.

1

Do without external resources and with a fade effect:

HTML

<div id="preload" class="preload"></div>

CSS

.preload{
    position: fixed;
    z-index:99999;
    top:0; left:0;
    width:100%; height:100%;
    opacity:1;
    background-color:#000;
    background-image:url('../images/721.gif');
    background-position:50% 50%;
    background-repeat:no-repeat;
}

JS

window.onload = function(){
    var div = document.getElementById('preload');
    preload(div, 50);
};
function preload(el, interval){
    var op = 1;
    var timer = setInterval(function () {
        if (op <= 0.1){
            clearInterval(timer);
            el.style.display = 'none';
            el.className = '';
        }
        el.style.opacity = op;
        op -= op * 0.1;
    }, interval);
}

0


There is an option on JQuery very simple.
Using the examples already cited:

JQUERY

$(document).ready(function() {
  setTimeout('
              $("#preload").fadeOut(100);
  ', 1500);
});

When the page is completely "read" the div will disappear. The fadeOut(100) will cause the div disappear "smoothly" in 100 milliseconds. See more about the fadeOut here: http://api.jquery.com/fadeout/

The count of setTimeout also in milliseconds, so if you want 1.5 seconds, just multiply by 1000, in case 1500.

CSS

body {
  background: #cccccc;
}
.preload {
  position: fixed;
  z-index: 99999;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  opacity: 1;
  background-color: #fff;
  background-image: url('https://38.media.tumblr.com/bec5933eea5043acf6a37bb1394384ab/tumblr_meyfxzwXUc1rgpyeqo1_400.gif');
  background-size: 298px 298px;
  background-position: center;
  background-repeat: no-repeat;
}

In the background-position just put center. The z-index: 99999, will cause the div always be above all other page elements as long as they have a z-index less than "99999".

HTML

<div id="preload"></div>

See the result here: http://jsfiddle.net/SamirChaves/6ns0grm0/2/

Browser other questions tagged

You are not signed in. Login or sign up in order to post.