angular - scroll height and document height units












0















When the window slides, it can detect the current height, but I don't know the unit of this height. I hope to get the total height(bottom height) by angular.



The height of the document is different from the height unit of the scroll. How do you convert between the two? Or in what way do you get the common unit?



For example:



 import {HostListener,Inject} from "@angular/core";
import { DOCUMENT } from "@angular/platform-browser";

constructor(@Inject(DOCUMENT) private document: Document {}

ngOnInit() {
}

@HostListener("window:scroll", )onWindowScroll() {
//.scrollTop
console.log(this.document.documentElement.scrollTop)
//.clientHeight
console.log(this.document.documentElement.clientHeight);
//.innerHeight
console.log(window.innerHeight);
}


These three are different.
document.documentElement.scrollTopdocument.documentElement.clientHeightwindow.innerHeight










share|improve this question

























  • what do you mean by convert? these are separate properties and hence named differently - with definitions present in various locations

    – Akber Iqbal
    Nov 22 '18 at 6:06











  • @AIqbalRaj Edited in the first paragraph.

    – Albert
    Nov 22 '18 at 6:23
















0















When the window slides, it can detect the current height, but I don't know the unit of this height. I hope to get the total height(bottom height) by angular.



The height of the document is different from the height unit of the scroll. How do you convert between the two? Or in what way do you get the common unit?



For example:



 import {HostListener,Inject} from "@angular/core";
import { DOCUMENT } from "@angular/platform-browser";

constructor(@Inject(DOCUMENT) private document: Document {}

ngOnInit() {
}

@HostListener("window:scroll", )onWindowScroll() {
//.scrollTop
console.log(this.document.documentElement.scrollTop)
//.clientHeight
console.log(this.document.documentElement.clientHeight);
//.innerHeight
console.log(window.innerHeight);
}


These three are different.
document.documentElement.scrollTopdocument.documentElement.clientHeightwindow.innerHeight










share|improve this question

























  • what do you mean by convert? these are separate properties and hence named differently - with definitions present in various locations

    – Akber Iqbal
    Nov 22 '18 at 6:06











  • @AIqbalRaj Edited in the first paragraph.

    – Albert
    Nov 22 '18 at 6:23














0












0








0








When the window slides, it can detect the current height, but I don't know the unit of this height. I hope to get the total height(bottom height) by angular.



The height of the document is different from the height unit of the scroll. How do you convert between the two? Or in what way do you get the common unit?



For example:



 import {HostListener,Inject} from "@angular/core";
import { DOCUMENT } from "@angular/platform-browser";

constructor(@Inject(DOCUMENT) private document: Document {}

ngOnInit() {
}

@HostListener("window:scroll", )onWindowScroll() {
//.scrollTop
console.log(this.document.documentElement.scrollTop)
//.clientHeight
console.log(this.document.documentElement.clientHeight);
//.innerHeight
console.log(window.innerHeight);
}


These three are different.
document.documentElement.scrollTopdocument.documentElement.clientHeightwindow.innerHeight










share|improve this question
















When the window slides, it can detect the current height, but I don't know the unit of this height. I hope to get the total height(bottom height) by angular.



The height of the document is different from the height unit of the scroll. How do you convert between the two? Or in what way do you get the common unit?



For example:



 import {HostListener,Inject} from "@angular/core";
import { DOCUMENT } from "@angular/platform-browser";

constructor(@Inject(DOCUMENT) private document: Document {}

ngOnInit() {
}

@HostListener("window:scroll", )onWindowScroll() {
//.scrollTop
console.log(this.document.documentElement.scrollTop)
//.clientHeight
console.log(this.document.documentElement.clientHeight);
//.innerHeight
console.log(window.innerHeight);
}


These three are different.
document.documentElement.scrollTopdocument.documentElement.clientHeightwindow.innerHeight







angular






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 22 '18 at 6:47







Albert

















asked Nov 22 '18 at 5:58









AlbertAlbert

147315




147315













  • what do you mean by convert? these are separate properties and hence named differently - with definitions present in various locations

    – Akber Iqbal
    Nov 22 '18 at 6:06











  • @AIqbalRaj Edited in the first paragraph.

    – Albert
    Nov 22 '18 at 6:23



















  • what do you mean by convert? these are separate properties and hence named differently - with definitions present in various locations

    – Akber Iqbal
    Nov 22 '18 at 6:06











  • @AIqbalRaj Edited in the first paragraph.

    – Albert
    Nov 22 '18 at 6:23

















what do you mean by convert? these are separate properties and hence named differently - with definitions present in various locations

– Akber Iqbal
Nov 22 '18 at 6:06





what do you mean by convert? these are separate properties and hence named differently - with definitions present in various locations

– Akber Iqbal
Nov 22 '18 at 6:06













@AIqbalRaj Edited in the first paragraph.

– Albert
Nov 22 '18 at 6:23





@AIqbalRaj Edited in the first paragraph.

– Albert
Nov 22 '18 at 6:23












1 Answer
1






active

oldest

votes


















0














First of all this question has nothing to do with Angular, but it is specifically Javascript DOM model.



Second all heights and width are returned in pixels, so there is no question of conversion



now specific to elements asked by you



document.documentElement.scrollTop - this property returns the number of pixels an element's content is scrolled vertically. For more information refer this url



window.innerHeight and document.documentElement.clientHeight are same, only difference is IE older browser calles it document.documentElement.clientHeight, and modern browswer calles it window.innerHeight. Refer this link for more details






share|improve this answer
























  • Is there any way to get the total height of the scroll?

    – Albert
    Nov 22 '18 at 6:38











  • Scroll is always attached to an element, most of the time div. So you can get height of corresponding div. I prefer to use $('#some_div').height();, but in case you are not using jquery, please use document.getElementById('some_div').getBoundingClientRect().height or document.getElementById('some_div').clientHeight

    – user7154703
    Nov 22 '18 at 6:50











  • I tried to use this.document.documentElement.getBoundingClientRect().height, its value is closer to this.document.documentElement.scrollTop,but this.document.documentElement.clientHeight is completely another value.

    – Albert
    Nov 22 '18 at 6:59













  • Am not sure how you are checking but at element level there are not many variations than mentioned below ` document.getElementById("some_div").height ` 2) height() - return the height without padding 3) innerHeight() - Returns the height of an element (includes padding) 4) outerHeight() - Returns the height of an element (includes padding and border)

    – user7154703
    Nov 22 '18 at 7:09






  • 1





    If you using Chrome, please take help from Developer Tool ( Control + Shift + I ) , you will know which class exactly changing height . And refer url w3schools.com/jquery/css_height.asp and w3schools.com/jsref/obj_screen.asp for height specific knowledge.

    – user7154703
    Nov 22 '18 at 7:56













Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53424704%2fangular-scroll-height-and-document-height-units%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














First of all this question has nothing to do with Angular, but it is specifically Javascript DOM model.



Second all heights and width are returned in pixels, so there is no question of conversion



now specific to elements asked by you



document.documentElement.scrollTop - this property returns the number of pixels an element's content is scrolled vertically. For more information refer this url



window.innerHeight and document.documentElement.clientHeight are same, only difference is IE older browser calles it document.documentElement.clientHeight, and modern browswer calles it window.innerHeight. Refer this link for more details






share|improve this answer
























  • Is there any way to get the total height of the scroll?

    – Albert
    Nov 22 '18 at 6:38











  • Scroll is always attached to an element, most of the time div. So you can get height of corresponding div. I prefer to use $('#some_div').height();, but in case you are not using jquery, please use document.getElementById('some_div').getBoundingClientRect().height or document.getElementById('some_div').clientHeight

    – user7154703
    Nov 22 '18 at 6:50











  • I tried to use this.document.documentElement.getBoundingClientRect().height, its value is closer to this.document.documentElement.scrollTop,but this.document.documentElement.clientHeight is completely another value.

    – Albert
    Nov 22 '18 at 6:59













  • Am not sure how you are checking but at element level there are not many variations than mentioned below ` document.getElementById("some_div").height ` 2) height() - return the height without padding 3) innerHeight() - Returns the height of an element (includes padding) 4) outerHeight() - Returns the height of an element (includes padding and border)

    – user7154703
    Nov 22 '18 at 7:09






  • 1





    If you using Chrome, please take help from Developer Tool ( Control + Shift + I ) , you will know which class exactly changing height . And refer url w3schools.com/jquery/css_height.asp and w3schools.com/jsref/obj_screen.asp for height specific knowledge.

    – user7154703
    Nov 22 '18 at 7:56


















0














First of all this question has nothing to do with Angular, but it is specifically Javascript DOM model.



Second all heights and width are returned in pixels, so there is no question of conversion



now specific to elements asked by you



document.documentElement.scrollTop - this property returns the number of pixels an element's content is scrolled vertically. For more information refer this url



window.innerHeight and document.documentElement.clientHeight are same, only difference is IE older browser calles it document.documentElement.clientHeight, and modern browswer calles it window.innerHeight. Refer this link for more details






share|improve this answer
























  • Is there any way to get the total height of the scroll?

    – Albert
    Nov 22 '18 at 6:38











  • Scroll is always attached to an element, most of the time div. So you can get height of corresponding div. I prefer to use $('#some_div').height();, but in case you are not using jquery, please use document.getElementById('some_div').getBoundingClientRect().height or document.getElementById('some_div').clientHeight

    – user7154703
    Nov 22 '18 at 6:50











  • I tried to use this.document.documentElement.getBoundingClientRect().height, its value is closer to this.document.documentElement.scrollTop,but this.document.documentElement.clientHeight is completely another value.

    – Albert
    Nov 22 '18 at 6:59













  • Am not sure how you are checking but at element level there are not many variations than mentioned below ` document.getElementById("some_div").height ` 2) height() - return the height without padding 3) innerHeight() - Returns the height of an element (includes padding) 4) outerHeight() - Returns the height of an element (includes padding and border)

    – user7154703
    Nov 22 '18 at 7:09






  • 1





    If you using Chrome, please take help from Developer Tool ( Control + Shift + I ) , you will know which class exactly changing height . And refer url w3schools.com/jquery/css_height.asp and w3schools.com/jsref/obj_screen.asp for height specific knowledge.

    – user7154703
    Nov 22 '18 at 7:56
















0












0








0







First of all this question has nothing to do with Angular, but it is specifically Javascript DOM model.



Second all heights and width are returned in pixels, so there is no question of conversion



now specific to elements asked by you



document.documentElement.scrollTop - this property returns the number of pixels an element's content is scrolled vertically. For more information refer this url



window.innerHeight and document.documentElement.clientHeight are same, only difference is IE older browser calles it document.documentElement.clientHeight, and modern browswer calles it window.innerHeight. Refer this link for more details






share|improve this answer













First of all this question has nothing to do with Angular, but it is specifically Javascript DOM model.



Second all heights and width are returned in pixels, so there is no question of conversion



now specific to elements asked by you



document.documentElement.scrollTop - this property returns the number of pixels an element's content is scrolled vertically. For more information refer this url



window.innerHeight and document.documentElement.clientHeight are same, only difference is IE older browser calles it document.documentElement.clientHeight, and modern browswer calles it window.innerHeight. Refer this link for more details







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 22 '18 at 6:27







user7154703




















  • Is there any way to get the total height of the scroll?

    – Albert
    Nov 22 '18 at 6:38











  • Scroll is always attached to an element, most of the time div. So you can get height of corresponding div. I prefer to use $('#some_div').height();, but in case you are not using jquery, please use document.getElementById('some_div').getBoundingClientRect().height or document.getElementById('some_div').clientHeight

    – user7154703
    Nov 22 '18 at 6:50











  • I tried to use this.document.documentElement.getBoundingClientRect().height, its value is closer to this.document.documentElement.scrollTop,but this.document.documentElement.clientHeight is completely another value.

    – Albert
    Nov 22 '18 at 6:59













  • Am not sure how you are checking but at element level there are not many variations than mentioned below ` document.getElementById("some_div").height ` 2) height() - return the height without padding 3) innerHeight() - Returns the height of an element (includes padding) 4) outerHeight() - Returns the height of an element (includes padding and border)

    – user7154703
    Nov 22 '18 at 7:09






  • 1





    If you using Chrome, please take help from Developer Tool ( Control + Shift + I ) , you will know which class exactly changing height . And refer url w3schools.com/jquery/css_height.asp and w3schools.com/jsref/obj_screen.asp for height specific knowledge.

    – user7154703
    Nov 22 '18 at 7:56





















  • Is there any way to get the total height of the scroll?

    – Albert
    Nov 22 '18 at 6:38











  • Scroll is always attached to an element, most of the time div. So you can get height of corresponding div. I prefer to use $('#some_div').height();, but in case you are not using jquery, please use document.getElementById('some_div').getBoundingClientRect().height or document.getElementById('some_div').clientHeight

    – user7154703
    Nov 22 '18 at 6:50











  • I tried to use this.document.documentElement.getBoundingClientRect().height, its value is closer to this.document.documentElement.scrollTop,but this.document.documentElement.clientHeight is completely another value.

    – Albert
    Nov 22 '18 at 6:59













  • Am not sure how you are checking but at element level there are not many variations than mentioned below ` document.getElementById("some_div").height ` 2) height() - return the height without padding 3) innerHeight() - Returns the height of an element (includes padding) 4) outerHeight() - Returns the height of an element (includes padding and border)

    – user7154703
    Nov 22 '18 at 7:09






  • 1





    If you using Chrome, please take help from Developer Tool ( Control + Shift + I ) , you will know which class exactly changing height . And refer url w3schools.com/jquery/css_height.asp and w3schools.com/jsref/obj_screen.asp for height specific knowledge.

    – user7154703
    Nov 22 '18 at 7:56



















Is there any way to get the total height of the scroll?

– Albert
Nov 22 '18 at 6:38





Is there any way to get the total height of the scroll?

– Albert
Nov 22 '18 at 6:38













Scroll is always attached to an element, most of the time div. So you can get height of corresponding div. I prefer to use $('#some_div').height();, but in case you are not using jquery, please use document.getElementById('some_div').getBoundingClientRect().height or document.getElementById('some_div').clientHeight

– user7154703
Nov 22 '18 at 6:50





Scroll is always attached to an element, most of the time div. So you can get height of corresponding div. I prefer to use $('#some_div').height();, but in case you are not using jquery, please use document.getElementById('some_div').getBoundingClientRect().height or document.getElementById('some_div').clientHeight

– user7154703
Nov 22 '18 at 6:50













I tried to use this.document.documentElement.getBoundingClientRect().height, its value is closer to this.document.documentElement.scrollTop,but this.document.documentElement.clientHeight is completely another value.

– Albert
Nov 22 '18 at 6:59







I tried to use this.document.documentElement.getBoundingClientRect().height, its value is closer to this.document.documentElement.scrollTop,but this.document.documentElement.clientHeight is completely another value.

– Albert
Nov 22 '18 at 6:59















Am not sure how you are checking but at element level there are not many variations than mentioned below ` document.getElementById("some_div").height ` 2) height() - return the height without padding 3) innerHeight() - Returns the height of an element (includes padding) 4) outerHeight() - Returns the height of an element (includes padding and border)

– user7154703
Nov 22 '18 at 7:09





Am not sure how you are checking but at element level there are not many variations than mentioned below ` document.getElementById("some_div").height ` 2) height() - return the height without padding 3) innerHeight() - Returns the height of an element (includes padding) 4) outerHeight() - Returns the height of an element (includes padding and border)

– user7154703
Nov 22 '18 at 7:09




1




1





If you using Chrome, please take help from Developer Tool ( Control + Shift + I ) , you will know which class exactly changing height . And refer url w3schools.com/jquery/css_height.asp and w3schools.com/jsref/obj_screen.asp for height specific knowledge.

– user7154703
Nov 22 '18 at 7:56







If you using Chrome, please take help from Developer Tool ( Control + Shift + I ) , you will know which class exactly changing height . And refer url w3schools.com/jquery/css_height.asp and w3schools.com/jsref/obj_screen.asp for height specific knowledge.

– user7154703
Nov 22 '18 at 7:56






















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53424704%2fangular-scroll-height-and-document-height-units%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

MongoDB - Not Authorized To Execute Command

How to fix TextFormField cause rebuild widget in Flutter

in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith