0

I'm a js newbie and I'm trying to integrate the jQuery Easing Plugin (http://gsgd.co.uk/sandbox/jquery/easing/) into some of my .js:

$(function() {
var $root = $('html, body');
$('.project').click(function() {
var href = $.attr(this, 'href');
$root.animate({
    scrollTop: $(href).offset().top
}, 1000, function () {
    window.location.hash = href;
});
return false;
});
});

and

$(function(){
$(window).scroll(function(){
if ($(this).scrollTop() > 100) {
$('.scrollToTop').fadeIn();
} else {
$('.scrollToTop').fadeOut();
}
});
$('.scrollToTop').click(function(){
$('html, body').animate({scrollTop : 0},300);
return false;
});
});

I've tried adding

$(scrollElem).animate({scrollTop: targetOffset}, 300,
‘easeOutElastic’, function() {

And some similar others I've found, but I didn't get it working.

Any help? Thanks in advance.

Javier
  • 1
  • 3
  • Just to clarify, are you wanting to scroll the body to the top of some element? And, are you wanting it flush with the window or with some additional spacing above it? – Jonathan Bowman Oct 26 '15 at 21:20
  • The first code is for scroll to the anchors, and the second one creates a "to top" link element. I just want to integrate the easing plugin to get smoother in and out animations. – Javier Oct 27 '15 at 14:04
  • So it does scroll to the correct positions, and it does animate, but you just aren't able to get the easing animations to happen? Are you sure you included the script correctly and called it AFTER your jQuery include? You can use the CDN he has linked on his page, or you can include the files yourself - which did you do? – Jonathan Bowman Oct 27 '15 at 14:47
  • Ok, I didn't get that it was really so easy. I just used `jQuery.easing.def = "easeOutExpo";` in the first line and it worked. Sorry for the dumb question. – Javier Oct 27 '15 at 17:53
  • 1
    No worries at all - the only dumb thing we can do is not ask questions when we have them :) – Jonathan Bowman Oct 27 '15 at 19:10

0 Answers0