script.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. jQuery(document).ready(function($) {
  2. //window scrolls check
  3. $(window).scroll(function() {
  4. var topOfWindow = $(window).scrollTop();
  5. // console.log('topOfWindow',topOfWindow);
  6. if (topOfWindow > 100) {
  7. $("#top-bar").addClass("reduced");
  8. }
  9. else {
  10. $("#top-bar").removeClass("reduced");
  11. }
  12. });
  13. // init categories content images behaviour
  14. // console.log($(window).width());
  15. if( $(window).width() > 600 && $('body').is('.home')){
  16. // init Isotope
  17. var $grid = $('.grid').isotope({
  18. itemSelector: '.grid-block',
  19. transitionDuration: '0.4s'
  20. });
  21. // $('.grid .grid-block')
  22. // .hide()
  23. // .imagesLoaded().progress( function( imgLoad, image ) {
  24. // // get item
  25. // // image is imagesLoaded class, not <img>, <img> is image.img
  26. // var $item = $( image.img ).parents('.grid-block');
  27. // // un-hide item
  28. // $item.show();
  29. // // isotope does its thing
  30. // $grid.appended( $item );
  31. // });
  32. $grid.imagesLoaded().progress(function(){
  33. $grid.isotope('layout');
  34. });
  35. // filter items on button click
  36. $('nav.categories a').on( 'click', function(e) {
  37. e.preventDefault();
  38. if($(this).is('.active')){
  39. location.hash = '';
  40. }else{
  41. var filterValue = $(this).attr('data-filter');
  42. location.hash = encodeURIComponent( filterValue );
  43. }
  44. return false;
  45. });
  46. function onHashchange() {
  47. var hashFilter = decodeURIComponent(location.hash.replace('#', ''));
  48. $('nav.categories a').removeClass('active');
  49. if ( !hashFilter ) {
  50. $grid.isotope({filter: '*'});
  51. }else{
  52. $('nav.categories a[data-filter='+hashFilter+']').addClass('active');
  53. $grid.isotope({filter: '.'+hashFilter});
  54. }
  55. }
  56. $(window).on( 'hashchange', onHashchange );
  57. onHashchange();
  58. }
  59. });