Community Forums › Forums › Archived Forums › General Discussion › Modern Portfolio Pro – Scrolling
Tagged: Modern Portfolio Pro, scroll
- This topic has 7 replies, 2 voices, and was last updated 8 years, 11 months ago by
pagerank.
-
AuthorPosts
-
April 10, 2016 at 12:00 pm #183286
pagerank
ParticipantI am using Modern Portfolio Pro. I have added the smooth scrolling capability to a page by adding the following
<script type='text/javascript' src='/wp-content/themes/modern-portfolio-pro/js/jquery.scrollTo.min.js?ver=1f5377270e80de4af718712f3afaf586-beta'></script> <script type='text/javascript' src='/wp-content/themes/modern-portfolio-pro/js/jquery.localScroll.min.js?ver=1f5377270e80de4af718712f3afaf586b'></script> <script type='text/javascript' src='/wp-content/themes/modern-portfolio-pro/js/scroll.js?ver=1f5377270e80de4af718712f3afaf586'></script> <script type='text/javascript' src='/wp-includes/js/wp-embed.min.js?ver=1f5377270e80de4af718712f3afaf586'></script>
It works fine when viewed on a desktop screen. However, when viewing the page on a tablet, it scrolls down to the section ID, and then it bounces back up part way. Is there a way to fix this? Or, is it possible to enqueue these scripts only when the desktop screen is being used?
Thanks,
ChrisApril 10, 2016 at 12:04 pm #183290Christoph
MemberHi Chris,
you can enqueue the scripts conditionally with wp_is_mobile()
https://codex.wordpress.org/Function_Reference/wp_is_mobileIf you need more control, you could use a plugin called Mobble.
April 10, 2016 at 12:24 pm #183293pagerank
ParticipantHi Christoph,
Thanks for that! For my situation (only enqueue for desktop), would I need to use wp_dequeue_script to remove the scripts from mobile?
Chris
April 10, 2016 at 12:27 pm #183294Christoph
MemberHi Chris,
you are welcome.
No, you would only enqueue the scripts if it´s not mobile.
if (! wp_is_mobile) {
...
}
April 10, 2016 at 12:35 pm #183295pagerank
ParticipantPalm to forehead ... Thanks 🙂
April 10, 2016 at 12:45 pm #183296pagerank
ParticipantMy palm is still beating my forehead ...
Could you please have a look at the following code and let me know where I'm going wrong?
if ( !wp_is_mobile() && is_page(507) ) { function wpdocs_theme_name_scripts() { wp_enqueue_script( 'custom-script', '/wp-content/themes/modern-portfolio-pro/js/jquery.scrollTo.min.js?ver=1f5377270e80de4af718712f3afaf586-beta', array( 'jquery' ) ); wp_enqueue_script( 'custom-script', '/wp-content/themes/modern-portfolio-pro/js/jquery.localScroll.min.js?ver=1f5377270e80de4af718712f3afaf586b', array( 'jquery' ) ); wp_enqueue_script( 'custom-script', '/wp-content/themes/modern-portfolio-pro/js/scroll.js?ver=1f5377270e80de4af718712f3afaf586', array( 'jquery' ) ); wp_enqueue_script( 'custom-script', '/wp-includes/js/wp-embed.min.js?ver=1f5377270e80de4af718712f3afaf586', array( 'jquery' ) ); } add_action( 'wp_enqueue_scripts', 'wpdocs_theme_name_scripts' );
I have tried removing
, array('jquery')
'custom-script',
Neither worked. As you can see, I'm not a coder, just a tinkerer. Any help would be greatly appreciated.
ChrisApril 10, 2016 at 2:03 pm #183305Christoph
MemberHi,
I haven't tested the code but this looks better:
function wpdocs_theme_name_scripts() { if ( !wp_is_mobile() && is_page(507) ) { wp_enqueue_script( 'custom-script', '/wp-content/themes/modern-portfolio-pro/js/jquery.scrollTo.min.js?ver=1f5377270e80de4af718712f3afaf586-beta', array( 'jquery' ) ); wp_enqueue_script( 'custom-script', '/wp-content/themes/modern-portfolio-pro/js/jquery.localScroll.min.js?ver=1f5377270e80de4af718712f3afaf586b', array( 'jquery' ) ); wp_enqueue_script( 'custom-script', '/wp-content/themes/modern-portfolio-pro/js/scroll.js?ver=1f5377270e80de4af718712f3afaf586', array( 'jquery' ) ); wp_enqueue_script( 'custom-script', '/wp-includes/js/wp-embed.min.js?ver=1f5377270e80de4af718712f3afaf586', array( 'jquery' ) ); } } add_action( 'wp_enqueue_scripts', 'wpdocs_theme_name_scripts' );
April 10, 2016 at 3:04 pm #183310pagerank
ParticipantThanks again for your help! I eventually figured out how to do it a) using Genesis Extender and b) installing the plugin "Mobble" provided at the bottom of the WordPress.org link you sent me. Here's the direct link if anyone else needs it - https://github.com/scottsweb/mobble
Thanks again!
-
AuthorPosts
- The forum ‘General Discussion’ is closed to new topics and replies.