Advertisement
Guest User

Untitled

a guest
Jul 13th, 2014
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.78 KB | None | 0 0
  1. $(function() {
  2.  
  3. var setTitle = function(title, href) {
  4. title = 'Derp: ' + title;
  5. href = href || '';
  6.  
  7. history.pushState({id: href}, title, href.replace('#', '/'));
  8. document.title = title;
  9. },
  10. scroll = function(url, speed) {
  11.  
  12. var href = typeof url == 'string' ? url : $(this).attr('href'),
  13. target = $(href),
  14. offset = target.offset(),
  15. title = target.find('h1').text();
  16.  
  17. if(typeof url == 'number') {
  18. target = [{id:''}];
  19. offset = {top: url};
  20. }
  21.  
  22. // And move the element
  23. if(offset.top) {
  24. // Set the new URL and title
  25. setTitle(title, href);
  26.  
  27. // Make sure we're not moving the contact panel
  28. if(target[0].id != 'contact') {
  29. $('html, body').animate({scrollTop: offset.top}, speed);
  30. }
  31. }
  32.  
  33. return false;
  34. };
  35.  
  36. // Handle existing URL fragments on load
  37. if(location.pathname.length > 1) {
  38. scroll(location.pathname.replace('/', '#'), 0);
  39. }
  40.  
  41. $('a#logo').click(function() {
  42. $('html,body').animate({scrollTop: 0});
  43. return false;
  44. });
  45.  
  46. // Handle internal link clicks
  47. $('a[href^=#]:not(#logo)').click(scroll);
  48.  
  49.  
  50. // Close the "Get In Touch" box
  51. var box = $('#contact'),
  52. moveBox = function() {
  53. var closing = $(this).attr('class') == 'close',
  54. amount = closing ? -(box.height() + 20) : 0,
  55. cb = closing ? '' : function() { box.animate({marginTop: -10}, 150); };
  56.  
  57. box.animate({marginTop: amount}, cb);
  58. };
  59.  
  60. box.css('margin-top', -(box.height() + 20));
  61. $('#contact a.close, #get-in-touch').click(moveBox);
  62.  
  63.  
  64. // Nasty little fix for vertical centering
  65. $('.vertical').each(function() {
  66. $(this).css('margin-top', -($(this).height() / 2));
  67. });
  68.  
  69.  
  70. // Work panels
  71. var parent = $('#work'),
  72. panels = parent.children('div');
  73.  
  74. panels.each(function() {
  75. $(this).css('width', 100 / panels.length + '%');
  76. })
  77.  
  78. parent.css('width', (panels.length * 100) + '%');
  79.  
  80.  
  81. // Bind the keyboards
  82. $(document).keyup(function(e) {
  83. var actions = {
  84. // Left
  85. 37: function() {
  86. var prev = panels.filter('.active').prev().not('small');
  87.  
  88. if(prev.length > 0) {
  89. prev.siblings().removeClass('active');
  90.  
  91. setTitle(prev.find('h1').text(), prev[0].id);
  92.  
  93. setTimeout(function() {
  94. prev.addClass('active');
  95. }, 250);
  96.  
  97. parent.animate({left: '+=100%'}).css('background-color', '#' + prev.attr('data-background'));
  98. }
  99. },
  100.  
  101. // Right
  102. 39: function() {
  103. var next = panels.filter('.active').next();
  104.  
  105. if(next.length > 0) {
  106. next.siblings().removeClass('active');
  107.  
  108. setTitle(next.find('h1').text(), next[0].id);
  109.  
  110. setTimeout(function() {
  111. next.addClass('active');
  112. }, 250);
  113.  
  114. parent.animate({left: '-=100%'}).css('background-color', '#' + next.attr('data-background'));
  115. }
  116. },
  117.  
  118. // Down
  119. 40: function() {
  120. var w = $(window),
  121. height = w.height() * panels.children('div').length,
  122. h = w.height() + w.scrollTop();
  123.  
  124. if(h < height) {
  125. scroll(h);
  126. }
  127. },
  128.  
  129. // Up
  130. 38: function() {
  131. var w = $(window);
  132. $('html,body').animate({scrollTop: w.scrollTop() - w.height()});
  133. }
  134. };
  135.  
  136. // Call a function based on keycode
  137. if(actions[e.which]) {
  138. actions[e.which]();
  139. }
  140.  
  141. e.preventDefault();
  142. return false;
  143. });
  144.  
  145.  
  146. // Fix crazy resize bugs
  147. $(window).resize(function() {
  148.  
  149. var m = $(this),
  150. h = m.height(),
  151. s = m.scrollTop();
  152.  
  153. if((h - s) < (h / 2)) {
  154. m.scrollTop(h);
  155. }
  156.  
  157. //$('html,body').animate({scrollTop: s});
  158. });
  159.  
  160.  
  161. // slideshow
  162. var woof = function() {
  163. var slides = $('#molly li'),
  164. active = slides.filter('.active');
  165.  
  166. if(!active.length) {
  167. active = slides.last();
  168. }
  169.  
  170. active.addClass('active');
  171.  
  172. var next = active.next().length ? active.next() : slides.first();
  173.  
  174. next.css('opacity', 0).addClass('active').animate({opacity: 1}, function() {
  175. active.removeClass('active last-active');
  176. });
  177. };
  178.  
  179. setInterval(woof, 3000);
  180.  
  181.  
  182. // easing
  183. $.easing.swing = function(v,i,s,u,a,l) {
  184. if((i /= a / 2) < 1) {
  185. return u / 2 * (Math.pow(i, 3)) + s;
  186. }
  187.  
  188. return u / 2 * ((i -= 2) * i * i + 2) + s;
  189. };
  190.  
  191. // Change the default .animate() time: http://forr.st/~PG0
  192. $.fx.speeds._default = 600;
  193.  
  194. // And move the element
  195. if(offset.top) {
  196.  
  197. var href = typeof url == 'string' ? url : $(this).attr('href'),
  198. target = $(href), //line 2
  199. offset = target.offset(), //line 3
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement