Good afternoon, I want to make a small static site without reloading the main page when clicking on links. Just loading countries into a div block, trying to implement all this through jquery
$(document).ready(function() { $('li a').click(function(){ var toLoad = $(this).attr('href'); $('.load-in').fadeOut('fast', loadContent); $('.loader').show(); function loadContent() { $('.load-in').css({ opacity : 0.3 }).load( toLoad , hideLoad ); }; function hideLoad () { $('.load-in').fadeIn('fast' , function () { //прячем лоадер и opacity 1 $('.loader').fadeOut('fast'); $('.load-in').animate({ opacity : 1 }); } ); }; return false; }); });
css
*{padding:0;margin:0;} .ab {width:60px;height:60px;background:red;} .wrap {width:900px;margin:0 auto;position:relative;} .load-in {} .loader { height:60px; width:60px; left:50%; margin-left:-30px; position:fixed; top:30%; display:none; z-index:1000; background:url('images/preloader.gif') center no-repeat red; }
markup
<div class="loader"></div> <div class="wrap"> <ul> <li class="ab"><a href="load.html">load me</a></span> <li class="ab"><a href="loader.html">load here</a></span></li> </ul> <div class="load-in"> </div> </div>
But for some reason callback in this line
$('.load-in').css({ opacity : 0.3 }).load( toLoad , hideLoad );
It works before the pictures are loaded in the loading page. It is necessary that the opacity and preloader be removed after the content and images are fully loaded. I don’t really understand jquery, so if I ask a Nubian question I apologize in advance!
Thank!