cs_mahhoura
Messages postés15Date d'inscriptionvendredi 23 janvier 2004StatutMembreDernière intervention25 août 2007
-
25 août 2007 à 18:46
cs_bultez
Messages postés13615Date d'inscriptionjeudi 13 février 2003StatutMembreDernière intervention15 octobre 2013
-
26 août 2007 à 13:03
// Une fonction qui permet de centrer une div sur lecran sans faire recours a CSS .. (je sais que c'est possible.)
function centerMe(myDiv)
{
var arrayPageSize = getPageSize();
var object2 = document.getElementById(myDiv);
object2.style.top=((arrayPageSize[3]/2) - (object2.offsetWidth / 2))+'px';
object2.style.left=((arrayPageSize[2]/2) -(object2.offsetHeight / 2)) +'px';
}
function getPageSize(){
var xScroll, yScroll;
if (window.innerHeight && window.scrollMaxY) {
xScroll = document.body.scrollWidth;
yScroll = window.innerHeight + window.scrollMaxY;
} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
xScroll = document.body.scrollWidth;
yScroll = document.body.scrollHeight;
} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
xScroll = document.body.offsetWidth;
yScroll = document.body.offsetHeight;
}
var windowWidth, windowHeight;
if (self.innerHeight) { // all except Explorer
windowWidth = self.innerWidth;
windowHeight = self.innerHeight;
} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
windowWidth = document.documentElement.clientWidth;
windowHeight = document.documentElement.clientHeight;
} else if (document.body) { // other Explorers
windowWidth = document.body.clientWidth;
windowHeight = document.body.clientHeight;
}
// for small pages with total height less then height of the viewport
if(yScroll < windowHeight){
pageHeight = windowHeight;
} else {
pageHeight = yScroll;
}
// for small pages with total width less then width of the viewport
if(xScroll < windowWidth){
pageWidth = windowWidth;
} else {
pageWidth = xScroll;
}
arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
return arrayPageSize;
}
cs_bultez
Messages postés13615Date d'inscriptionjeudi 13 février 2003StatutMembreDernière intervention15 octobre 201330 26 août 2007 à 13:03
amical bonjour à toi aussi,
>>
Une fonction qui permet de centrer une div sur
>>lecran sans faire recours a CSS
soit c'est une affirmation soit un exemple ?
pourquoi faire ça en javascript, si ça fonctionne avec le CSS ?
ou alors c'est une question ?
ce que tu fais ne fonctionne pas ? il y a un message d'erreur ?
avec quel navigateur ? la fonction est appelée comment ? quand ?
regarde plutôt du coté du CSS, ça marchera.
<hr />
merci beaucoup pour la question ou l'exemple Bul [mon Site] [M'écrire]