Last active
July 23, 2020 06:35
-
-
Save Inontran/67a77e999af27572f698ea1fd0ae99aa to your computer and use it in GitHub Desktop.
lazyload каруселей
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 lazy_owl(){ | |
| var wh = $(window).height(); | |
| var scrollTop_body = $('html, body').scrollTop() || $(document).scrollTop() || $(window).scrollTop(); | |
| $('.carousel.carousel_lazyload', 'body').each(function(){ | |
| var current_carousel = $(this); | |
| if( !current_carousel.hasClass('owl-loaded') && !current_carousel.find('.owl-loaded').length ) | |
| { | |
| if( (current_carousel.hasClass('owl-carousel') && current_carousel.parent().is(':visible')) ) | |
| { | |
| if( current_carousel.parent().offset().top <= scrollTop_body + (wh + 200) ) | |
| { | |
| // console.log( current_carousel.offset().top + ' ' + current_carousel.attr('class') ); | |
| current_carousel.owlCarouselStart(); | |
| } | |
| } else if( (!current_carousel.hasClass('owl-carousel') && current_carousel.is(':visible')) ){ | |
| if( current_carousel.offset().top <= scrollTop_body + (wh + 200) ) | |
| { | |
| // console.log( current_carousel.offset().top + ' ' + current_carousel.attr('class') ); | |
| current_carousel.owlCarouselStart(); | |
| } | |
| } | |
| } | |
| }); | |
| // console.log('===================='); | |
| }; | |
| lazy_owl(); | |
| var timer_lazy_owl = null; | |
| $(window).scroll(function(){ | |
| if(timer_lazy_owl !== null) { | |
| clearTimeout(timer_lazy_owl); | |
| } | |
| timer_lazy_owl = setTimeout(function() { | |
| lazy_owl(); | |
| }, 150); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment