ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

javascript – Google Closure相当于jQuery $(‘html,body’).animate({scrollTop:800});

2019-07-25 07:41:07  阅读:249  来源: 互联网

标签:javascript jquery animation scroll google-closure


有问题的代码会将页面滚动到页面上的特定点.正如标题所说,我希望Google Closure等同于以下jQuery:

$(‘html,body’).animate({scrollTop: 800});

它说here那个html,正文允许浏览器不一致,而$(文档)是等价的.

我尝试过以下方法:

var anim = new goog.fx.dom.Scroll(document, [0, 0], [0, 800], 400);
anim.play();

我也尝试过document.body.

goog.fx.dom.Svroll上网没有演示和惨淡缺乏信息.

解决方法:

使goog.fx.Scroll类与文档(正文或HTML)一起工作的方法是通过以下方式传递文档滚动元素:

/**
 * Document scroll element obtained from goog.dom
 * @type {Element}
 * @private
 */
let documentScrollElement_ = goog.dom.getDocumentScrollElement()

/**
 * Function triggered by any target to start scrolling
 * @param  {Event} e Triggered event
 * @private
 */
function scrollTrigger_(e) {
  let googScroll = new goog.fx.dom.Scroll(
    this.documentScrollElement_,
    [0, 0],
    [0, 800],
    400);

  googScroll.play();
}

只是让你知道Scroll类有这个可选参数来为滚动添加缓动.你应该像这样新建这个类:

let googScroll = new goog.fx.dom.Scroll(
    this.documentScrollElement_,
    [0, 0],
    [0, 800],
    400,
    goog.fx.easing.inAndOut(t)); // Note that you need to import or require the goog.fx.easing object

我知道这是一个老问题,但我遇到了同样的问题,并设法让它工作,所以我认为值得回答这个问题.

希望能帮助到你!

标签:javascript,jquery,animation,scroll,google-closure
来源: https://codeday.me/bug/20190725/1531041.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有