J'essaie d'utiliser window.pageYOffset & window.scrollMaxY pour calculer la progression de la page en cours. Cette approche fonctionne sous FF3.5 mais sous webkit window.scrollMaxY est indéfini.Alternatives à window.scrollMaxY?
9
A
Répondre
2
J'ai loin avec document.body.scrollHeight
afin que
document.body.scrollHeight = window.pageYOffset + screen height in pixels
à la fin de la page (sur Android).
14
Alternative à window.scrollMaxY
:
document.documentElement.scrollHeight - document.documentElement.clientHeight
donne même résultat que window.scrollMaxY
avec IE7, IE8, FF3.5, Safari 4, Opera 10, Google Chrome 3 sous DOCTYPE XHTML 1.0 Transitional.
3
deux ans plus tard ...
function getScrollMaxY(){
var innerh;
if (window.innerHeight){
innerh = window.innerHeight;
}else{
innerh = document.body.clientHeight;
}
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;
}
0
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
Questions connexes
- 1. Alternatives légères à NHibernate
- 2. NoSQL - Alternatives à SGBDR
- 3. Alternatives à ID Selector?
- 4. Alternatives à TOAD (Linux)
- 5. Alternatives à YQL
- 6. Alternatives à WCF
- 7. Alternatives à popen/pclose?
- 8. Optimisation des alternatives à DateTime.Now
- 9. Alternatives PCAP
- 10. Spring.NET & Alternatives
- 11. Antialiasing alternatives
- 12. NAnt Alternatives
- 13. Session_End Alternatives
- 14. Alternatives SmartGWT
- 15. Alternatives à l'interface utilisateur jQuery Redimensionnable
- 16. Stockage de fichiers à Heroku - alternatives?
- 17. Existe-t-il des alternatives à svn_load_dirs.pl?
- 18. Alternatives à MS SQL 2005 FullText Catalog
- 19. Alternatives à swfobject pour l'intégration de flashplayer
- 20. Alternatives à NativeWindow pour la sous-classe
- 21. Quelles sont les alternatives à ClickOnce?
- 22. Quelles sont quelques alternatives ALM à TFS?
- 23. Microsoft Sync Framework Alternatives
- 24. alternatives/améliorations de JSplitPane
- 25. Acts_as_paranoid, is_paranoid ... Alternatives?
- 26. Open Source Clearcase Alternatives
- 27. RTMP Stream bitrate alternatives
- 28. MappedSuperclass Alternatives dans Grails
- 29. Gratuit XamlPad Alternatives
- 30. Hibernate Union alternatives
Merci bon monsieur. J'aimerais savoir s'il y a des inconvénients à utiliser cette méthode. Je viens de le tester en chrome/firefox et ça marche! – swajak
En essayant de l'implémenter avec 'window.scrollY', j'ai remarqué que dans le chrome au moins,' window.scrollY' est un float de haute précision, alors que 'scrollHeight' et' clientHeight' sont des entiers, donc j'ai dû 'Math.round() ' – Kaiido