gpt4 book ai didi

javascript - ionic 2 - 获取 window.scrollTop

转载 作者:行者123 更新时间:2023-11-30 08:28:34 26 4
gpt4 key购买 nike

如果没有 jquery,我如何在 Ionic 中执行此操作?

  var window_top = jQuery(window).scrollTop() + 56;
var div_top = jQuery('#sticky-anchor').offset().top;

最佳答案

您可以使用对 Content 的引用:

import { Component, ViewChild } from '@angular/core';
import { Content } from 'ionic-angular';

@Component({...})
export class MyPage{
@ViewChild(Content) content: Content;

scrollToTop() {
this.content.scrollToTop();
}

scrollTo(elementId:string) {
let yOffset = document.getElementById(elementId).offsetTop;
this.content.scrollTo(0, yOffset, 4000)
}
}

您可以使用很多属性;最重要的一个是......

getContentDimensions():返回内容和滚动元素的尺寸。

Property                    Type    Details
dimensions.contentHeight number content offsetHeight
dimensions.contentTop number content offsetTop
dimensions.contentBottom number content offsetTop+offsetHeight
dimensions.contentWidth number content offsetWidth
dimensions.contentLeft number content offsetLeft
dimensions.contentRight number content offsetLeft + offsetWidth
dimensions.scrollHeight number scroll scrollHeight
dimensions.scrollTop number scroll scrollTop
dimensions.scrollBottom number scroll scrollTop + scrollHeight
dimensions.scrollWidth number scroll scrollWidth
dimensions.scrollLeft number scroll scrollLeft
dimensions.scrollRight number scroll scrollLeft + scrollWidth

关于javascript - ionic 2 - 获取 window.scrollTop,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41317643/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com