[英]ionic 2 - Get window.scrollTop
没有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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.