Affichage div et position
Bonjour,
Je ne suis pas très performant en javascript mais j'essaie d'apprendre j'ai tapé un code qui est pas mal mais qui semble bloqué quelquepart je vous colle le code ci-dessous :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
| <?php
header("Content-Type: text/javascript");
$url = "http://www.site1.com";
$img = "http://www.site2.fr/exemple.gif";
?>
if (window.innerHeight) {
//Navigateurs sauf Explorer
var fenHeight = window.innerHeight;
var fenWidth = window.innerWidth;
}
else if (document.documentElement && document.documentElement.clientHeight) {
//Internet Explorer mode Strict
var fenHeight = document.documentElement.clientHeight;
var fenWidth = document.documentElement.clientWidth;
}
else if (document.body && document.body.clientHeight) {
//Autres Internet Explorer
var fenHeight = document.body.clientHeight;
var fenWidth = document.body.clientWidth;
}
hauteur = (fenHeight-270)/2;
gauche = (fenWidth-250)/2;
function scroll_fenetre()
{
if (window.innerHeight) {
//Navigateurs sauf Explorer
var scroll = 0;
}
else if (document.documentElement && document.documentElement.scrollTop) {
//Internet Explorer mode Strict
var scroll = document.documentElement.scrollTop+hauteur;
}
else if (document.body && document.body.scrollTop) {
//Autres Internet Explorer
var scroll = document.body.scrollTop+hauteur;
}
if (window.ActiveXObject && window.XMLHttpRequest && window.external && document.compatMode=="CSS1Compat") {
var scroll=hauteur;
}
return scroll;
}
function IEFixedElementPos()
{
// IE 7 en mode standard
if (window.ActiveXObject && window.XMLHttpRequest && window.external && document.compatMode=="CSS1Compat")
{
return ("fixed");
}
return ("absolute");
}
document.write('<style type="text/css">\n'+
'#supersticiel \n'+
' {\n'+
' position:fixed;\n'+
' width:250px;\n'+
' height:270px;\n'+
' top:\n'+hauteur+'px;\n'+
' left:\n'+gauche+'px;\n'+
' position: expression(IEFixedElementPos());;\n'+
' top: expression(scroll_fenetre());\n'+
' }\n'+
'</style>');
function supersticiel_affiche()
{
document.write("<table id='supersticiel' cellspacing='0' cellpadding='0' WIDTH='250' HEIGHT='270'><tr><td><a href='<?php echo $url; ?>' target='_blank'><img src='<?php echo $img; ?>' alt='' width='250' height='250' border='0'></a></td></tr></table>");
}
function supersticiel_close()
{
if(document.getElementById)
{
document.getElementById("supersticiel").style.width = 1;
document.getElementById("supersticiel").style.height = 1;
document.getElementById("supersticiel").style.display="none";
}
}
if(window.addEventListener){
window.addEventListener('load',function() {
supersticiel_affiche();
},false)
} else if(window.attachEvent) {
window.attachEvent('onload',function() {
supersticiel_affiche();
})
} |
Mon code devrait selon mes souhaits se baser sur le style css #supersticiel pour faire une image de 250*270 en position fixed centrer au milieu de l'écran mais le problème semble se poser sur l'affichage de l'image qui doit s'afficher par dessus la page alors que là ben le document.write semble effacer tout le code html de la page et n'afficher que le contenu du document.write