EduardET

tabs scroll to tab content

Jan 23rd, 2018
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <script>
  2. ( function( $ ) {
  3.     $( document ).ready( function() {
  4.         if ( $( window ).width() < 768 ) {
  5.             var tabs = $( '.et_pb_tabs_0 .et_pb_tabs_controls li' ),
  6.                 contents = $( '.et_pb_tabs_0 .et_pb_all_tabs > div' ),
  7.                 tabLinks = $( '.et_pb_tabs_0 .et_pb_tabs_controls li a' );
  8.  
  9.             tabs.each( function() {
  10.                 var index = $( this ).index(),
  11.                     link = $( this ).find( 'a' );
  12.                 link.attr( 'href', '#wpc-tab' + index )
  13.             } );
  14.  
  15.             contents.each( function() {
  16.                 var index_content = $( this ).index();
  17.                 $( this ).attr( 'id', 'wpc-tab' + index_content );
  18.             } )
  19.  
  20.             tabLinks.each( function() {
  21.                 $( this ).click( function() {
  22.                     var elementToScroll = $( '.et_pb_tabs_0 .et_pb_all_tabs div' + $( this ).attr( "href" ) );
  23.                     setTimeout( function() {
  24.                         $( "html, body" ).animate( {
  25.                             scrollTop: elementToScroll.offset().top
  26.                         }, 500 );
  27.                     }, 800 )
  28.                 } )
  29.             } )
  30.         }
  31.     } );
  32. } )( jQuery );
  33. </script>
Advertisement
Add Comment
Please, Sign In to add comment