(function( $ ) { "use strict"; window.bt_bb_floating_icon_loop = function() { var win_w = window.innerWidth; var win_h = window.innerHeight; $( 'html:not(.bt_bb_touch) .bt_bb_floating_icon' ).each(function() { var elem = $(this).find('.bt_bb_floating_icon_icon'); var bounds = this.getBoundingClientRect(); if ( bounds.top < win_h && bounds.bottom > 0 ) { var speed = $(this).attr( 'data-speed' ) / 10; var ypos = ( bounds.top - win_h/2 ) * speed; if ( elem.data( 'direction' ) == 'left_right' ) { elem.css( 'transform', 'translateX(' + ypos + 'px)' ); } else if ( elem.data( 'direction' ) == 'rotate' ) { elem.css( 'transform', 'rotate(' + ypos + 'deg)' ); } else { elem.css( 'transform', 'translateY(' + ypos + 'px)' ); } } }); window.bt_bb_floating_icon_lock = false; } window.bt_bb_floating_icon_lock = false; $( window ).on( 'scroll', function() { if ( ! window.bt_bb_floating_icon_lock ) { window.bt_bb_floating_icon_lock = true; bt_bb_requestAnimFrame( bt_bb_floating_icon_loop ); // bt_bb_floating_icon_loop(); } }); bt_bb_requestAnimFrame( bt_bb_floating_icon_loop ); // bt_bb_floating_icon_loop(); $( window ).on( "load", function() { bt_bb_requestAnimFrame( bt_bb_floating_icon_loop ); $('#hero-slider .slick-slider').on('afterChange', function( event, slick, currentSlide, nextSlide ){ var min = 25; var max = 50; var dir = [ -1, 1 ]; $( this ).find('.slick-current .bt_bb_floating_icon_icon').each( function() { var p = min + Math.floor( Math.random() * ( max - min ) ); var d = dir[ Math.floor( Math.random() * dir.length ) ]; // var y = parseInt( $( this ).css('transform').split(',')[5] ); var y = 0; var ny = y + d * p; $( this ).css( 'transform', 'translateY(' + ny + 'px)' ); console.log('-- beforeChange --'); console.log($( this )); console.log(ny); }); //window.bt_bb_floating_icon_lock = true; //bt_bb_floating_icon_loop() }); }); })( jQuery );