techhjork

dynamicpage.js

Jul 3rd, 2020
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. // search this on * http://benalman.com/projects/jquery-hashchange-plugin/
  2. //jquery.ba-hashchange.min.js
  3.  
  4. $(function() {
  5.  
  6. var newHash = "",
  7. $mainContent = $("#main-content"),
  8. $pageWrap = $("#page-wrap"),
  9. baseHeight = 0,
  10. $el;
  11.  
  12. $pageWrap.height($pageWrap.height());
  13. baseHeight = $pageWrap.height() - $mainContent.height();
  14.  
  15. $("nav").delegate("a", "click", function() {
  16. window.location.hash = $(this).attr("href");
  17. return false;
  18. });
  19.  
  20. $(window).bind('hashchange', function(){
  21.  
  22. newHash = window.location.hash.substring(1);
  23.  
  24. if (newHash) {
  25. $mainContent
  26. .find("#guts")
  27. .fadeOut(200, function() {
  28. $mainContent.hide().load(newHash + " #guts", function() {
  29. $mainContent.fadeIn(200, function() {
  30. $pageWrap.animate({
  31. height: baseHeight + $mainContent.height() + "px"
  32. });
  33. });
  34. $("nav a").removeClass("current");
  35. $("nav a[href="+newHash+"]").addClass("current");
  36. });
  37. });
  38. };
  39.  
  40. });
  41.  
  42. $(window).trigger('hashchange');
  43.  
  44. });
Add Comment
Please, Sign In to add comment