Go top smooth function
-
I have a problem that I write the following code in the functions.php to realize the page go top.
It works.but just work for the user fist visit the page and click the button for first time.
I must refresh the page let the function work.
Did I miss something?
function back_and_top( $content ) { if( is_front_page() || is_home() ) { return $content; } $custom_content .= '<div class="back_and_top"> <a class="top_btn" href="javascript:const scrollToTop = () => { const c = document.documentElement.scrollTop || document.body.scrollTop; if (c > 0) { window.requestAnimationFrame(scrollToTop); window.scrollTo(0, c - c / 8); } }; scrollToTop();" title="go top"><i class="fa fa-sort" aria-hidden="true"></i>Go Top</a> </div>'; $content .= $custom_content; return $content; } add_filter( 'the_content', 'back_and_top' );
Viewing 6 replies - 1 through 6 (of 6 total)
Viewing 6 replies - 1 through 6 (of 6 total)
The topic ‘Go top smooth function’ is closed to new replies.