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 :

Chercher nom d'une image avec js


Sujet :

JavaScript

Vue hybride

Message pr�c�dent Message pr�c�dent   Message suivant Message suivant
  1. #1
    Membre �clair� Avatar de BRUNO71
    Homme Profil pro
    Retrait�
    Inscrit en
    Janvier 2007
    Messages
    507
    D�tails du profil
    Informations personnelles :
    Sexe : Homme
    �ge : 62
    Localisation : France, Sa�ne et Loire (Bourgogne)

    Informations professionnelles :
    Activit� : Retrait�
    Secteur : Industrie

    Informations forums :
    Inscription : Janvier 2007
    Messages : 507
    Par d�faut Chercher nom d'une image avec js
    Bonjour � tous,

    Besoin de vos comp�tences en JS, pour information mon site fonctionne avec c# .net MVC...

    J'utilise le script suivant pour mes photos que j'ai obtenu ici.

    Ce script fonctionne tr�s bien....

    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
     
     
    <script>
        // configuration :
        // Définir le mode d'affichage des images par défaut
     
        $defaultViewMode = "normal"; // full, normal, original
        $tsMargin = 30; // première et dernière marge de vignette (pour une meilleure interaction du curseur)
        $scrollEasing = 600; // assouplissement du défilement (0 pour aucune atténuation)
        $scrollEasingType = "easeOutCirc"; // type d'accélération de défilement
        $thumbnailsContainerOpacity = 0.8; // opacité par défaut de la zone des vignettes
        $thumbnailsContainerMouseOutOpacity = 0; // opacité de la zone des vignettes à la souris
        $thumbnailsOpacity = 0.6; // vignettes opacité par défaut
        $nextPrevBtnsInitState = "show"; // Etat initial des boutons image suivant/précédent ("masquer" ou "afficher")
        $keyboardNavigation = "on"; // activer/désactiver la navigation au clavier ("on" ou "off")
     
        // cache vars
        $thumbnails_wrapper = $("#thumbnails_wrapper");
        $outer_container = $("#outer_container");
        $thumbScroller = $(".thumbScroller");
        $thumbScroller_container = $(".thumbScroller .container");
        $thumbScroller_content = $(".thumbScroller .content");
        $thumbScroller_thumb = $(".thumbScroller .thumb");
        $preloader = $("#preloader");
        $toolbar = $("#toolbar");
        $toolbar_a = $("#toolbar a");
        $bgimg = $("#bgimg");
        $img_title = $("#img_title");
        $nextImageBtn = $(".nextImageBtn");
        $prevImageBtn = $(".prevImageBtn");
     
        $(window).load(function () {
            $toolbar.data("imageViewMode", $defaultViewMode); // mode d'affichage par défaut
            if ($defaultViewMode == "full") {
                $toolbar_a.html("<img src='~/Photos/toolbar_n_icon.png' style='width: 50px; height: 50px' />").attr("onClick", "ImageViewMode('normal');return false").attr("title", "Minimize");
            } else {
            $toolbar_a.html("<img src='~/Photos/toolbar_fs_icon.png' style='width: 50px; height: 50px' />").attr("onClick", "ImageViewMode('full');return false").attr("title", "Maximize");
            }
            ShowHideNextPrev($nextPrevBtnsInitState);
            // scroller miniature
            $thumbScroller_container.css("marginLeft", $tsMargin + "px"); // ajouter de la marge
            sliderLeft = $thumbScroller_container.position().left;
            sliderWidth = $outer_container.width();
            $thumbScroller.css("width", sliderWidth);
            var totalContent = 0;
            fadeSpeed = 200;
     
            var $the_outer_container = document.getElementById("outer_container");
            var $placement = findPos($the_outer_container);
     
            $thumbScroller_content.each(function () {
                var $this = $(this);
                totalContent += $this.innerWidth();
                $thumbScroller_container.css("width", totalContent);
                $this.children().children().children(".thumb").fadeTo(fadeSpeed, $thumbnailsOpacity);
            });
     
            $thumbScroller.mousemove(function (e) {
                if ($thumbScroller_container.width() > sliderWidth) {
                    var mouseCoords = (e.pageX - $placement[1]);
                    var mousePercentX = mouseCoords / sliderWidth;
                    var destX = -((((totalContent + ($tsMargin * 2)) - (sliderWidth)) - sliderWidth) * (mousePercentX));
                    var thePosA = mouseCoords - destX;
                    var thePosB = destX - mouseCoords;
                    if (mouseCoords > destX) {
                        $thumbScroller_container.stop().animate({ left: -thePosA }, $scrollEasing, $scrollEasingType); //with easing
                    } else if (mouseCoords < destX) {
                        $thumbScroller_container.stop().animate({ left: thePosB }, $scrollEasing, $scrollEasingType); //with easing
                    } else {
                        $thumbScroller_container.stop();
                    }
                }
            });
     
            $thumbnails_wrapper.fadeTo(fadeSpeed, $thumbnailsContainerOpacity);
            $thumbnails_wrapper.hover(
                function () { // passer la souris sur (mouse over)
                    var $this = $(this);
                    $this.stop().fadeTo("slow", 1);
                },
                function () { // passer la souris (mouse out)
                    var $this = $(this);
                    $this.stop().fadeTo("slow", $thumbnailsContainerMouseOutOpacity);
                }
            );
     
            $thumbScroller_thumb.hover(
                function () { // passer la souris sur (mouse over)
                    var $this = $(this);
                    $this.stop().fadeTo(fadeSpeed, 1);
                },
                function () { // passer la souris (mouse out)
                    var $this = $(this);
                    $this.stop().fadeTo(fadeSpeed, $thumbnailsOpacity);
                }
            );
     
            // sur la fenêtre redimensionner l'image et réinitialiser le défilement des petites images
            $(window).resize(function () {
                FullScreenBackground("#bgimg", $bgimg.data("newImageW"), $bgimg.data("newImageH"));
                $thumbScroller_container.stop().animate({ left: sliderLeft }, 400, "easeOutCirc");
                var newWidth = $outer_container.width();
                $thumbScroller.css("width", newWidth);
                sliderWidth = newWidth;
                $placement = findPos($the_outer_container);
            });
     
            // charger la 1ère image
            var the1stImg = new Image();
            the1stImg.onload = CreateDelegate(the1stImg, theNewImg_onload);
            the1stImg.src = $bgimg.attr("src");
            $outer_container.data("nextImage", $(".content").first().next().find("a").attr("href"));
            $outer_container.data("prevImage", $(".content").last().find("a").attr("href"));
        });
     
        function BackgroundLoad($this, imageWidth, imageHeight, imgSrc) {
            $this.fadeOut("fast", function () {
                $this.attr("src", "").attr("src", imgSrc); // changer la source de l'image
                FullScreenBackground($this, imageWidth, imageHeight); // échelle image de fond
                $preloader.fadeOut("fast", function () { $this.fadeIn("slow"); });
                var imageTitle = $img_title.data("imageTitle");
                if (imageTitle) {
                    $this.attr("alt", imageTitle).attr("title", imageTitle);
                    $img_title.fadeOut("fast", function () {
                        $img_title.html(imageTitle).fadeIn();
                    });
                } else {
                    $img_title.fadeOut("fast", function () {
                        $img_title.html($this.attr("title")).fadeIn();
                    });
                }
            });
        }
     
        // barre d'outils mouseover
        if ($toolbar.css("display") != "none") {
            $toolbar.fadeTo("fast", 0.4);
        }
        $toolbar.hover(
            function () { // passer la souris sur (mouse over)
                var $this = $(this);
                $this.stop().fadeTo("fast", 1);
            },
            function () { // passer la souris (mouse out)
                var $this = $(this);
                $this.stop().fadeTo("fast", 0.4);
            }
        );
     
        // Cliquer sur la vignette change l'image d'arrière-plan
        $("#outer_container a").click(function (event) {
            event.preventDefault();
            var $this = $(this);
            GetNextPrevImages($this);
            GetImageTitle($this);
            SwitchImage(this);
            ShowHideNextPrev("show");
        });
     
        // boutons images suivantes / images précédentes
        $nextImageBtn.click(function (event) {
            event.preventDefault();
            SwitchImage($outer_container.data("nextImage"));
            var $this = $("#outer_container a[href='" + $outer_container.data("nextImage") + "']");
            GetNextPrevImages($this);
            GetImageTitle($this);
        });
     
        $prevImageBtn.click(function (event) {
            event.preventDefault();
            SwitchImage($outer_container.data("prevImage"));
            var $this = $("#outer_container a[href='" + $outer_container.data("prevImage") + "']");
            GetNextPrevImages($this);
            GetImageTitle($this);
        });
     
        // images suivantes / images précédentes flèches du clavier
        if ($keyboardNavigation == "on") {
            $(document).keydown(function (ev) {
                if (ev.keyCode == 39) { // flèche droite
                    SwitchImage($outer_container.data("nextImage"));
                    var $this = $("#outer_container a[href='" + $outer_container.data("nextImage") + "']");
                    GetNextPrevImages($this);
                    GetImageTitle($this);
                    return false; // n'exécute pas l'action par défaut (défilement ou autre)
                } else if (ev.keyCode == 37) { // Flèche gauche
                    SwitchImage($outer_container.data("prevImage"));
                    var $this = $("#outer_container a[href='" + $outer_container.data("prevImage") + "']");
                    GetNextPrevImages($this);
                    GetImageTitle($this);
                    return false; // n'exécute pas l'action par défaut(défilement ou autre)
                }
            });
        }
     
        function ShowHideNextPrev(state) {
            if (state == "hide") {
                $nextImageBtn.fadeOut();
                $prevImageBtn.fadeOut();
            } else {
                $nextImageBtn.fadeIn();
                $prevImageBtn.fadeIn();
            }
        }
     
        // obtenir le titre de l'image
        function GetImageTitle(elem) {
            var title_attr = elem.children("img").attr("title"); // obtenir l'attribut titre de l'image
            $img_title.data("imageTitle", title_attr); // titre de l'image du magasin
        }
     
        // obtenir les images suivantes / prev
        function GetNextPrevImages(curr) {
            var nextImage = curr.parents(".content").next().find("a").attr("href");
            if (nextImage == null) { // si dernière image, la suivante est la première
                var nextImage = $(".content").first().find("a").attr("href");
            }
            $outer_container.data("nextImage", nextImage);
            var prevImage = curr.parents(".content").prev().find("a").attr("href");
            if (prevImage == null) { // si première image, précédent est dernier
                var prevImage = $(".content").last().find("a").attr("href");
            }
            $outer_container.data("prevImage", prevImage);
        }
     
        // changer d'image
        function SwitchImage(img) {
            $preloader.fadeIn("fast"); // montrer le préchargement
            var theNewImg = new Image();
            theNewImg.onload = CreateDelegate(theNewImg, theNewImg_onload);
            theNewImg.src = img;
        }
     
        // obtenir de nouvelles dimensions d'image
        function CreateDelegate(contextObject, delegateMethod) {
            return function () {
                return delegateMethod.apply(contextObject, arguments);
            }
        }
     
        // nouvelle image en charge
        function theNewImg_onload() {
            $bgimg.data("newImageW", this.width).data("newImageH", this.height);
            BackgroundLoad($bgimg, this.width, this.height, this.src);
        }
     
        // Fonction d'échelle d'image
        function FullScreenBackground(theItem, imageWidth, imageHeight) {
            var winWidth = $(window).width();
            var winHeight = $(window).height();
            if ($toolbar.data("imageViewMode") != "original") { //scale
                var picHeight = imageHeight / imageWidth;
                var picWidth = imageWidth / imageHeight;
                if ($toolbar.data("imageViewMode") == "full") { // mode image plein écran
                    if ((winHeight / winWidth) < picHeight) {
                        $(theItem).attr("width", winWidth);
                        $(theItem).attr("height", picHeight * winWidth);
                    } else {
                        $(theItem).attr("height", winHeight);
                        $(theItem).attr("width", picWidth * winHeight);
                    };
                } else { // mode d'image de taille normale
                    if ((winHeight / winWidth) > picHeight) {
                        $(theItem).attr("width", winWidth);
                        $(theItem).attr("height", picHeight * winWidth);
                    } else {
                        $(theItem).attr("height", winHeight);
                        $(theItem).attr("width", picWidth * winHeight);
                    };
                }
                $(theItem).css("margin-left", (winWidth - $(theItem).width()) / 2);
                $(theItem).css("margin-top", (winHeight - $(theItem).height()) / 2);
            } else { // pas d'échelle
                $(theItem).attr("width", imageWidth);
                $(theItem).attr("height", imageHeight);
                $(theItem).css("margin-left", (winWidth - imageWidth) / 2);
                $(theItem).css("margin-top", (winHeight - imageHeight) / 2);
            }
        }
     
        // Fonction de mode de visualisation d'image - plein écran ou taille normale
        function ImageViewMode(theMode) {
            $toolbar.data("imageViewMode", theMode);
            FullScreenBackground($bgimg, $bgimg.data("newImageW"), $bgimg.data("newImageH"));
            if (theMode == "full") {
                $toolbar_a.html("<img src='~/Photos/toolbar_n_icon.png' style='width: 50px; height: 50px' />").attr("onClick", "ImageViewMode('normal');return false").attr("title", "Minimize");
            } else {
                $toolbar_a.html("<img src='~/Photos/toolbar_fs_icon.png' style='width: 50px; height: 50px' />").attr("onClick", "ImageViewMode('full');return false").attr("title", "Maximize");
            }
        }
     
        // fonction pour trouver l'élément Position
        function findPos(obj) {
            var curleft = curtop = 0;
            if (obj.offsetParent) {
                curleft = obj.offsetLeft
                curtop = obj.offsetTop
                while (obj = obj.offsetParent) {
                    curleft += obj.offsetLeft
                    curtop += obj.offsetTop
                }
            }
            return [curtop, curleft];
        }
     
     
    </script>
    Chaque image porte un num�ro de 1 � 20, j'aimerai adapter une musique mp3 au moment ou l'image 4 d�file sur l'�cran !

    Est-ce possible, si oui comment ?

    Quel fonction uitliser ?

    Merci � vous,

    Bruno

  2. #2
    Membre �clair� Avatar de BRUNO71
    Homme Profil pro
    Retrait�
    Inscrit en
    Janvier 2007
    Messages
    507
    D�tails du profil
    Informations personnelles :
    Sexe : Homme
    �ge : 62
    Localisation : France, Sa�ne et Loire (Bourgogne)

    Informations professionnelles :
    Activit� : Retrait�
    Secteur : Industrie

    Informations forums :
    Inscription : Janvier 2007
    Messages : 507
    Par d�faut
    Je pensais avoir r�solu ma question, mais il n'en est rien.
    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
     
     
    <script>
     
        function connect(oElem, sEvType, fn, bCapture) {
            return document.addEventListener ?
                oElem.addEventListener(sEvType, fn, bCapture) :
                oElem.attachEvent ?
                    oElem.attachEvent('on' + sEvType, fn) :
                    false;
        }
     
        function chargerFonction() {
            if (document.getElementById('Son_MP3'))
                return document.getElementById('Son_MP3').onclick = recupId;
     
               return alert("Inconnu");
     
        }
     
        function recupId() {
            if (this.id)
     
                   return alert(this.id);
     
            return false;
        }
     
        connect(window, 'load', chargerFonction, false);
     
    </script>
    J'aimerai r�cup�rer l'ID de de l'image qui d�file � l'�cran...car si on s�lectionne la miniature ok je trouve son id..
    Mais si l'image est s�lectionn�e depuis les fl�ches suivant et pr�c�dent..dans ce cas �a ne marche pas...


    Avec la portion de code ci-dessous, peuton r�cup�rer l'id de l'image qui est sur l'�cran ?

    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
     
     
       // obtenir les images suivantes / prev
        function GetNextPrevImages(curr) {
            var nextImage = curr.parents(".content").next().find("a").attr("href");
            if (nextImage == null) { // si dernière image, la suivante est la première
                var nextImage = $(".content").first().find("a").attr("href");
            }
            $outer_container.data("nextImage", nextImage);
            var prevImage = curr.parents(".content").prev().find("a").attr("href");
            if (prevImage == null) { // si première image, précédent est dernier
                var prevImage = $(".content").last().find("a").attr("href");
            }
            $outer_container.data("prevImage", prevImage);
        }
     
        // changer d'image
        function SwitchImage(img) {
            $preloader.fadeIn("fast"); // montrer le préchargement
            var theNewImg = new Image();
            theNewImg.onload = CreateDelegate(theNewImg, theNewImg_onload);
            theNewImg.src = img;
        }
    Comment faire ?

    Merci � vous,

Discussions similaires

  1. R�ponses: 4
    Dernier message: 16/01/2007, 19h48
  2. [Access] Nom d'une table avec un espace dans SQL
    Par Corsaire dans le forum Langage SQL
    R�ponses: 7
    Dernier message: 21/04/2006, 15h50
  3. Afficher une image avec swing
    Par arnonote dans le forum AWT/Swing
    R�ponses: 11
    Dernier message: 07/08/2004, 12h10
  4. [D�butante] Cr�ation d'une image avec un composant
    Par gwendo dans le forum AWT/Swing
    R�ponses: 9
    Dernier message: 09/07/2004, 09h58
  5. PL/SQL - Comment afficher une image avec HTP ?
    Par patmaba dans le forum PL/SQL
    R�ponses: 2
    Dernier message: 08/07/2004, 09h28

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