IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

JavaScript Discussion :

Balise <DIV> capricieuse..!!


Sujet :

JavaScript

  1. #1
    Membre à l'essai
    Profil pro
    Inscrit en
    Mai 2005
    Messages
    17
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2005
    Messages : 17
    Points : 11
    Points
    11
    Par défaut Balise <DIV> capricieuse..!!
    salut,

    J'ai un problème avec une balise DIV au comportement étrange.

    dans une page j'ai plusieurs zone DIV.. notamment en haut de la page ou se trouve le menu. Comme cette zone n'est pas très grande en hauteur comme en largeur. J'ai d'ailleurs un scrollbar latéral qui s'affiche. j'ai décidé d'empécher la scrollbar de s'afficher et de la remplacer par deux flèche à droite et à gauche du menu faisant défiler la zone. C'est là que commence le mystère....

    j'ai réussi à faire un script qui tourne sous IE6 pour vérifier si le menu est plus grand que la zone <DIV> et si oui afficher les images qui remplaceront la barre de défilement. j'ai bien évidemment placé ces images dans 2 autres zones à droite et à gauche. Seulement sans que je comprenne pourquoi une des deux images ne s'affiche pas..!! elle ne s'affiche que quand je renomme avec le même nom que la zone que je veux faire défiler. Seulement quand je fais ça la fonction pour faire défiler ne marche pas...
    : :
    voici mon code Javascript :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
    // fonction qui test si le menu est plus grand que la zone
     
    function WidthTest(layer) {
      target=document.getElementById(layer)
      if (target.scrollLeft==target.scrollWidth)  {
      return "TRUE" ;}
      else { return "FALSE" ;}
    }
     
    // Fonction qui affiche les boutons si le menu est plus grand que la zone
     
    function ScrollAffiche (sens,layer) {
      if (sens==1) sensTxt="droite";
      if (sens==2) sensTxt="gauche";
      if (WidthTest(layer)=="FALSE") {
       document.write("<img src=\"../Images/scroll_"+sensTxt+".jpg\" height=\"15\" width=\"15\" onclick=\"Scroll("+sens+",'"+layer+"')\"/>"); }
    }
     
     
    //fonction qui fait défiler la zone à droite ou à gauche
     
    function Scroll(sens,layer) {
    var P=GetScrollPos(layer);
      if (sens==1)
      document.getElementById(layer).scrollLeft=P+10;
     
      if (sens==2)
      document.getElementById(layer).scrollLeft=P-10;
    }
     
     
    //fonction qui retourne la position actuelle de la barre de défilement
     
    function GetScrollPos(layer){
     
    var target=document.getElementById(layer);
    var res=target.scrollLeft;
     
    return res;
    }
    Et voilà la partie HTML :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
    <div style="position: absolute; z-index: 0; overflow: none; left: 225px; width: 15px; top: 5px; height: 15px;"  id="layer1">
     
     
    <script language="JavaScript">ScrollAffiche(2,'layer2');</script>
     
    </div>
     
    <div id="layer2" style="position: absolute; height: 53px; z-index: 0; top: -2px; overflow: hidden; left: 259px; width: 679px;">
     
    <table id="MenuH" align="center" border="0" cellpadding="5" cellspacing="3" height="15" width="80%">
      <tbody>
        <tr>
          <td class="menu_H" colspan="2"> <a href="correspondance.php?page=navig&amp;constr=Alstom">Alstom</a></td>
          <td class="menu_H" colspan="2"> <a href="correspondance.php?page=navig&amp;constr=Bova">Bova</a></td>
          <td class="menu_H" colspan="2"> <a href="correspondance.php?page=navig&amp;constr=Evobus">Evobus</a></td>
          <td class="menu_H" colspan="2"> <a href="correspondance.php?page=navig&amp;constr=Heuliez">Heuliez</a></td>
          <td class="menu_H" colspan="2"> <a href="correspondance.php?page=navig&amp;constr=IRISBUS">IRISBUS</a></td>
          <td class="menu_H" colspan="2"> <a href="correspondance.php?page=navig&amp;constr=Iveco">Iveco</a></td>
          <td class="menu_H" colspan="2"> <a href="correspondance.php?page=navig&amp;constr=Karosa">Karosa</a></td>
          <td class="menu_H" colspan="2"> <a href="correspondance.php?page=navig&amp;constr=Man">Man</a></td>
          <td class="menu_H" colspan="2"> <a href="correspondance.php?page=navig&amp;constr=Mercedes">Mercedes</a></td>
          <td class="menu_H" colspan="2"> <a href="correspondance.php?page=navig&amp;constr=Neoplan">Neoplan</a></td>
          <td class="menu_H" colspan="2"> <a href="correspondance.php?page=navig&amp;constr=Scania">Scania</a></td>
          <td class="menu_H" colspan="2"> <a href="correspondance.php?page=navig&amp;constr=Setra">Setra</a></td>
          <td class="menu_H" colspan="2"> <a href="correspondance.php?page=navig&amp;constr=Solaris">Solaris</a></td>
          <td class="menu_H" colspan="2"> <a href="correspondance.php?page=navig&amp;constr=Temsa">Temsa</a></td>
          <td class="menu_H" colspan="2"> <a href="correspondance.php?page=navig&amp;constr=Van%20Hool">VanHool</a></td>
          <td class="menu_H" colspan="2"> <a href="correspondance.php?page=navig&amp;constr=Volvo">Volvo</a></td>
        </tr>
      </tbody>
    </table>
    <table align="center" border="0" cellpadding="0" cellspacing="2" height="15" width="95%">
      <tbody>
        <tr>
        </tr>
      </tbody>
    </table>
     
    </div>
     
    <div style="position: absolute; z-index: 0; overflow: auto; left: 955px; width: 27px; top: 5px; height: 29px;"  id="layer3">
     
     
    <script language="JavaScript">ScrollAffiche(1,'layer2');</script>
     
    </div>
    je suis assez perplexe sur ce phénomène... il y a surement quelquechose qui m'échappe.. mais quoi...

    si quelqu'un voit une solution à ce mystère...

    Nerik

  2. #2
    Membre émérite
    Inscrit en
    Septembre 2002
    Messages
    2 307
    Détails du profil
    Informations forums :
    Inscription : Septembre 2002
    Messages : 2 307
    Points : 2 814
    Points
    2 814
    Par défaut
    Evite de faire ça.!
    document.write("<img src=\"../Images/scroll_"+sensTxt+".jpg\" height=\"15\" width=\"15\" onclick=\"Scroll("+sens+",'"+layer+"')\"/>"); }
    donne un nom/id à ton image, puis modifie la source de l'image

  3. #3
    Membre à l'essai
    Profil pro
    Inscrit en
    Mai 2005
    Messages
    17
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2005
    Messages : 17
    Points : 11
    Points
    11
    Par défaut
    Dsl mathieu, je ne vois pas ce que tu veux dire??

  4. #4
    Membre éclairé
    Avatar de shwin
    Profil pro
    Inscrit en
    Novembre 2003
    Messages
    568
    Détails du profil
    Informations personnelles :
    Localisation : Canada

    Informations forums :
    Inscription : Novembre 2003
    Messages : 568
    Points : 777
    Points
    777
    Par défaut
    Ce qu'il veut dire, c'est au lieu de créé ton image avec un document.write. Met ton image en place avec une src null et quand il faut que tu affiche l'image, tu allimente ta src via ton fichier image.

    De cette facon, c'est beaucoup plus propre et tu évite des document.write.
    Remoting Context Matters
    Everything in this chapter is 100 percent undocumented. Reliance on these techniques is not supported by either Microsoft, the publisher, or the author of this book. Use at you own risk! If your computer won't work afterwards, your toaster blows up or your car doesn't start, I assume no liability whatsoever: You're now about to enter the uncharted territories of .NET and you do so on your own risk. I can only provide some guidance

  5. #5
    Membre à l'essai
    Profil pro
    Inscrit en
    Mai 2005
    Messages
    17
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2005
    Messages : 17
    Points : 11
    Points
    11
    Par défaut
    ok c'est ce que j'ai fait...


    j'ai remplacé le document.write par:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    document.getElementById(img).src="../Images/Scroll_droite.jpg";
    et dans le HTML:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    <img id="monimage" height="15px" width="15px" src="" onclick="Scroll(2,'layer2')">
    Le défilement marche bien mais l'image n'apparait pas.. et je suis sur du chemin... c pas par un document.getElementById(img).src qu'on alimente la source??

    Et puis si jamais le menu est plus petit que la zone.. les boutons apparaitron quand même?? :

  6. #6
    Membre éclairé
    Avatar de shwin
    Profil pro
    Inscrit en
    Novembre 2003
    Messages
    568
    Détails du profil
    Informations personnelles :
    Localisation : Canada

    Informations forums :
    Inscription : Novembre 2003
    Messages : 568
    Points : 777
    Points
    777
    Par défaut
    Citation Envoyé par nerik38
    ok c'est ce que j'ai fait...


    j'ai remplacé le document.write par:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    document.getElementById(img).src="../Images/Scroll_droite.jpg";
    et dans le HTML:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    <img id="monimage" height="15px" width="15px" src="" onclick="Scroll(2,'layer2')">
    Le défilement marche bien mais l'image n'apparait pas.. et je suis sur du chemin... c pas par un document.getElementById(img).src qu'on alimente la source??

    Et puis si jamais le menu est plus petit que la zone.. les boutons apparaitron quand même?? :
    tu défini ton id comme étant "monimage" et tu call getElementById sur l'id "img". Call le sur "monimage" et ca devrais fonctionner beaucoup mieux
    Remoting Context Matters
    Everything in this chapter is 100 percent undocumented. Reliance on these techniques is not supported by either Microsoft, the publisher, or the author of this book. Use at you own risk! If your computer won't work afterwards, your toaster blows up or your car doesn't start, I assume no liability whatsoever: You're now about to enter the uncharted territories of .NET and you do so on your own risk. I can only provide some guidance

  7. #7
    Membre à l'essai
    Profil pro
    Inscrit en
    Mai 2005
    Messages
    17
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2005
    Messages : 17
    Points : 11
    Points
    11
    Par défaut
    dsl là c de ma faut c paske j'ai pas tout mis.. en fait l'intégralité du code est :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
     
    function ScrollAffiche (img,layer) {
      if (WidthTest(layer)=="FALSE" && img=="scrollLeft") {
      document.getElementById(img).src='../Images/Scroll_gauche.jpg';}}
      if (WidthTest(layer)=="FALSE" && img=="scrollRight") {
      document.getElementById(img).src='../Images/Scroll_droite.jpg';}
    }
    et pareil en HTML...
    j'ai 2 images vides dans 2 zones: scrollLeft et scrollRight.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    <img onload="scrollAffiche('scrollLeft','layer2')" id="scrollLeft"  height="15px" width="15px"  onclick="Scroll(2,'layer2')">

  8. #8
    Membre éclairé
    Avatar de shwin
    Profil pro
    Inscrit en
    Novembre 2003
    Messages
    568
    Détails du profil
    Informations personnelles :
    Localisation : Canada

    Informations forums :
    Inscription : Novembre 2003
    Messages : 568
    Points : 777
    Points
    777
    Par défaut
    enleve le S majuscule a ta fonction et met un s minuscule. Ca va aller mieux

    on va y arriver lache pas
    Remoting Context Matters
    Everything in this chapter is 100 percent undocumented. Reliance on these techniques is not supported by either Microsoft, the publisher, or the author of this book. Use at you own risk! If your computer won't work afterwards, your toaster blows up or your car doesn't start, I assume no liability whatsoever: You're now about to enter the uncharted territories of .NET and you do so on your own risk. I can only provide some guidance

  9. #9
    Membre à l'essai
    Profil pro
    Inscrit en
    Mai 2005
    Messages
    17
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2005
    Messages : 17
    Points : 11
    Points
    11
    Par défaut
    je vais devenir dingue..!!

    J'ai mis le nom de la fontion en majuscule mais ça ne marche toujours pas..!!! Niarf..!!!!

    C'est vriament bizarre.. j'ai mis un document.write(img) après ma fonction et je l'ai appelé de la zone principale de la page avec une autre image avec un id="patapof" et en passant par des balises script et plus par un événement Onload.. là l'image ne s'affiche toujours pas mais le "patapof" apparait alors que dans les 2 petites zones du menu il n'y a même pas le nom de l'image..!! :

    je suis perplexe...

  10. #10
    Membre à l'essai
    Profil pro
    Inscrit en
    Mai 2005
    Messages
    17
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2005
    Messages : 17
    Points : 11
    Points
    11
    Par défaut
    Au fait:

    on va y arriver lache pas
    merci pour ton soutien et ta patience shwin

  11. #11
    Membre à l'essai
    Profil pro
    Inscrit en
    Mai 2005
    Messages
    17
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2005
    Messages : 17
    Points : 11
    Points
    11
    Par défaut
    Rectification ça marche dans la zone principale de la page..!!!

  12. #12
    Membre éclairé
    Avatar de shwin
    Profil pro
    Inscrit en
    Novembre 2003
    Messages
    568
    Détails du profil
    Informations personnelles :
    Localisation : Canada

    Informations forums :
    Inscription : Novembre 2003
    Messages : 568
    Points : 777
    Points
    777
    Par défaut
    tu peux me redonner le code ?

    Avec les modifications que tu as effectué.
    Remoting Context Matters
    Everything in this chapter is 100 percent undocumented. Reliance on these techniques is not supported by either Microsoft, the publisher, or the author of this book. Use at you own risk! If your computer won't work afterwards, your toaster blows up or your car doesn't start, I assume no liability whatsoever: You're now about to enter the uncharted territories of .NET and you do so on your own risk. I can only provide some guidance

  13. #13
    Membre à l'essai
    Profil pro
    Inscrit en
    Mai 2005
    Messages
    17
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2005
    Messages : 17
    Points : 11
    Points
    11
    Par défaut
    voilà pour la fonction :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
     
    function ScrollAffiche (img,layer) {
     
      if (WidthTest(layer)=="FALSE" && img=="scrollLeft") {
      document.getElementById(img).src='../Images/Scroll_gauche.jpg';}
      if (WidthTest(layer)=="FALSE" && img=="scrollRight") {
      document.getElementById(img).src='../Images/Scroll_droite.jpg';}
      document.write(img);
    }
    et voilà pour les images :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
    ZONE 1: flèche défilement vers la gauche
     
    <div  style="position: absolute; z-index: 0; overflow: auto; left: 210px; width: 30px; top: 5px; height: 30px;"  id="layer1">
     
     <script language="JavaScript">ScrollAffiche('scrollLeft','layer2');</script>
    <img id="scrollLeft"  height="15px" width="15px"  onclick="Scroll(2,'layer2')">
     
    </div>
     
    ZONE 2 : Menu
     
    <div id="layer2" style="position: absolute; height: 53px; z-index: 3; top: -2px; overflow: hidden; left: 259px; width: 679px;">
     
    <table id="MenuH" align="center" border="0" cellpadding="5" cellspacing="3" height="15" width="80%">
      <tbody>
        <tr>
          <td class="menu_H" colspan="2"> <a href="correspondance.php?page=navig&amp;constr=Alstom">Alstom</a></td>
          <td class="menu_H" colspan="2"> <a href="correspondance.php?page=navig&amp;constr=Bova">Bova</a></td>
          <td class="menu_H" colspan="2"> <a href="correspondance.php?page=navig&amp;constr=Evobus">Evobus</a></td>
          <td class="menu_H" colspan="2"> <a href="correspondance.php?page=navig&amp;constr=Heuliez">Heuliez</a></td>
          <td class="menu_H" colspan="2"> <a href="correspondance.php?page=navig&amp;constr=IRISBUS">IRISBUS</a></td>
          <td class="menu_H" colspan="2"> <a href="correspondance.php?page=navig&amp;constr=Iveco">Iveco</a></td>
          <td class="menu_H" colspan="2"> <a href="correspondance.php?page=navig&amp;constr=Karosa">Karosa</a></td>
          <td class="menu_H" colspan="2"> <a href="correspondance.php?page=navig&amp;constr=Man">Man</a></td>
          <td class="menu_H" colspan="2"> <a href="correspondance.php?page=navig&amp;constr=Mercedes">Mercedes</a></td>
          <td class="menu_H" colspan="2"> <a href="correspondance.php?page=navig&amp;constr=Neoplan">Neoplan</a></td>
          <td class="menu_H" colspan="2"> <a href="correspondance.php?page=navig&amp;constr=Scania">Scania</a></td>
          <td class="menu_H" colspan="2"> <a href="correspondance.php?page=navig&amp;constr=Setra">Setra</a></td>
          <td class="menu_H" colspan="2"> <a href="correspondance.php?page=navig&amp;constr=Solaris">Solaris</a></td>
          <td class="menu_H" colspan="2"> <a href="correspondance.php?page=navig&amp;constr=Temsa">Temsa</a></td>
          <td class="menu_H" colspan="2"> <a href="correspondance.php?page=navig&amp;constr=Van%20Hool">VanHool</a></td>
          <td class="menu_H" colspan="2"> <a href="correspondance.php?page=navig&amp;constr=Volvo">Volvo</a></td>
        </tr>
      </tbody>
    </table>
    <table align="center" border="0" cellpadding="0" cellspacing="2" height="15" width="95%">
      <tbody>
        <tr>
        </tr>
      </tbody>
    </table>
     
    </div>
     
    ZONE 3 : Flèche défilement vers la droite
     
    <div style="position: absolute; z-index: 1; overflow: auto; left: 955px; width: 27px; top: 5px; height: 29px;"  id="layer3">
     
     <img onload="ScrollAffiche('scrollRight','layer2')" id="scrollRight"  height="15px" width="15px" onclick="Scroll(1,'layer2')">
     
     
    </div>
     
    ZONE 4 : zone principale ou l'image apparait... (Remarque: je ne laisse pas l'id scrollLeft en même temps sur l'image de la zone 4 et celle de la zone 1 c'est pour montrer que c'est la même chose mais que dans un cas ça marche et l'autre a marche po..!!)
     
    <div id="Layer4" style="border: 1px none rgb(0, 0, 0); position: absolute; width: 803px; height: 475px; z-index: 1; left: 181px; top: 58px; visibility: inherit; overflow: auto;">
    <img id="scrollLeft"  height="15px" width="15px"  onclick="Scroll(2,'layer2')">
    <script language="JavaScript">ScrollAffiche('scrollLeft','layer2')</script>
     
    </div>

Discussions similaires

  1. Edition d'une balise HTML div dans une WebView
    Par everdgg dans le forum Composants graphiques
    Réponses: 3
    Dernier message: 13/07/2012, 12h57
  2. XML brut (avec balises) dans div HTML
    Par mcfive dans le forum Langage
    Réponses: 4
    Dernier message: 05/07/2012, 17h07
  3. [DIV] contenir les elements dans la balise div
    Par kemodo dans le forum Mise en page CSS
    Réponses: 5
    Dernier message: 11/10/2004, 20h43
  4. [C#] Placer fichier html entre balises DIV
    Par Febus dans le forum ASP.NET
    Réponses: 9
    Dernier message: 07/05/2004, 11h44
  5. XSLT et balise HTML div
    Par haypo dans le forum XSL/XSLT/XPATH
    Réponses: 6
    Dernier message: 01/07/2003, 20h38

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo