Support Forums for LiveMesh Themes & Plugins › Forums › Agile Theme Support › How to scroll down to an internal anchor?
- This topic has 15 replies, 3 voices, and was last updated 10 years, 2 months ago by Raghavendra.
-
AuthorPosts
-
February 7, 2014 at 6:27 pm #4286jhodgskiMember
In my main navigation menu on my home page, I have a link with href=”http://localhost/mwe2014/#contact” and when I click it, the page scrolls down nicely to the Contact area.
In the content of my home page, I’ve added another like to the Contact area, but when I create a link with href=”http://localhost/mwe2014/#contact”, it doesn’t scroll there but jumps (and actually jumps a bit too far down). How can I make the behaviour here the same as for the main nav links?
Also, when you click a link in the main nav and the site scrolls down nicely, if you then click the ‘Home’ link, it doesn’t scroll back up but the page is reloaded. (This happens in the demo at https://www.livemeshthemes.com/agile/ as well.) Can this be changed so it scrolls back up instead?
Thanks,
JamesFebruary 7, 2014 at 6:38 pm #4288RaghavendraModeratorFor links to function like menu items, will need some additional Javascript code for the same. Will send the same out tonight.
For making the Home jump to the Home button, you will need to set the URL as something like http://localhost/mwe2014/#header so that it jumps within the page and is also navigable from external pages.
February 7, 2014 at 8:02 pm #4294jhodgskiMemberhttp://localhost/mwe2014/#header didn’t work, but http://localhost/mwe2014/#container did. 🙂
Look forward to receiving the new JS code. Thanks.
February 11, 2014 at 6:07 am #4357RaghavendraModeratorFor the JS solution, I found a topic which addresses this already. Pls have a look here –
February 11, 2014 at 11:22 am #4368jhodgskiMemberThanks. I have now added…
$('a[href*=#]').smoothScroll();
…to the bottom of Agile’s js\main.js file, and have added…
<a href="#footer" rel="nofollow">smooth scroll to footer</a>
…to my page, but when I click the link it still jumps there rather than smooth scrolls. Can you advise?Also, is there an upgrade-safe way of implementing the solution? (I am using agile-child.)
Cheers,
JamesFebruary 11, 2014 at 3:07 pm #4379RaghavendraModeratorCan you pls post as private reply a temp login to the site? I can give a try. Works for me in my installation. Hope there is no script error.
February 11, 2014 at 10:50 pm #4388jhodgskiMemberThis reply has been marked as private.February 12, 2014 at 1:13 am #4392RaghavendraModeratorWorks fine now. Just had to insert it inside a document ready or window load function. Pls check. Will get back to you with the code for the child theme.
February 13, 2014 at 10:55 am #4424jhodgskiMemberIt worked, but it broke the filterable portfolio functionality.
February 13, 2014 at 12:03 pm #4436NexusModeratorLooks like you are making some changes right now to your site. I will get back to the issue when you are done. Thanks!
February 13, 2014 at 12:12 pm #4437RaghavendraModeratorTo stay safe, it is best to prefix the above code with the element to which your internal links belong to. Like below –
$('#services-section a[href*=#]').smoothScroll();
Pls replace #services-section with the element id of your own. You can place multiple such statements to target multiple div elements containing internal links. This way the portfolio section is not affected.
February 13, 2014 at 2:04 pm #4453jhodgskiMemberCheers. I’ve looked at the other solution page, and I prefer this solution…
<a class="smooth-scroll-link" href="#footer" rel="nofollow">Scroll smoothly to footer</a>
…with the JS code being…
$('.smooth-scroll-link').smoothScroll();
…just in case that helps anyone.
February 13, 2014 at 2:06 pm #4454jhodgskiMemberHow do I implement that line of JS code in an upgrade-proof way though?
February 14, 2014 at 1:08 pm #4479RaghavendraModeratorYou can just create a JS file of your own in the child theme and then have this piece of code in functions.php (make sure you have put your code in document ready function as in main.js file) –
add_action('wp_enqueue_scripts', 'mo_enqueue_scripts'); function mo_enqueue_scripts() { wp_enqueue_script('my-custom-js', get_stylesheet_directory() . '/js/my-custom.js', array('jquery'), false, true); }
Hope this works for you.
February 15, 2014 at 1:13 am #4492jhodgskiMemberThanks, but your code contained a couple of errors (white screen + 404).
Correct code for functions.php is:
/*
* Load my script
*/
function mo_enqueue_scripts() {
wp_enqueue_script(‘my-custom-js’, get_stylesheet_directory_uri() . ‘/js/my-custom.js’, array(‘jquery’), false, true);
}
add_action(‘wp_enqueue_scripts’, ‘mo_enqueue_scripts’);Correct code for my-custom.js:
jQuery(document).ready(function ($) {
$(‘.smooth-scroll’).smoothScroll();
}); -
AuthorPosts
- The topic ‘How to scroll down to an internal anchor?’ is closed to new replies.