J'essaie d'utiliser fenêtre.PageYoffset em> & fenêtre.scrollmaxy em> Pour calculer la page actuelle progression. Cette approche fonctionne sous FF3.5 mais sous WebKit window.scrollmaxy em> est indéfinie. P>
4 Réponses :
Je suis sorti avec à la fin de la page (sur Android). P> < / p> document.body.scrollheight code> de sorte que
alternative à donne le même résultat que fenêtre.scrollmaxy code>:
fenêtre.scrollmaxy code> avec IE7, IE8, FF3.5, Safari 4, Opéra 10, Google Chrome 3 Sous Doctype XHTML 1.0 Transitional. P> P>
Merci bon monsieur. J'aimerais savoir s'il y a des inconvénients pour utiliser cette méthode. Je viens de le tester à Chrome / Firefox et ça marche!
Essayer de le mettre en œuvre contre window.scrolly code> J'ai remarqué que dans le chrome au moins,
fenêtre.scrolly code> est un flotteur de haute précision, tandis que
Scrollheight code> et
ClientHeight code> sont des entiers, donc j'ai dû
math.round () code> il
Deux ans plus tard ...
function getScrollMaxY(){"use strict"; var innerh = window.innerHeight || ebody.clientHeight, yWithScroll = 0; if (window.innerHeight && window.scrollMaxY){ // Firefox yWithScroll = window.innerHeight + window.scrollMaxY; } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac yWithScroll = document.body.scrollHeight; } else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari yWithScroll = document.body.offsetHeight; } return yWithScroll-innerh; }
x = document.body.clientHeight; console.log(x ,"Cline HEight"); xx = window.innerHeight; console.log(xx, "Inner Height"); xxx = document.body.scrollHeight console.log(xxx, "scrollHeight"); xxxx = window.scrollMaxY; console.log(xxxx, "scrollMaxY for IE"); xxxxx = document.body.offsetHeight; console.log(xxxxx, "offsetHeight"); xxxxxx= document.body.scrollTop; console.log(xxxxxx, "scrollTop");strong text