- This topic has 9 replies, 3 voices, and was last updated 6 years, 1 month ago by Tom.
-
AuthorPosts
-
March 21, 2018 at 9:14 am #525551geco
Hello,
I would like to add this animation “.animate({scrollTop:”20″},1000, ‘swing’);” of js in this code:
add_filter( ‘generate_back_to_top_scroll_speed’, ‘tu_back_to_top_scroll_speed’ );
function tu_back_to_top_scroll_speed() {
return 700; // milliseconds
}can someone help me implement it?
Thanks
SergioMarch 21, 2018 at 5:09 pm #525841LeoStaffCustomer SupportHi there,
One of the methods here should do: https://docs.generatepress.com/article/adding-php/
Code Snippets is the easiest if you aren’t using a child theme.
March 22, 2018 at 2:16 am #526137gecoHi leo!
I think he expresses me wrong, sorry for my English.
What I want is to include this code: .animate ({scrollTop: “20”}, 1000, ‘swing’); with which I show here below:
add_filter (‘generate_back_to_top_scroll_speed’, ‘tu_back_to_top_scroll_speed’);
function tu_back_to_top_scroll_speed () {
return 700;
}This does not work for me:
add_filter (‘generate_back_to_top_scroll_speed’, ‘tu_back_to_top_scroll_speed’);
function tu_back_to_top_scroll_speed () {
return 700;
.animate ({scrollTop: “20”}, 1000, ‘swing’);
}Thanks
SergioMarch 22, 2018 at 10:24 am #526582TomLead DeveloperLead DeveloperHi there,
Unfortunately that’s not possible with the way our button is set up, as it’s not using jQuery.
You could remove our javascript:
add_action( 'wp_enqueue_scripts', 'tu_remove_back_to_top', 20 ); function tu_remove_back_to_top() { wp_dequeue_script( 'generate-back-to-top' ); }
Then you can add your own javascript in the wp_footer hook (for example):
<script> jQuery( document ).ready( function($) { $( '.generate-back-to-top' ).on( 'click', function() { $( 'html, body' ).animate ({scrollTop: "20"}, 1000, 'swing'); } ); } ); </script>
Totally untested, but should get you started.
March 23, 2018 at 10:42 am #528262gecoHello Tom,
I have added the two codes that you have given me, but the result is not as expected: http://sergioratia.com/tienda-online/. When you click on back to top it behaves strangely.
In version 1.4 of GP if I could add it optimally. You used this code below and I just had to add the final line:
jQuery( document ).ready( function($) { var _amountScrolled = $( '.generate-back-to-top' ).data( 'start-scroll' ), _scrollSpeed = $( '.generate-back-to-top' ).data( 'scroll-speed' ), _button = $( 'a.generate-back-to-top' ), _window = $( window ); _window.scroll(function() { if ( _window.scrollTop() > _amountScrolled ) { $( _button ).css({ 'opacity': '1', 'visibility': 'visible' }); } else { $( _button ).css({ 'opacity': '0', 'visibility' : 'hidden' }); } }); $( _button ).on( 'click', function( e ) { e.preventDefault(); $("html, body").animate({scrollTop:"20"},1000, 'swing'); }); });
March 23, 2018 at 8:40 pm #528794TomLead DeveloperLead DeveloperThat exact code should still work fine, as long as the current script is removed. The original script is still on your page – maybe try clearing your caching plugin?
March 26, 2018 at 3:16 am #530811gecoHello Tom,
I have inserted the code that you have passed to deactivate the javascript with Snippets, is it the correct way to deactivate javascript?
Thanks
SergioMarch 26, 2018 at 9:26 am #531284TomLead DeveloperLead DeveloperYes – I just adjusted it a bit to ensure it fires after the theme adds it, just in case.
March 26, 2018 at 10:52 am #531419gecoNow it worked Tom! Thank you ๐
March 26, 2018 at 10:43 pm #531970TomLead DeveloperLead DeveloperYou’re welcome! ๐
-
AuthorPosts
- You must be logged in to reply to this topic.