How to access Flexslider instance?
-
Some time ago, I added to following code to one of my themes to be able to control the Flexslider slider added by WooCommerce to product galleries. It was working with no problems, but recently I’m getting an “Uncaught TypeError: “slider” is undefined” when triggering the “click” events added by my script.
( function( $ ) { $( function() { var slider = $( '.woocommerce-product-gallery' ).data( 'flexslider' ); console.log( $( '.woocommerce-product-gallery' ) ); // The class exists. $( '.woocommerce-product-gallery__image' ).on( 'click', function( e ) { e.preventDefault(); var x = e.pageX - $( this ).offset().left; var width = $( this ).width(); if ( x < width / 2 ) { slider.flexAnimate( slider.getTarget( 'prev' ) ); } else { slider.flexAnimate( slider.getTarget( 'next' ) ); } }); $( '.woocommerce-product-gallery-slider-nav .slider-prev' ).on( 'click', function( e ) { e.preventDefault(); slider.flexAnimate( slider.getTarget( 'prev' ) ); }); $( '.woocommerce-product-gallery-slider-nav .slider-next' ).on( 'click', function( e ) { e.preventDefault(); slider.flexAnimate( slider.getTarget( 'next' ) ); }); }); } )( jQuery );
Has something changed in the Flexslider code shipped with WooCommerce? How can I get the Flexslider instance to be able to attach events to it now?
Any help would be appreciated?
Viewing 7 replies - 1 through 7 (of 7 total)
Viewing 7 replies - 1 through 7 (of 7 total)
- The topic ‘How to access Flexslider instance?’ is closed to new replies.