1

So I am developing this site from scratch (first time ever) and I've made the general layout from the psd I made and everything is great, so I am now at the point where I want to refine the site a bit with some javascript effects-functions.

When I am at the index page, you have a banner, sidebar and content (articles). When I press the articles it goes to the article (obviously) but I want to make a custom loading page like this at 0:22: https://www.youtube.com/watch?v=k1q6Y_snURw#t=20

I've got to make or find a gif but say I've done that, how would I add this to the site?

The articles are all in a class by themselves although I guess I would have to use the ID for each specific article to get it to go to the respective article.

Dmitry Evseev
  • 11,533
  • 3
  • 34
  • 48
  • This question is as is not a good fit at SO. Please read the guide lines here [help] - for some example code have a google for transitions, for example I googled for flyout jquery and found this http://ricostacruz.com/jquery.transit/ – mplungjan Oct 17 '14 at 12:49

2 Answers2

0

If i understand properly you want a smooth scrolling to the article. You can achieve this with using animate and scrollTop.

Is it possible to animate scrollTop with jQuery?

Now you need to select your article with a selector.

http://api.jquery.com/category/selectors/

Your saying that your article has is proper class. So the code will look like this :

$("sidebar").click(function () { 
    // "." is the selector for class and i assume the value of the sidebar match the class of article
    $("html, body").animate({ scrollTop: $("." + $(this).val()).position().top }); 
});

Hope this help.

Community
  • 1
  • 1
Mathieu Labrie Parent
  • 2,598
  • 1
  • 9
  • 10
0

EDIT: Pop this in a file and add a reference to it in every page that has a link:

function loadXMLDoc(name) {
  var xmlhttp = new XMLHttpRequest();
  xmlhttp.addEventListener("load", transferComplete, false);
  xmlhttp.open("GET", name, true);
  document.getElementById("Loading").style.display = "block";
  xmlhttp.send();

  function transferComplete() {
    document.write(xmlhttp.responseText);
    history.replaceState(null, null, name);
  }
}

function AJAXcallback(e) {
  var e = window.e || e;
  var href = e.target.getAttribute("href");
  if (e.target.tagName !== 'A' || href[0] == "#" || href.substring(0, 11).toUpperCase() == "JAVASCRIPT:" || e.target.class == "noloadpage")
    return;
  e.preventDefault();
  loadXMLDoc(href);
}
if (document.addEventListener)
  document.addEventListener('click', AJAXcallback, false);
else
  document.attachEvent('onclick', AJAXcallback);

And something to show when the next page is loading (be sure to add the id "Loading") like this:

<div id="Loading" style="display:none">Loading</div>

This makes every link that isn't an anchor(#id) or function(javascript:whatever) and doesn't have the "noloadpage" class load with AJAX and show the Loading div while loading.

DividedByZero
  • 4,333
  • 2
  • 19
  • 33
  • Ahh, okay, I was looking for some kind of a gif transition cause I've seen some pages start out with a loading page so I thought that might have been some kind of transition page or something. – Richard Lund Winther Oct 17 '14 at 20:55
  • @RichardLundWinther sorry I didn't get you, what do you mean by a transition page? – DividedByZero Oct 17 '14 at 21:04
  • Well, Let's say I'm on index which is page a and I wanna go to the link b then instead of the link going directly it would go through a page that says loading... or something like that. I'm not sure exactly how it works so I can't be any more specific! – Richard Lund Winther Oct 18 '14 at 16:12
  • @RichardLundWinther You could use AJAX but that's a bit hard to pull off for even experienced designers.. I will make a small demo page on js fiddle for you to study in a minute. – DividedByZero Oct 18 '14 at 17:28
  • Thanks man (woman, girl, boy) I'm not in a hurry, but if I at least have somebody to direct me I'll learn it sometime! – Richard Lund Winther Oct 18 '14 at 20:44
  • @RichardLundWinther I'm 14, so boy should be fine :P. I just noticed the absence of external resources on JsFiddle so I've uploaded the demo to this website: cryptolight.cf/test.html and it will be available in a few minutes. it basically loads another page without having to leave the first one (it replaces all the code in page 1 with page 2) and displays a loading page while that happens. btw: tell me when you've seen it – DividedByZero Oct 18 '14 at 21:35
  • Oh I see! I found another video showing how to do this, so with this I could basically make any gif with, let's say, after effects, and make it look like it's a transition! Hmm, "experiments I will be doing". Oh, and another question as I saw your site, on my site I have a header that stays at the same place all the time, how did you make it stay there while browsing through pages? I clicked on contact us, then back to home, and the header never reloaded, only the content. (If you get what I am saying.) – Richard Lund Winther Oct 19 '14 at 00:07
  • @RichardLundWinther No. the page you saw uses the gif as a loading indicator and it is nothing to do with the technical stuff. if you were to use the loading stuff without AJAX you would end up with a page that would purely waste the users time, since all of page 2 will have to be loaded after leaving the loading page.. – DividedByZero Oct 19 '14 at 13:12