Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 10th, 2012  |  syntax: None  |  size: 1.58 KB  |  hits: 2  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Ajax: fade in new content only if its fully loaded
  2. $(function(){
  3.     var replacePage = function(url) {
  4.  
  5.         $.ajax({
  6.             url: url,
  7.             type: 'get',
  8.             dataType: 'html',
  9.             beforeSend: function() {    
  10.                 $(".menue").slideUp();
  11.             },
  12.             success: function(data){
  13.                 var dom = $(data);
  14.                 var html = dom.filter('#content').html();
  15.  
  16.                 $('#content').html(html);
  17.  
  18.             },
  19.             complete: function(){
  20.                 $("#content").fadeIn();
  21.             }
  22.         });
  23.     }
  24.  
  25.     $('nav a').live('click', function(e){
  26.         history.pushState(null, null, this.href);  
  27.         replacePage(this.href);
  28.         e.preventDefault();
  29.     $("#content").hide();
  30.     });
  31.  
  32.     $(window).bind('popstate', function(){
  33.         replacePage(location.pathname);
  34.     });
  35. });
  36.        
  37. success: function(data){
  38.            var dom = $(data);
  39.            var html = dom.filter('#content').html();
  40.            $(".menue").promise().done(function(){
  41.                 $('#content').html(html).fadeIn()
  42.            })
  43.         },
  44.        
  45. $(".menue").slideUp('slow', function(){
  46.     $.ajax({
  47.         url: url,
  48.         type: 'get',
  49.         dataType: 'html',
  50.         success: function(data){
  51.             var dom = $(data);
  52.             var html = dom.filter('#content').html();
  53.             $('#content').html(html).fadeIn()
  54.         }
  55.     });
  56.  })
  57.        
  58. success: function(data){
  59.                 var dom = $(data);
  60.                 var html = dom.filter('#content').html();
  61.                 $('#content').html(html).hide().fadeIn();
  62.             },