流畅的JavaScript/jQuery滚动到元素 [英] Smooth JavaScript/jQuery scroll to element

查看:56
本文介绍了流畅的JavaScript/jQuery滚动到元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试制作一个水平滚动网站,但是我不知道如何平滑从一个元素滚动到另一个元素. 我尝试了以下代码:

I'm trying to make a horizontal scroll website, but I don't know how to smoothly scroll from one element to the other. I tried the following code:

$("a[href='#top']").click(function() {
  $("body").animate({ scrollTop: 0 }, "slow");
  return false;
});

但是它只滚动到顶部,我还尝试了jQuery插件 ScrollTo ,但是我只是无法正常工作,我还尝试了jQuery插件:

But it only scrolls to the top, I also tried the jQuery-plugin ScrollTo, but I just can't get it to work, I also tried the jQuery plugin:

$('.click').click(function(){
    $.scrollTo( '.last', 800, {easing:'elasout'});
});

但是也没有成功.

有人知道我可以使用的很好的,易于理解的样本吗?预先感谢!

Does anyone know a good, easy to understand, sample I can use? Thanks in advance!

推荐答案

未测试

   $('.click').click(function(){
        $.scrollTo( $('.last'), 800);
    });

这篇关于流畅的JavaScript/jQuery滚动到元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆