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

Untitled

By: a guest on May 2nd, 2012  |  syntax: None  |  size: 0.99 KB  |  hits: 15  |  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. Jquery event capture change in margin-left
  2. <nav id="servicos_nav">
  3.     <div id="full">
  4.         ...
  5.     </div>
  6.     <div id="minimized">
  7.         ...
  8.     </div>
  9. </nav>
  10. <section id="content">
  11. … PHP generated code …
  12. </section>
  13.        
  14. window.onresize = function(event) {
  15.         if(window.innerWidth <= 1142)
  16.         {
  17.             $("#content").css("margin-left","140px");
  18.         }
  19.         else
  20.         {
  21.             $("#content").removeAttr("style");
  22.         }
  23.     };
  24.        
  25. var contentWidth = $('#content').width();
  26. var leftWidth = $('#left').width();
  27.  
  28. $(window).resize = function(event) {
  29.     var windowWidth = window.innerWidth;
  30.     if (windowWidth <= (contentWidth + (leftWidth * 2)) {
  31.         $('#content').css('margin-left', leftWidth);
  32.     } else {
  33.         $('#content').css('margin-left', 'auto')
  34.     }
  35. }
  36.        
  37. $(window).resize = function(event) {
  38.    if ($('#content').offset().left < leftWidth) {
  39.      $('#content').css('margin-left', leftWidth);
  40.    } else {
  41.      $('#content').css('margin-left', 'auto')
  42.    }
  43. }