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 :

Insérer un décalage vertical sur une ancre la page


Sujet :

JavaScript

  1. #1
    Membre extrêmement actif
    Avatar de Madmac
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Juin 2004
    Messages
    1 685
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Canada

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : Alimentation

    Informations forums :
    Inscription : Juin 2004
    Messages : 1 685
    Points : 1 376
    Points
    1 376
    Billets dans le blog
    7
    Par défaut Insérer un décalage vertical sur une ancre la page
    Je sais que je suis proche de la solution, mais je n'arrive pas à comprendre comment à introduire le décalage. Dois-je utiliser une chaine ou un nombre ?

    Voici ma page, elle fonctionne. Mais quand j'utilise le menu, mes titres se retrouvent sous le menu.

    Code HTML : 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
    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
    <!DOCTYPE html>
    <html>
    <head>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <script>
    function jumpto(h){
        var top = document.getElementById(h).offsetTop; //Getting Y of target e
        window.scrollTo(0, top);                        //Go there directly or some transition
    }
    </script>
    <style>
    body {margin:0;}
     
    .navbar {
      overflow: hidden;
      background-color: #333;
      position: fixed;
      top: 0;
      width: 100%;
    }
     
    .navbar a {
      float: left;
      display: block;
      color: #f2f2f2;
      text-align: center;
      padding: 14px 16px;
      text-decoration: none;
      font-size: 17px;
    }
     
    .navbar a:hover {
      background: #ddd;
      color: black;
    }
     
    .main {
      padding: 16px;
      margin-top: 30px;
      height: 1500px; /* Used in this example to enable scrolling */
    }
    </style>
     
     
     
    </head>
     
     
    <body>
     
    <div class="navbar">
            <a onclick="jumpto('lnk_01');">section 1</a>
            <a onclick="jumpto('lnk_02');">section 2</a>
            <a onclick="jumpto('lnk_03');">section 3</a>
            <a onclick="jumpto('lnk_04');">section 4</a>
     
    </div>
     
    <div class="main">
            <div class="titlepage">
                <h1 id="lnk_01">section 1</h1>
            </div>
            <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.
    		</p>
     
            <div class="titlepage">
                <h1 id="lnk_02">section 2</h1>
            </div>
            <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.
    		</p>
     
    		        <div class="titlepage">
                <h1 id="lnk_03">section 3</h1>
            </div>
            <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.
    		</p>
     
    		        <div class="titlepage">
                <h1 id="lnk_04">section 4</h1>
            </div>
            <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.
    		</p>
     
    </div>
     
    </body>
    </html>

  2. #2
    Expert confirmé
    Avatar de Doksuri
    Profil pro
    Développeur Web
    Inscrit en
    Juin 2006
    Messages
    2 451
    Détails du profil
    Informations personnelles :
    Âge : 54
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Web

    Informations forums :
    Inscription : Juin 2006
    Messages : 2 451
    Points : 4 600
    Points
    4 600
    Par défaut
    Citation Envoyé par Madmac Voir le message
    Je sais que je suis proche de la solution
    Code javascript : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    function jumpto(h){
        var top = document.getElementById(h).offsetTop - 50; //Getting Y of target e
        window.scrollTo(0, top);                        //Go there directly or some transition
    }
    La forme des pyramides prouve que l'Homme a toujours tendance a en faire de moins en moins.

    Venez discuter sur le Chat de Développez !

  3. #3
    Membre extrêmement actif
    Avatar de Madmac
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Juin 2004
    Messages
    1 685
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Canada

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : Alimentation

    Informations forums :
    Inscription : Juin 2004
    Messages : 1 685
    Points : 1 376
    Points
    1 376
    Billets dans le blog
    7
    Par défaut
    Un grand merci ! J'ai un site complet qui dépendait de cette foutu fonction,

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Comment insérer un lien hypertexte sur une view?
    Par xXO--Hades--OXx dans le forum Composants graphiques
    Réponses: 2
    Dernier message: 20/01/2011, 18h52
  2. Intercepter un event non géré par un on(dbl)click sur une ancre
    Par Invité dans le forum Général JavaScript
    Réponses: 7
    Dernier message: 09/06/2010, 20h42
  3. Décalage VERTICAL sur un tableau avec IE6
    Par Msieurduss dans le forum Balisage (X)HTML et validation W3C
    Réponses: 3
    Dernier message: 29/01/2009, 19h29
  4. Mettre un intitulé sur une ancre
    Par Solly dans le forum Dreamweaver
    Réponses: 1
    Dernier message: 09/07/2008, 18h01
  5. Positionnement sur une ancre
    Par ghostdogpr dans le forum Balisage (X)HTML et validation W3C
    Réponses: 4
    Dernier message: 27/01/2006, 10h51

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