[jQuery] Smooth navigation
2 posts
Page 1 of 1
Hello everyone,
It's been a while since I've posted any tutorials.
This time, I decided to make tutorial more client side related, since last tutorial was server side related ([PHP] Make your site multilang!). This tutorial will be about:
Smooth transitions between pages in jQuery
If you don't want to follow tutorial, there is a code on the bottom of the page!
So let's begin with importing jQuery to our HTML file. All you have to do is add this bit of code to head section of your page:
Now we will create function that will handle our document.ready event:
We still have to add redirection function which will be called after fade out effect:
That would be it. If you want to copy paste complete code, here it is:
Hope you like it
-Filip
It's been a while since I've posted any tutorials.
This time, I decided to make tutorial more client side related, since last tutorial was server side related ([PHP] Make your site multilang!). This tutorial will be about:
Smooth transitions between pages in jQuery
If you don't want to follow tutorial, there is a code on the bottom of the page!
So let's begin with importing jQuery to our HTML file. All you have to do is add this bit of code to head section of your page:
Code: Select all
Next step is to open <script> tag and get some coding done!<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
Now we will create function that will handle our document.ready event:
Code: Select all
Inside of this function, we will hide whole page first: $(document).ready(function() {
Code: Select all
and than fade in whole page with built in jQuery function fadeIn. Fade in process will last for 2 seconds (2000 mseconds)$("body").css("display", "none");
Code: Select all
This is the code for loaded page. Now we will add event to all anchor (<a>) tags on page. Again we are creating function that will be called when anchor tag is clicked:$("body").fadeIn(2000);
Code: Select all
In next few lines of code, we will prevent default transition and declare variable which will hold href attribute of clicked link:$("a").click(function(event){
Code: Select all
And finally, we are fading out the page with fadeOut function and call redirection function (function name: transition):
event.preventDefault();
hrefVar = this.href;
Code: Select all
After that, close the a.click event function with });$("body").fadeOut(1000, transition);
We still have to add redirection function which will be called after fade out effect:
Code: Select all
And finally close the document.ready function with }); function transition() {
window.location = hrefVar;
}
That would be it. If you want to copy paste complete code, here it is:
Code: Select all
Thanks for reading this tutorial! $(document).ready(function() {
$("body").css("display", "none");
$("body").fadeIn(2000);
$("a").click(function(event){
event.preventDefault();
hrefVar= this.href;
$("body").fadeOut(1000, transition);
});
function transition() {
window.location = hrefVar;
}
});
Hope you like it
-Filip
CodenStuff wrote:Nope, it's just your sick and dirty mind. You sick twisted warped little pervo
nice tutorial mate , keep it up i dont much have connections with jquery though :P
Find my programs on Softpedia
2 posts
Page 1 of 1
Copyright Information
Copyright © Codenstuff.com 2020 - 2023