2015-08-05 3 views
0

Я пытаюсь создать динамический jssor вложенный слайдер, который будет отображать альбомы и связанные изображения из базы данных mySQL. Прямо сейчас, он отлично работает с одним альбомом, но когда в базе данных есть два или более альбома, оно отображается неправильно. Я относительно новичок в JavaScript и JQuery. Ниже мой код.Создание динамического вложенного слайдера Jssor

<div id="slider1_container" style="position: relative; top: 0px; left: 0px; width: 810px; height: 600px; background: #24262e; overflow: hidden; "> 
        <!-- Loading Screen --> 
        <div u="loading" style="position: absolute; top: 0px; left: 0px;"> 
         <div style="filter: alpha(opacity=70); opacity:0.7; position: absolute; display: block; 
          background-color: #000; top: 0px; left: 0px;width: 100%;height:100%;"> 
         </div> 
         <div style="position: absolute; display: block; background: url(img/loading.gif) no-repeat center center; 
          top: 0px; left: 0px;width: 100%;height:100%;"> 
         </div> 
        </div> 
        <!-- Slides Container --> 
        <div u="slides" style="cursor: move; position: absolute; left: 210px; top: 0px; width: 600px; height: 600px; 
         overflow: hidden;"> 
         <!-- beginning of PHP Loop --> 
         <?php 
         $q = mysql_query("select * from album"); 
         while($albumRes = mysql_fetch_array($q)) 
         { 
         $i = 1; 
         $divId = "sliderh" . $i . "_container"; 
         $divClass = "sliderh" . $i; 
         ?> 
         <div> 
          <div id="<?php echo $divId ?>" class="<?php echo $divClass ?>" style="position: relative; top: 0px; left: 0px; width: 600px; 
           height: 600px;"> 
           <!-- Slides Container --> 
           <div u="slides" style="cursor: move; position: absolute; left: 0px; top: 0px; width: 600px; height: 500px; 
            overflow: hidden;"> 
            <!-- Begin images loop --> 
            <?php 
            $img_query = mysql_query("select * from gallery_images where IMG_AB_ID='$albumRes[0]'"); 
            while($imageRes = mysql_fetch_array($img_query)) 
            { 
            ?> 
            <div> 
             <img u="image" src="<?php echo fix_directory($imageRes[2]) ?>" /> 
             <img u="thumb" src="<?php echo fix_directory($imageRes[2]) ?>" /> 
            </div> 
            <?php } ?> 
            <!-- End images loop --> 
           </div> 
           <!-- thumbnail navigator container (bottom row thumbnails)--> 
           <div u="thumbnavigator" class="jssort05" style="left: 0px; bottom: 0px;"> 
            <!-- Thumbnail Item Skin Begin --> 
            <div u="slides" style="cursor: default;"> 
             <div u="prototype" class="p"> 
              <div class="o"> 
               <div u="thumbnailtemplate" class="b"></div> 
               <div class="i"></div> 
               <div u="thumbnailtemplate" class="f"></div> 
              </div> 
             </div> 
            </div> 
            <!-- Thumbnail Item Skin End --> 
           </div> 
           <!--#endregion Bullet Navigator Skin End --> 
          </div> 
          <div u="thumb"> 
           <img src="<?php echo fix_directory($albumRes[3]) ?>" /> 
           <div class="title_back"></div> 
           <div class="title"> 
            <?php echo $albumRes[1]?> 
           </div> 
          </div> 
         </div> 
         <!-- End of Album Loop --> 
         <?php 
         $i = $i + 1; 
         } 
         ?> 
         </div>  <!--#region Thumbnail Navigator Skin Begin --> 
         <!-- Help: http://www.jssor.com/development/slider-with-thumbnail-navigator-jquery.html --> 
         <!-- thumbnail navigator container --> 
         <div u="thumbnavigator" class="jssort16" style="left: 0px; top: 0px;"> 
          <!-- Thumbnail Item Skin Begin --> 
          <div u="slides" style="cursor: default;"> 
           <div u="prototype" class=p> 
            <div u="thumbnailtemplate" class="t"></div> 
           </div> 
          </div> 
          <!-- Thumbnail Item Skin End --> 
         </div> 
         <!--#endregion Thumbnail Navigator Skin End 
         <a style="display: none" href="http://www.jssor.com">Bootstrap Slider</a>--> 
         <!-- Trigger --> 
         <script> 
         jssor_slider1_starter('slider1_container'); 
         </script> 
        </div> 
       </div> 
       <!-- Jssor Slider End --> 
       <?php 

       } //end else statement for page 2 (gallery page) 
       ?> 

Вот код сценария:

<script> 
       // get number of albums from DB and PHP 
       var div = document.getElementById("dom-target"); 
       var numAlbums = div.textContent; 
       // generate array for each function based on 
       var sliderArray = []; 
       for(var i = 0; i < numAlbums; i++) 
       { 
       // add first container 
       if(i === 0) 
       { 
       sliderArray.push("sliderh1_container"); 
       } 
       else // add any existing containers for albums after that 
       { 
       var num = i + 1; 
       var n = num.toString(); 
       sliderArray.push("sliderh" + n + "_container"); 
       } 
       // output to console for testing purposes 
       console.log(sliderArray); 
       } 
       jssor_slider1_starter = function (containerId) { 
       var nestedSliders = []; 
       $Jssor$.$Each(sliderArray, function (containerId) { 
       var nestedSliderOptions = { 
       $PauseOnHover: 1,        //[Optional] Whether to pause when mouse over if a slider is auto playing, 0 no pause, 1 pause for desktop, 2 pause for touch device, 3 pause for desktop and touch device, 4 freeze for desktop, 8 freeze for touch device, 12 freeze for desktop and touch device, default value is 1 
       $SlideDuration: 500,        //[Optional] Specifies default duration (swipe) for slide in milliseconds, default value is 500 
       $MinDragOffsetToSlide: 20,       //[Optional] Minimum drag offset to trigger slide , default value is 20 
       //$SlideWidth: 200,         //[Optional] Width of every slide in pixels, default value is width of 'slides' container 
       //$SlideHeight: 150,        //[Optional] Height of every slide in pixels, default value is height of 'slides' container 
       $SlideSpacing: 3,         //[Optional] Space between each slide in pixels, default value is 0 
       $Cols: 1,         //[Optional] Number of pieces to display (the slideshow would be disabled if the value is set to greater than 1), the default value is 1 
       $Align: 0,        //[Optional] The offset position to park slide (this options applys only when slideshow disabled), default value is 0. 
       $UISearchMode: 0,         //[Optional] The way (0 parellel, 1 recursive, default value is 1) to search UI components (slides container, loading screen, navigator container, arrow navigator container, thumbnail navigator container etc). 
       $ThumbnailNavigatorOptions: {      //[Optional] Options to specify and enable thumbnail navigator or not 
       $Class: $JssorThumbnailNavigator$,    //[Required] Class to create thumbnail navigator instance 
       $ChanceToShow: 2,        //[Required] 0 Never, 1 Mouse Over, 2 Always 
       $ActionMode: 1,         //[Optional] 0 None, 1 act by click, 2 act by mouse hover, 3 both, default value is 1 
       $SpacingX: 8,         //[Optional] Horizontal space between each thumbnail in pixel, default value is 0 
       $Cols: 10,        //[Optional] Number of pieces to display, default value is 1 
       $Align: 360       //[Optional] The offset position to park thumbnail 
       } 
       }; 
       nestedSliders.push(new $JssorSlider$(containerId, nestedSliderOptions)); 
       }); 
       var options = { 
       $AutoPlay: false,         //[Optional] Whether to auto play, to enable slideshow, this option must be set to true, default value is false 
       $AutoPlaySteps: 1,         //[Optional] Steps to go for each navigation request (this options applys only when slideshow disabled), the default value is 1 
       $AutoPlayInterval: 2000,       //[Optional] Interval (in milliseconds) to go for next slide since the previous stopped if the slider is auto playing, default value is 3000 
       $PauseOnHover: 1,        //[Optional] Whether to pause when mouse over if a slider is auto playing, 0 no pause, 1 pause for desktop, 2 pause for touch device, 3 pause for desktop and touch device, 4 freeze for desktop, 8 freeze for touch device, 12 freeze for desktop and touch device, default value is 1 
       $ArrowKeyNavigation: true,       //[Optional] Allows keyboard (arrow key) navigation or not, default value is false 
       $SlideDuration: 300,        //[Optional] Specifies default duration (swipe) for slide in milliseconds, default value is 500 
       $MinDragOffsetToSlide: 80,       //[Optional] Minimum drag offset to trigger slide , default value is 20 
       //$SlideWidth: 600,         //[Optional] Width of every slide in pixels, default value is width of 'slides' container 
       //$SlideHeight: 150,        //[Optional] Height of every slide in pixels, default value is height of 'slides' container 
       $SlideSpacing: 3,         //[Optional] Space between each slide in pixels, default value is 0 
       $Cols: 1,         //[Optional] Number of pieces to display (the slideshow would be disabled if the value is set to greater than 1), the default value is 1 
       $Align: 0,        //[Optional] The offset position to park slide (this options applys only when slideshow disabled), default value is 0. 
       $UISearchMode: 0,         //[Optional] The way (0 parellel, 1 recursive, default value is 1) to search UI components (slides container, loading screen, navigator container, arrow navigator container, thumbnail navigator container etc). 
       $PlayOrientation: 2,        //[Optional] Orientation to play slide (for auto play, navigation), 1 horizental, 2 vertical, 5 horizental reverse, 6 vertical reverse, default value is 1 
       $DragOrientation: 0,        //[Optional] Orientation to drag slide, 0 no drag, 1 horizental, 2 vertical, 3 either, default value is 1 (Note that the $DragOrientation should be the same as $PlayOrientation when $Cols is greater than 1, or parking position is not 0), 

       $ThumbnailNavigatorOptions: { 
       $Class: $JssorThumbnailNavigator$,    //[Required] Class to create thumbnail navigator instance 
       $ChanceToShow: 2,        //[Required] 0 Never, 1 Mouse Over, 2 Always 
       $ActionMode: 1,         //[Optional] 0 None, 1 act by click, 2 act by mouse hover, 3 both, default value is 1 
       $AutoCenter: 3,         //[Optional] Auto center thumbnail items in the thumbnail navigator container, 0 None, 1 Horizontal, 2 Vertical, 3 Both, default value is 3 
       $Rows: 1,          //[Optional] Specify lanes to arrange thumbnails, default value is 1 
       $SpacingX: 10,         //[Optional] Horizontal space between each thumbnail in pixel, default value is 0 
       $SpacingY: 10,         //[Optional] Vertical space between each thumbnail in pixel, default value is 0 
       $Cols: 3,        //[Optional] Number of pieces to display, default value is 1 
       $Align: 0,       //[Optional] The offset position to park thumbnail 
       $Orientation: 2,        //[Optional] Orientation to arrange thumbnails, 1 horizental, 2 vertical, default value is 1 
       $NoDrag: false       //[Optional] Disable drag or not, default value is false 
       } 
       }; 
       var jssor_slider1 = new $JssorSlider$(containerId, options); 
       function OnMainSliderPark(currentIndex, fromIndex) { 
       $Jssor$.$Each(nestedSliders, function (nestedSlider) { 
       nestedSlider.$Pause(); 
       }); 
       setTimeout(function() { 
       nestedSliders[currentIndex].$Play(); 
       }, 2000); 
       } 
       jssor_slider1.$On($JssorSlider$.$EVT_PARK, OnMainSliderPark); 
       OnMainSliderPark(0, 0); 
       //responsive code begin 
       //you can remove responsive code if you don't want the slider scales while window resizes 
       function ScaleSlider() { 
       var parentWidth = jssor_slider1.$Elmt.parentNode.clientWidth; 
       if (parentWidth) 
       jssor_slider1.$ScaleWidth(Math.min(parentWidth, 800)); 
       else 
       $Jssor$.$Delay(ScaleSlider, 30); 
       } 
       ScaleSlider(); 
       $Jssor$.$AddEvent(window, "load", ScaleSlider); 
       $Jssor$.$AddEvent(window, "resize", $Jssor$.$WindowResizeFilter(window, ScaleSlider)); 
       $Jssor$.$AddEvent(window, "orientationchange", ScaleSlider); 
       //responsive code end 
       }; 
       </script> 
+0

Что вы ожидаете от этого? Что происходит? – vonbrand

+0

Я ожидаю увидеть альбомы, отображаемые с левой стороны, что случается, когда присутствует один альбом. Однако, когда их несколько альбомов присутствуют, он не показывает ни одного из альбомов и просто показывает слайдер первого альбома, а также миниатюры. Я знаю, что это должно быть что-то действительно маленькое. Я просто не могу понять это. –

ответ

0

Ну ... Я думаю, что это любительский час, но я обнаружил, что, возможно, я не должен объявлять счетчик переменных внутри цикла. Дело закрыто.

 Смежные вопросы

  • Нет связанных вопросов^_^