My website structure is a header, content, footer. My goal is that every time the visitor clicks on the links, only the “content” part loads, everything else stays the same.
I don’t know what is the best practice to reach this effect I read a lot on the web, I found some examples for iFrames and or jquery/css/ajax, but I can’t make up my mind what to use.
(The content on the website, that would be changing, would be all sub pages of my website, hence I thought iFrames is not the tool I need, but correct me if I am wrong.)
The “content” of the page consist of a white background and a layer above it, that are pictures / text.
What I want to achieve is whenever the visitor clicks a link, the content layer of text / pictures “fades out”, the white background re sizes to a new size of the sub page, then the new content of the sub page fades in.
The “fade in, fade out” is implemented already:
$(document).ready(function() {
$("#valtozo").css("display", "none");
$("#valtozo").fadeIn(2000);
$("a").click(function(event){
event.preventDefault();
linkLocation = this.href;
$("#valtozo").fadeOut(1000, redirectPage);
});
function redirectPage() {
window.location = linkLocation;
}
});
“valtozo” is the id of the changing div.
For the smooth re-size of the transition of the white background I thought I use this:
jQuery Animation – Smooth Size Transition
I would like to hear your thoughts / ideas what to use to achieve frames like functionality while keeping all visual effects, mentioned above.
Sorry for long post, thanks in advance.
(Btw if u have better ideas, more compact or better, fire away, nothing is set in stone!)
You can use defunkt’s pjax.
You will need to implement a server-side component that send you only the content of the page, without all the menus and stuff. Then it’ll work.
Sample code
Not fully tested, please comment whether or not it works. To test it, make sure it’s done over HTTP (not
file://) – at least when using Chrome.Check the jsFiddle example with a fake request and alerts showing triggered events.
In
index.htmlIn
news.html(should check for pjax to enable/disable menus)In your
pjax-fade-click.jsThen create all your html pages as you normally would, but don’t show menus when you receive the header
'X-PJAX'or querystring_pjax=true.javascript pjax
Edit 1
Didn’t double check the pjax version on the pjax demo site – turns out it was old. Now using the raw version of
jquery.pjax.jsstraight from github, but it should be loaded from somewhere else. Also added the jsfiddle.