So, I have jQuery page preloader on main page like this:
<script type="text/javascript">
$(window).load(function() {
$("#preloader").delay(700).fadeOut("slow");
})
<div id="preloader" class="preloader"></div>
This shows 4 times:
- When I enter the site through domain name;
- When I refresh main page by F5;
- When I click on logo (i must go to main page when i clicked that);
- When I click «Home» menu item.
But i want to show it only on first two times.
So, the first idea which came in my mind is delete
div
class to not show preloader image over whole page when i clicking logo or menu item by JS. And have used this:
document.getElementById("preloader").className = 'test';
But then... I realized that by clicking menu item to load main page again, i create new copy of document, so my preloader has his class again and showed up. So, i decided to use AJAX and to not reload whole page by clicking menu item or logo. Now i use this:
<script type="text/javascript">
$(document).ready(function(){
$("#blog, #logo").click(function(){
$("#container").load("/blog");
document.getElementById("preloader").className = 'test';
});
});
</script>
So, when i click logo or menu item i load my category called «blog» in container. And my side bar looks like this:
...
<a href="javascript:;" id="logo"><i class="logo"></i></a>
...
<li class="m_blog"><a id="blog" href="javascript:;"><i class="icon"></i>Blog</a></li>
...
So, it works! Preloader appear only when you open site through domain name. But 1 problem appear. When i open category «video» i have adress like this: mysite.com/video/
And when i came back to main page through logo or menu i have same adress! Because content loading without reload whole page and adress doesn't change. How i can fix it? Help me, please! I just want to show my preloader only once: when i came through domain name or refresh main page by F5. I already feel dizzy, because i only know HTML and CSS, but today start to learn AJAX and jQuery. Help me in this matter.