Created
March 9, 2017 18:53
-
-
Save amirkhan81/6acd2afd7abc04715d6e216d3df236d3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(function(){ | |
var waypoints = $('.slide1').waypoint(function(direction) { | |
//cnsole.log(this); | |
$(this.element).find('div:first').addClass('slideIn'); | |
$(window).scroll(function() { | |
var windowHeight = window.innerHeight; | |
console.log(windowHeight + 'window height') | |
var x = $(this).scrollTop(); | |
console.log(x + 'scroll top'); | |
$('.slide1 > .slideIn > .scrollImage').css("transform", "translate(0px," + parseInt(-x / 2.6) + "px)").css('margin-bottom', parseInt(-x / 2.6) + "px"); | |
}); | |
}, { | |
offset: '100%' | |
}); | |
}); | |
$(window).scroll(function() { | |
var windowHeight = window.innerHeight; | |
console.log(windowHeight + 'window height 2') | |
var x = $(this).scrollTop() - windowHeight; | |
console.log(x + 'scroll top 2'); | |
$('.slide2.in-view .scrollImage').css("transform", "translate(0px," + parseInt(-x / 2.6) + "px)").css('margin-bottom', parseInt(-x / 2.6) + "px"); | |
}); | |
$(window).scroll(function() { | |
var windowHeight = window.innerHeight; | |
console.log(windowHeight + 'window height 2') | |
var x = $(this).scrollTop() - windowHeight; | |
console.log(x + 'scroll top 2'); | |
$('.slide3.in-view .scrollImage').css("transform", "translate(0px," + parseInt(-x / 2.6) + "px)").css('margin-bottom', parseInt(-x / 2.6) + "px"); | |
}); | |
var $animation_elements = $('.waypoint-slide-up'); | |
var $window = $(window); | |
function check_if_in_view() { | |
var window_height = $window.height(); | |
var window_top_position = $window.scrollTop(); | |
var window_bottom_position = (window_top_position + window_height); | |
$.each($animation_elements, function() { | |
var $element = $(this); | |
var element_height = $element.outerHeight(); | |
var element_top_position = $element.offset().top; | |
var element_bottom_position = (element_top_position + element_height); | |
//check to see if this current container is within viewport | |
if ((element_bottom_position >= window_top_position) && | |
(element_top_position <= window_bottom_position)) { | |
$element.addClass('in-view'); | |
} else { | |
$element.removeClass('in-view'); | |
} | |
}); | |
} | |
$window.on('scroll resize', check_if_in_view); | |
$window.trigger('scroll'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment