-
AuthorPosts
-
VariFrame Friend
VariFrame
- Join date:
- November 2015
- Posts:
- 76
- Downloads:
- 10
- Uploads:
- 1
- Thanks:
- 6
- Thanked:
- 3 times in 2 posts
September 20, 2017 at 3:03 pm #1063151Hey guys – I have one more problem here. I have an anchor menu and when you click its links it jumps fast to a destination. I would need it to smooth scroll there… I have noticed that back to top button has a smooth scrolling so there must be a jquerry code for it somewhere could you please help me with that? Thanks 🙂
Saguaros ModeratorSaguaros
- Join date:
- September 2014
- Posts:
- 31405
- Downloads:
- 237
- Uploads:
- 471
- Thanks:
- 845
- Thanked:
- 5346 times in 4964 posts
September 22, 2017 at 4:10 am #1063450Hi,
I will report to the team for further consideration on this.
Regards
VariFrame FriendVariFrame
- Join date:
- November 2015
- Posts:
- 76
- Downloads:
- 10
- Uploads:
- 1
- Thanks:
- 6
- Thanked:
- 3 times in 2 posts
November 16, 2017 at 4:41 pm #1074780Nice…so until we have this in JA Builder (would be wonderful to have something like next to Anchor function to have a button to enable or disable smooth scroll :-O) I resolved it like this. For anyone who needs smooth scrolling anchors:
1) Navigate to Extensions -> Click on templates
2)Click on JA Builder -> Custom code (it should work with any other template cause most of them use something like custom codes in template details)
3) Add this code to HEAD (shouldn’t make a difference if you use "top of head" or "bottom of head" code area… I have mine in bottom area):jQuery(document).ready(function ($) { $('a[href*="#"]') // Remove links that don't actually link to anything .not('[href="#"]') .not('[href="#0"]') .click(function(event) { // Grab height of fixed header var headHeight = $('header').outerHeight(); // On-page links if ( location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') && location.hostname == this.hostname ) { // Figure out element to scroll to var target = $(this.hash); target = target.length ? target : $('[name=' + this.hash.slice(1) + ']'); // Does a scroll target exist? if (target.length) { // Only prevent default if animation is actually gonna happen event.preventDefault(); $('html, body').animate({ scrollTop: target.offset().top - headHeight - 20 }, 1000, function() { // Callback after animation // Don't scroll on focus! $.fn.focusNoScroll = function(){ var x = window.scrollX, y = window.scrollY; this.focus(); window.scrollTo(x, y); return this; //chainability }; // Must change focus, but don't scroll! var $target = $(target); $target.focusNoScroll(); if ($target.is(":focus")) { // Checking if the target was focused return false; } else { $target.attr('tabindex','-1'); // Adding tabindex for elements not focusable $target.focusNoScroll(); // Set focus again }; }); } } }); });
And dont forget to add script (in angle brackets, no idea how to put it here cause the forum always changes it to code and doesnt show it here) to before and after the code itself!
From now on your anchors should have smooth scroll AND it also measures the height of your sticky menu and adjusts the scroll accordingly so that it doesn’t cover your headings…
EDIT:
This line:
jQuery(document).ready(function ($)
is only there for ppl using jquery easy or any other jquery no conflict plugins. If you dont use any you can remove this line (I think :-O)
-
AuthorPosts
This topic contains 2 replies, has 2 voices, and was last updated by VariFrame 7 years ago.
We moved to new unified forum. Please post all new support queries in our New Forum