Link to section -> animate the scroll ?

Rate this topic: Evaluations: 1, 1.00 on the average.Evaluations: 1, 1.00 on the average.Evaluations: 1, 1.00 on the average.Evaluations: 1, 1.00 on the average.Evaluations: 1, 1.00 on the average.Evaluations: 1, 1.00 on the average.1.00 out of 6 based on 1 vote(s)
GK User
Tue Aug 19, 2014 1:03 pm
Reply with quote
Report this post
Hello.
I want to use Simplicity template as onepage. I have links to sections in menu.
How can I add animated scroll to sections?
User avatar
Fresh Boarder

teitbite
Wed Aug 20, 2014 11:55 am
Reply with quote
Report this post
Hi
Please try adding this to template's js file:

Code: Select all
   // smooth anchor scrolling
   jQuery('a[href^="#"]').on('click',function (e) {
      e.preventDefault();

      var target = this.hash,
      target = jQuery(target);
      if(this.hash !== '') {
         jQuery('html, body').stop().animate({
            'scrollTop': target.offset().top
         }, 1000, 'swing', function () {
            window.location.hash = target.selector;
         });
      }
   });

User avatar
Moderator

GK User
Tue Sep 30, 2014 5:01 pm
Reply with quote
Report this post
Which file is exactly the one that we have to edit?
User avatar
Expert Boarder

teitbite
Thu Oct 02, 2014 10:51 am
Reply with quote
Report this post
Hi

It's in template's /js/gk.scripts.js
User avatar
Moderator

GK User
Tue Oct 27, 2015 10:48 pm
Reply with quote
Report this post
gives an error:

Parse error: syntax error, unexpected ')', expecting '&' or variable (T_VARIABLE) in
/Quark-Child/functions.php on line 44

= this line:
jQuery('a[href^="#"]').on('click',function (e) {

can you correct it?
thanks!
User avatar
Fresh Boarder

GK User
Tue Oct 27, 2015 11:26 pm
Reply with quote
Report this post
found a better script:
<script>
$(document).ready(function(){
$('a[href^="#"]').on('click',function (e) {
e.preventDefault();

var target = this.hash;
var $target = $(target);

$('html, body').stop().animate({
'scrollTop': $target.offset().top
}, 900, 'swing', function () {
window.location.hash = target;
});
});
});
</script>

there is now /js/gk.scripts.js
in my template..

what file i have to add this script???
User avatar
Fresh Boarder

teitbite
Fri Oct 30, 2015 1:02 pm
Reply with quote
Report this post
Hi

The error was shown because was copied to wrong place. My guess is somewhere within PHP tags.

Look into /js/gk.scripts.js file in template. There You will see a code for smooth scrolling. It will be commented so should be easy to find. Simply remove it and replace with Your own.
User avatar
Moderator


cron