Save
This commit is contained in:
23
wp-content/themes/hello-elementor/assets/js/custom.js
Normal file
23
wp-content/themes/hello-elementor/assets/js/custom.js
Normal file
@@ -0,0 +1,23 @@
|
||||
jQuery(function ($) {
|
||||
$(window).on('scroll', function () {
|
||||
$('.parallax-box').each(function () {
|
||||
var box = $(this)
|
||||
var img = box.find('.parallax-box-img')
|
||||
|
||||
var boxTop = box.offset().top
|
||||
var boxHeight = box.outerHeight()
|
||||
var scrollTop = $(window).scrollTop()
|
||||
var windowHeight = $(window).height()
|
||||
|
||||
if (scrollTop + windowHeight > boxTop && scrollTop < boxTop + boxHeight) {
|
||||
var percentSeen =
|
||||
(scrollTop + windowHeight - boxTop) / (windowHeight + boxHeight)
|
||||
percentSeen = Math.min(Math.max(percentSeen, 0), 1)
|
||||
|
||||
var translateY = (percentSeen - 0.5) * 400
|
||||
|
||||
img.css('transform', 'translateY(' + translateY + 'px)')
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user