Files
gilles-acezat/user/themes/gilles_acezat/js/site.js
T
2019-02-22 23:38:16 +01:00

132 lines
3.5 KiB
JavaScript

var $cards = $('#items .full-works');
var $card = $('#items .card');
var $cat = $('.cat-list .cat a');
var $img = $('.item #items .img');
function masonry() {
var $grid = $cards.masonry({
itemSelector: '.card',
columnWidth: '.card',
percentPosition: true,
transitionDuration: '0.2s'
});
var $grid2 = $img.masonry({
itemSelector: '.img-card',
columnWidth: '.img-card',
percentPosition: true,
gutter: 20,
transitionDuration: '0.2s'
});
$grid.imagesLoaded().progress( function() {
$grid.masonry();
});
$grid2.imagesLoaded().progress( function() {
$grid2.masonry();
});
}
function contact() {
var $contact = $('header .contact');
$contact.on('click',function() {
if ($(this).hasClass('open')) {
$(this).removeClass('open');
$(this).addClass('close');
} else {
$(this).addClass('open');
$(this).removeClass('close');
}
})
}
function scroll() {
// left: 37, up: 38, right: 39, down: 40,
// spacebar: 32, pageup: 33, pagedown: 34, end: 35, home: 36
if ($('#page-wrapper.blog').length > 0){
$(window).bind('mousewheel DOMMouseScroll', function(event){
var $height = $(window).scrollTop();
var $heightW = $(window).height();
var wh = $heightW - $height;
var keys = {32: 1, 37: 1, 38: 1, 39: 1, 40: 1};
function preventDefault(e) {
e = e || window.event;
if (e.preventDefault)
e.preventDefault();
e.returnValue = false;
}
function preventDefaultForScrollKeys(e) {
if (keys[e.keyCode]) {
preventDefault(e);
return false;
}
}
function disablescroll() {
if (window.addEventListener) // older FF
window.addEventListener('DOMMouseScroll', preventDefault, false);
window.onwheel = preventDefault; // modern standard
window.onmousewheel = document.onmousewheel = preventDefault; // older browsers, IE
window.ontouchmove = preventDefault; // mobile
document.ontouchmove = function(e) {
var target = e.currentTarget;
while(target) {
if(checkIfElementShouldScroll(target))
return;
target = target.parentNode;
}
e.preventDefault();
};
document.onkeydown = preventDefaultForScrollKeys;
}
function enableScroll() {
if (window.removeEventListener)
window.removeEventListener('DOMMouseScroll', preventDefault, false);
window.onmousewheel = document.onmousewheel = null;
window.onwheel = null;
window.ontouchmove = null;
document.onkeydown = null;
var aTag = $("#start");
$('html,body').animate({scrollTop: aTag.offset().top},'slow');
}
if (event.originalEvent.wheelDelta > 0 || event.originalEvent.detail < 0) {
if (wh > 0) {
console.log('up');
$('.blog header').removeClass('hide');
$('.blog #start').removeClass('visible');
// disablescroll();
// setTimeout(enableScroll, 500);
$('.blog #start #items').removeClass('fixed');
}
}else {
if (wh > 0) {
console.log('down');
$('.blog header').addClass('hide');
$('.blog #start').addClass('visible');
disablescroll();
setTimeout(enableScroll, 500);
$('.blog #start #items').addClass('fixed');
}
}
});
}
}
jQuery(document).ready(function($){
masonry();
contact();
scroll();
$(window).load(function(){
$('html, body').scrollTop(0);
});
});