1
如何在沒有jquery的Ionic中執行此操作?ionic 2 - 獲取window.scrollTop
var window_top = jQuery(window).scrollTop() + 56;
var div_top = jQuery('#sticky-anchor').offset().top;
如何在沒有jquery的Ionic中執行此操作?ionic 2 - 獲取window.scrollTop
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
你在哪裏可以解決這個問題? – sebaferreras
@sebaferreras不,我不是我結束了使用jQuery的那樣 –