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

Contribuez Discussion :

Défilement d'élements [4 sens]


Sujet :

Contribuez

  1. #1
    Expert confirmé
    Avatar de le_chomeur
    Profil pro
    Développeur informatique
    Inscrit en
    Février 2006
    Messages
    3 653
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Février 2006
    Messages : 3 653
    Points : 4 835
    Points
    4 835
    Par défaut Défilement d'élements [4 sens]
    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
    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
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
     
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <style type="text/css">
        .slideIn{
            overflow:hidden;
            width:500px;
            height:300px;
            background-color:#FFFFFF;
            border:1px solid #000000;
            position:relative;
        }
        .slideIn div{
            width:458px;
            height:258px;
            border:1px dashed #666;
            position:absolute;
            display:none;
            margin:20px;
        }
    </style>
    <script type="text/javascript">
     
    var SlideIn = function(){
        //Variable globale
        this.idObj = null;
        this.timer = null;
        this.from = null;
        this.to = null;
        this.direction = null;
        //Tableau d'élément a déplacé
        this.elementToSlide = new Array();
        //Index de l'élément en cours
        this.currentIndex = 0;
        //Paramètre pour lancement automatique
        this.timePause = 0 ; //permet de définir le temps de pause entre deux slide
        this.auto = false ; //Permet d'activer ou non le slide automatique
        }
     
        /*##########################################################
        ####################  On ajoute les méthodes sur l'objet  ###################
        ##########################################################*/
        //Permet de récupérer un élément par id
        SlideIn.prototype.$ = function(element){
            return document.getElementById(element);
        };
     
        //Méthode permettant de lancer les animations si en auto :)
        SlideIn.prototype.go = function(){
            if(this.auto){
                switch (this.direction ){
                    case 'left':
                        this.SlideToLeft();
                    break;
                    case 'right':
                        this.SlideToRight();
                    break;
                    case 'top':
                        this.SlideToTop();
                    break;
                    case 'bottom':
                        this.SlideToBottom();
                    break;
                }
            }
        }
     
        //Méthode permettant d'ajouter un élément
        SlideIn.prototype.AddElement = function(element){
            if(typeof(element) == "string"){
                this.elementToSlide.push(this.$(element));
            }
            else if(typeof(element) == "object"){
                this.elementToSlide.push(element);
            }
        }
     
        //Méthode permettant d'ajouter plusieurs élément d'un coup
        SlideIn.prototype.AddElements = function (elements){
            for(var i = 0 , l = elements.length; i < l ;i++){
                this.AddElement(elements[i]);
            }
        }
     
        //Méthode permettant de déplacer les éléments vers la gauche
        SlideIn.prototype.SlideToLeft = function(){
            if(this.direction == null || this.direction == 'left'){
                var me = this ;
                //On vérifit la direction pour initialiser le positionnement
                if(this.direction != 'left'){
                        this.direction = 'left';
                        if(this.timer == null){
                            this.Positionne();
                        }
                }
                else if(this.direction == 'left' && this.auto && this.timer == null){
                    this.Positionne();
                }
     
                if(this.timer != null){
                    clearTimeout(this.timer);
                    this.timer = null;
                }
                //Si le timer n'est pas finit on détruit l'ancienne div
                if(parseInt(this.from.style.left) == Number.NaN || (parseInt(this.from.parentNode.offsetWidth) + parseInt(this.from.style.left))> 0){
                    this.from.style.left = parseInt(this.from.style.left) - 15 + "px";
                    this.to.style.left  =parseInt(this.to.style.left) - 15 + "px";
                    //alert((parseInt(this.$(from).offsetWidth) + parseInt(this.$(from).style.left)));
                    this.timer = setTimeout(function(){me.SlideToLeft()},25);
                }
                else{
                    clearTimeout(this.timer);
                    this.timer = null;
                    this.currentIndex = (this.currentIndex == (this.elementToSlide.length-1)) ? 0:this.currentIndex + 1;
                    this.$('debug').innerHTML = this.currentIndex;
                    this.Positionne();
                    if(this.auto){
                        setTimeout(function(){me.SlideToLeft()},this.timePause);
                    }
                    else{
                        this.direction = null;
                    }
                }
            }
        };
     
        //Méthode permettant de déplacer les éléments vers la droite
        SlideIn.prototype.SlideToRight = function(){
            var me = this ;
            if(this.direction == null || this.direction == 'right'){
                    if(this.direction != 'right'){
                        this.direction = 'right';
                        if(this.timer == null){
                            this.Positionne();
                        }
                    }
                    else if(this.direction == 'right' && this.auto && this.timer == null){
                        this.Positionne();
                    }
     
                    if(this.timer != null){
                        clearTimeout(this.timer);
                        this.timer = null;
                    }
                    //Si le timer n'est pas finit on détruit l'ancienne div
                    if(parseInt(this.from.style.left) == Number.NaN ||  parseInt(this.from.style.left) < parseInt(this.from.parentNode.offsetWidth)){
                        this.from.style.left = parseInt(this.from.style.left) + 15 + "px";
                        this.to.style.left  =parseInt(this.to.style.left) + 15 + "px";
                        //alert((parseInt(this.$(from).offsetWidth) + parseInt(this.$(from).style.left)));
                        this.timer = setTimeout(function(){me.SlideToRight()},25);
                    }
                    else{
                        clearTimeout(this.timer);
                        this.timer = null;
                        this.currentIndex = (this.currentIndex == 0) ? this.elementToSlide.length-1:this.currentIndex - 1;
                        this.$('debug').innerHTML = this.currentIndex;
                        this.Positionne();
                        if(this.auto){
                            setTimeout(function(){me.SlideToRight()},this.timePause);
                        }
                        else{
                            this.direction = null;
                        }
                    }
            }
     
     
        };
     
        //Méthode permettant de déplacer les éléments vers la gauche
        SlideIn.prototype.SlideToTop = function(){
            var me = this ;
            if(this.direction == null || this.direction == 'top'){
                //On vérifit la direction pour initialiser le positionnement
                if(this.direction != 'top'){
                        this.direction = 'top';
                        if(this.timer == null){
                            this.Positionne();
                        }
                }
                if(this.timer != null){
                    clearTimeout(this.timer);
                    this.timer = null;
                }
                //Si le timer n'est pas finit on détruit l'ancienne div
                if(parseInt(this.from.style.top) == Number.NaN || (parseInt(this.from.style.top) > - parseInt(this.from.parentNode.offsetHeight))){
                    this.from.style.top = parseInt(this.from.style.top) - 15 + "px";
                    this.to.style.top  =parseInt(this.to.style.top) - 15 + "px";
                    this.timer = setTimeout(function(){me.SlideToTop()},25);
                }
                else{
                    clearTimeout(this.timer);
                    this.timer = null;
                    this.currentIndex = (this.currentIndex == 0) ? this.elementToSlide.length-1:this.currentIndex - 1;
                    this.$('debug').innerHTML = this.currentIndex;
                    this.Positionne();                    
                    if(this.auto){
                        setTimeout(function(){me.SlideToTop()},this.timePause);
                    }
                    else{
                        this.direction = null;
                    }
                }
            }
        };
     
        //Méthode permettant de déplacer les éléments vers le bas
        SlideIn.prototype.SlideToBottom = function(){
            var me = this 
            if(this.direction == null || this.direction == 'bottom'){
                //On vérifit la direction pour initialiser le positionnement
                if(this.direction != 'bottom'){
                        this.direction = 'bottom';
                        if(this.timer == null){
                            this.Positionne();
                        }
                }
                if(this.timer != null){
                    clearTimeout(this.timer);
                    this.timer = null;
                }
                //Si le timer n'est pas finit on détruit l'ancienne div
                if(parseInt(this.from.style.top) == Number.NaN || parseInt(this.from.style.top) < parseInt(this.from.parentNode.offsetHeight)){
                    this.from.style.top = parseInt(this.from.style.top) + 15 + "px";
                    this.to.style.top  =parseInt(this.to.style.top) + 15 + "px";
                    ;
                    this.timer = setTimeout(function(){me.SlideToBottom()},25);
                }
                else{
                    clearTimeout(this.timer);
                    this.timer = null;
                    this.currentIndex = (this.currentIndex == this.elementToSlide.length-1) ? 0:this.currentIndex + 1;
                    this.$('debug').innerHTML = this.currentIndex;
                    this.Positionne();
                    if(this.auto){
                        setTimeout(function(){me.SlideToBottom()},this.timePause);
                    }
                    else{
                        this.direction = null;
                    }
                }
            }
        };
     
        //Fonction initialisant le tableau en positionnant tous les éléments :)
        SlideIn.prototype.Positionne = function(){
            if(this.direction == 'left'){
                //On vérifit que l'on est pas a la fin sinon le premier devient le dernier
                if(this.currentIndex == this.elementToSlide.length-1){
                    //récupération des éléments : 
                    this.from = this.elementToSlide[this.currentIndex];
                    this.to = this.elementToSlide[0]; //Premier élément
                }
                else{
                    this.from = this.elementToSlide[this.currentIndex];
                    this.to = this.elementToSlide[this.currentIndex + 1];
                }
                    this.from.style.display = "block" ;
                    this.from.style.left = 0 + "px";
                    this.to.style.left = this.from.parentNode.offsetWidth + "px";
                    this.to.style.display = "block";
                    //Posionement vertical
                    this.to.style.top = 0 + "px";
                    this.from.style.top = 0 + "px" ;
            }
            else if(this.direction == 'right'){
                if(this.currentIndex == 0){
                    this.from = this.elementToSlide[this.currentIndex];
                    this.to = this.elementToSlide[this.elementToSlide.length-1]; // dernier élément
                }
                else{
                    this.from = this.elementToSlide[this.currentIndex];
                    this.to = this.elementToSlide[this.currentIndex-1];
                }
                this.from.style.display = "block" ;
                this.from.style.left = 0 + "px";
                this.to.style.left = - (this.from.parentNode.offsetWidth )+ "px";
                this.to.style.display = "block";
                //Posionement vertical
                this.to.style.top = 0 + "px";
                this.from.style.top = 0 + "px" ;
            }
            else if(this.direction == 'bottom'){
                if(this.currentIndex == this.elementToSlide.length-1){
                    this.from = this.elementToSlide[this.currentIndex];
                    this.to = this.elementToSlide[0]; // dernier élément
                }
                else{
                    this.from = this.elementToSlide[this.currentIndex];
                    this.to = this.elementToSlide[this.currentIndex+1];
                }
                this.from.style.display = "block" ;
                this.from.style.top = 0 + "px";
                this.to.style.top = - (this.from.parentNode.offsetHeight )+ "px";
                this.to.style.display = "block";
                //Posionement horizontal
                this.to.style.left = 0 + "px";
                this.from.style.left = 0 + "px" ;
            }
            else if(this.direction == 'top'){
                if(this.currentIndex == 0){
                    this.from = this.elementToSlide[this.currentIndex];
                    this.to = this.elementToSlide[this.elementToSlide.length-1]; // dernier élément
                }
                else{
                    this.from = this.elementToSlide[this.currentIndex];
                    this.to = this.elementToSlide[this.currentIndex-1];
                }
                this.from.style.display = "block" ;
                this.from.style.top = 0 + "px";
                this.to.style.top = (this.from.parentNode.offsetHeight )+ "px";
                this.to.style.display = "block";
                //Posionement horizontal
                this.to.style.left = 0 + "px";
                this.from.style.left = 0 + "px" ;
            }
        };
    </script>
    </head>
    <body>
     
    <div class="slideIn">
        <div id="la1" style="background-color:#FFFFFF;display:block">la première</div>
        <div id="la2" style="background-color:blue;">la</div>
        <div id="la3" style="background-color:#ccc;">la</div>
        <div id="la4" style="background-color:yellow;">la jolie</div>
        <div id="la5" style="background-color:black;">la</div>
        <div id="la6" style="background-color:pink;">la 6 eme</div>
    </div>
    <input type="button" value="gauche" onclick="newSlide.SlideToLeft()">
    <input type="button" value="droite" onclick="newSlide.SlideToRight()">
    <input type="button" value="Top" onclick="newSlide.SlideToTop()">
    <input type="button" value="Bottom" onclick="newSlide.SlideToBottom()">
    <input type="button" value="Auto : on" onclick="newSlide.auto = (newSlide.auto) ? false:true;(!newSlide.auto) ?this.value='auto : off':this.value='auto : on'">
    <span id="debug"></span>
     
     
    <script type="text/javascript">
    //On instancie un slide
    var newSlide = new SlideIn();
    //On ajoute les éléments souhaités ( ici un tableau )  on peut utiliser la méthode AddElement pour ajouter un seul élément. on peut ajouter un id ou directement l'élément ;-)
    newSlide.AddElements(Array('la1','la2','la3','la4','la5',document.getElementById('la6')));
    //On définit le temps de pause entre deux slide
    newSlide.timePause = 2000;
    //On passe auto a true
    newSlide.auto = true;
    //On indique la direction souhaité
    newSlide.direction = 'left';
    //On lance :-)
    newSlide.go();
    </script>
    </body>
    </html>
    plutôt qu'un long discours voici une démo :

    - copier/coller cette source
    - au démarrage j'ai instancié l'objet et déclaré en défilement automatique a gauche
    - cliquez sur auto on pour arrêter le défilement auto
    - cliquez sur n'importe quel bouton pour faire défiler dans le sens voulu
    - re cliquez sur auto-off pour réactiver le défilement auto, puis n'importe quelle direction pour lancer


    une dédicace spéciale a Auteur qui est a l'origine du premier script

  2. #2
    Rédacteur/Modérateur

    Avatar de SpaceFrog
    Homme Profil pro
    Développeur Web Php Mysql Html Javascript CSS Apache - Intégrateur - Bidouilleur SharePoint
    Inscrit en
    Mars 2002
    Messages
    39 640
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 74
    Localisation : Royaume-Uni

    Informations professionnelles :
    Activité : Développeur Web Php Mysql Html Javascript CSS Apache - Intégrateur - Bidouilleur SharePoint
    Secteur : Industrie

    Informations forums :
    Inscription : Mars 2002
    Messages : 39 640
    Points : 66 663
    Points
    66 663
    Billets dans le blog
    1
    Par défaut
    On s'y perd dans la navigation ...

    Par contre j'imagine bien ça avec à coté les thumbs d'images placés en damier et un cadre rouge autour de l'image que l'on visualise ...

    Tu peux nous faire ça fillot ?

  3. #3
    Expert confirmé
    Avatar de le_chomeur
    Profil pro
    Développeur informatique
    Inscrit en
    Février 2006
    Messages
    3 653
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Février 2006
    Messages : 3 653
    Points : 4 835
    Points
    4 835
    Par défaut
    on s'y perd vi mais la j'ai mis les 4 directions pour montrer que ça fonctionnait et que c'était géré dans tous les sens

    par contre pas très très bien compris le principe du thumb et de mon apli tu pourrais imagé ?

  4. #4
    Rédacteur/Modérateur

    Avatar de SpaceFrog
    Homme Profil pro
    Développeur Web Php Mysql Html Javascript CSS Apache - Intégrateur - Bidouilleur SharePoint
    Inscrit en
    Mars 2002
    Messages
    39 640
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 74
    Localisation : Royaume-Uni

    Informations professionnelles :
    Activité : Développeur Web Php Mysql Html Javascript CSS Apache - Intégrateur - Bidouilleur SharePoint
    Secteur : Industrie

    Informations forums :
    Inscription : Mars 2002
    Messages : 39 640
    Points : 66 663
    Points
    66 663
    Billets dans le blog
    1
    Par défaut
    Cf image jointe
    l'ecran sert de visionneuse et les thumbs sont la bibliothèque ...
    le cadre rouge = image actuellement visible
    Images attachées Images attachées  

  5. #5
    Expert confirmé
    Avatar de le_chomeur
    Profil pro
    Développeur informatique
    Inscrit en
    Février 2006
    Messages
    3 653
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Février 2006
    Messages : 3 653
    Points : 4 835
    Points
    4 835
    Par défaut
    et on déplace la bibliothèque ?
    ( si oui c'est en cours )

  6. #6
    Rédacteur/Modérateur

    Avatar de SpaceFrog
    Homme Profil pro
    Développeur Web Php Mysql Html Javascript CSS Apache - Intégrateur - Bidouilleur SharePoint
    Inscrit en
    Mars 2002
    Messages
    39 640
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 74
    Localisation : Royaume-Uni

    Informations professionnelles :
    Activité : Développeur Web Php Mysql Html Javascript CSS Apache - Intégrateur - Bidouilleur SharePoint
    Secteur : Industrie

    Informations forums :
    Inscription : Mars 2002
    Messages : 39 640
    Points : 66 663
    Points
    66 663
    Billets dans le blog
    1
    Par défaut
    ben tu déplaces la cadre et tu affiches l'image dans le cadre de visu

  7. #7
    Expert confirmé
    Avatar de le_chomeur
    Profil pro
    Développeur informatique
    Inscrit en
    Février 2006
    Messages
    3 653
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Février 2006
    Messages : 3 653
    Points : 4 835
    Points
    4 835
    Par défaut
    voici une démo de ce a quoi peut servir l'appli
    Fichiers attachés Fichiers attachés

  8. #8
    Rédacteur/Modérateur

    Avatar de SpaceFrog
    Homme Profil pro
    Développeur Web Php Mysql Html Javascript CSS Apache - Intégrateur - Bidouilleur SharePoint
    Inscrit en
    Mars 2002
    Messages
    39 640
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 74
    Localisation : Royaume-Uni

    Informations professionnelles :
    Activité : Développeur Web Php Mysql Html Javascript CSS Apache - Intégrateur - Bidouilleur SharePoint
    Secteur : Industrie

    Informations forums :
    Inscription : Mars 2002
    Messages : 39 640
    Points : 66 663
    Points
    66 663
    Billets dans le blog
    1
    Par défaut
    presque ...
    en fait c'est la visonneuse qui devrait se deplacer, pas les thumbs ...
    seul le cadre se deplace sur les thumbs

  9. #9
    Membre habitué Avatar de DiDieuh
    Étudiant
    Inscrit en
    Juillet 2009
    Messages
    111
    Détails du profil
    Informations personnelles :
    Âge : 35

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juillet 2009
    Messages : 111
    Points : 141
    Points
    141
    Par défaut
    J'aime bien l'effet c'est marrant

Discussions similaires

  1. Réponses: 19
    Dernier message: 07/10/2013, 23h02
  2. [JScrollPane]Bloquer le défilement dans un sens
    Par benlaug dans le forum Composants
    Réponses: 4
    Dernier message: 09/08/2011, 10h26
  3. TRichEdit défilement de texte automatique
    Par bloops dans le forum C++Builder
    Réponses: 2
    Dernier message: 11/06/2003, 11h13
  4. [Syntaxe] Action simultanée sur plusieurs élements
    Par FranT dans le forum Composants VCL
    Réponses: 2
    Dernier message: 20/03/2003, 20h20
  5. Barre de défilement
    Par GO dans le forum Composants VCL
    Réponses: 2
    Dernier message: 26/01/2003, 17h40

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