site.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. var $cards = $('#items .full-works');
  2. var $card = $('#items .card');
  3. var $cat = $('.cat-list .cat a');
  4. var $img = $('.item #items .img');
  5. function masonry() {
  6. var $grid = $cards.masonry({
  7. itemSelector: '.card',
  8. columnWidth: '.card',
  9. percentPosition: true,
  10. transitionDuration: '0.2s'
  11. });
  12. var $grid2 = $img.masonry({
  13. itemSelector: '.img-card',
  14. columnWidth: '.img-card',
  15. percentPosition: true,
  16. gutter: 20,
  17. transitionDuration: '0.2s'
  18. });
  19. $grid.imagesLoaded().progress( function() {
  20. $grid.masonry();
  21. });
  22. $grid2.imagesLoaded().progress( function() {
  23. $grid2.masonry();
  24. });
  25. }
  26. function contact() {
  27. var $contact = $('header .contact');
  28. $contact.on('click',function() {
  29. if ($(this).hasClass('open')) {
  30. $(this).removeClass('open');
  31. $(this).addClass('close');
  32. } else {
  33. $(this).addClass('open');
  34. $(this).removeClass('close');
  35. }
  36. })
  37. }
  38. function scroll() {
  39. // left: 37, up: 38, right: 39, down: 40,
  40. // spacebar: 32, pageup: 33, pagedown: 34, end: 35, home: 36
  41. if ($('#page-wrapper.blog').length > 0){
  42. $(window).bind('mousewheel DOMMouseScroll', function(event){
  43. var $height = $(window).scrollTop();
  44. var $heightW = $(window).height();
  45. var wh = $heightW - $height;
  46. var keys = {32: 1, 37: 1, 38: 1, 39: 1, 40: 1};
  47. function preventDefault(e) {
  48. e = e || window.event;
  49. if (e.preventDefault)
  50. e.preventDefault();
  51. e.returnValue = false;
  52. }
  53. function preventDefaultForScrollKeys(e) {
  54. if (keys[e.keyCode]) {
  55. preventDefault(e);
  56. return false;
  57. }
  58. }
  59. function disablescroll() {
  60. if (window.addEventListener) // older FF
  61. window.addEventListener('DOMMouseScroll', preventDefault, false);
  62. window.onwheel = preventDefault; // modern standard
  63. window.onmousewheel = document.onmousewheel = preventDefault; // older browsers, IE
  64. window.ontouchmove = preventDefault; // mobile
  65. document.ontouchmove = function(e) {
  66. var target = e.currentTarget;
  67. while(target) {
  68. if(checkIfElementShouldScroll(target))
  69. return;
  70. target = target.parentNode;
  71. }
  72. e.preventDefault();
  73. };
  74. document.onkeydown = preventDefaultForScrollKeys;
  75. }
  76. function enableScroll() {
  77. if (window.removeEventListener)
  78. window.removeEventListener('DOMMouseScroll', preventDefault, false);
  79. window.onmousewheel = document.onmousewheel = null;
  80. window.onwheel = null;
  81. window.ontouchmove = null;
  82. document.onkeydown = null;
  83. var aTag = $("#start");
  84. $('html,body').animate({scrollTop: aTag.offset().top},'slow');
  85. }
  86. if (event.originalEvent.wheelDelta > 0 || event.originalEvent.detail < 0) {
  87. if (wh > 0) {
  88. console.log('up');
  89. $('.blog header').removeClass('hide');
  90. $('.blog #start').removeClass('visible');
  91. // disablescroll();
  92. // setTimeout(enableScroll, 500);
  93. $('.blog #start #items').removeClass('fixed');
  94. }
  95. }else {
  96. if (wh > 0) {
  97. console.log('down');
  98. $('.blog header').addClass('hide');
  99. $('.blog #start').addClass('visible');
  100. disablescroll();
  101. setTimeout(enableScroll, 500);
  102. $('.blog #start #items').addClass('fixed');
  103. }
  104. }
  105. });
  106. }
  107. }
  108. jQuery(document).ready(function($){
  109. masonry();
  110. contact();
  111. scroll();
  112. $(window).load(function(){
  113. $('html, body').scrollTop(0);
  114. });
  115. });