2015-10-20 69 views
-1

我有使用jquery.jcarousel.min.js準備的圖像的幻燈片放映。
現在在同一頁面上我想要複製相同的幻燈片。如何在同一頁面上覆制幻燈片放映?

下面

是我代碼

<div class="connected-carousels"> 
      <div class="stage"> 
       <div class="carousel carousel-stage" data-jcarousel="true"> 
       <ul style="left: 0px; top: 0px;"> 
         <li><img src="http://localhost/classapp/Images/Jsc/img/img1.jpg" width="600" height="400" alt=""></li> 
       <li><img src="http://localhost/classapp/Images/Jsc/img/img2.jpg" width="600" height="400" alt=""></li> 
       <li><img src="http://localhost/classapp/Images/Jsc/img/img3.jpg" width="600" height="400" alt=""></li> 
       <li><img src="http://localhost/classapp/Images/Jsc/img/img4.jpg" width="600" height="400" alt=""></li> 
       <li><img src="http://localhost/classapp/Images/Jsc/img/img5.jpg" width="600" height="400" alt=""></li> 
       <li><img src="http://localhost/classapp/Images/Jsc/img/img6.jpg" width="600" height="400" alt=""></li> 
       </ul> 
       </div> 
       <p class="photo-credits"> 
        Photos by <a href="http://www.mw-fotografie.de">Marc Wiegelmann</a> 
       </p> 
       <a href="#" class="prev prev-stage inactive" data-jcarouselcontrol="true"><span>‹</span></a> 
       <a href="#" class="next next-stage" data-jcarouselcontrol="true"><span>›</span></a> 
      </div> 

      <div class="navigation"> 
       <a href="#" class="prev prev-navigation inactive" data-jcarouselcontrol="true">‹</a> 
       <a href="#" class="next next-navigation" data-jcarouselcontrol="true">›</a> 
       <div class="carousel carousel-navigation" data-jcarousel="true"> 
        <ul style="left: 0px; top: 0px;"> 
        <li data-jcarouselcontrol="true" class="active"> 
<img src="http://localhost/classapp/Images/Jsc/img/img1_thumb.jpg" width="50" height="50" alt=""></li> 
       <li data-jcarouselcontrol="true"> 
<img src="http://localhost/classapp/Images/Jsc/img/img2_thumb.jpg" width="50" height="50" alt=""></li> 
       <li data-jcarouselcontrol="true"> 
<img src="http://localhost/classapp/Images/Jsc/img/img3_thumb.jpg" width="50" height="50" alt=""></li> 
       <li data-jcarouselcontrol="true"> 
<img src="http://localhost/classapp/Images/Jsc/img/img4_thumb.jpg" width="50" height="50" alt=""></li> 
       <li data-jcarouselcontrol="true"> 
<img src="http://localhost/classapp/Images/Jsc/img/img5_thumb.jpg" width="50" height="50" alt=""></li> 
       <li data-jcarouselcontrol="true"> 
<img src="http://localhost/classapp/Images/Jsc/img/img6_thumb.jpg" width="50" height="50" alt=""></li> 

     </ul> 
    </div> 
    </div> 
</div> 

我的javascript代碼

JS使用jquery.jcarousel.min.js

<script language="javascript"> 
var connector = function(itemNavigation, carouselStage) { 
    return carouselStage.jcarousel('items').eq(itemNavigation.index()); 
}; 

function ShowJsSlideShow() 
{ 
    // Setup the carousels. Adjust the options for both carousels here. 
    var carouselStage  = $('.carousel-stage').jcarousel(); 
    var carouselNavigation = $('.carousel-navigation').jcarousel(); 

    // We loop through the items of the navigation carousel and set it up 
    // as a control for an item from the stage carousel. 
    carouselNavigation.jcarousel('items').each(function() { 
     var item = $(this); 

     // This is where we actually connect to items. 
     var target = connector(item, carouselStage); 

     item 
      .on('jcarouselcontrol:active', function() { 
       carouselNavigation.jcarousel('scrollIntoView', this); 
       item.addClass('active'); 
      }) 
      .on('jcarouselcontrol:inactive', function() { 
       item.removeClass('active'); 
      }) 
      .jcarouselControl({ 
       target: target, 
       carousel: carouselStage 
      }); 
    }); 

    // Setup controls for the stage carousel 
    $('.prev-stage') 
     .on('jcarouselcontrol:inactive', function() { 
      $(this).addClass('inactive'); 
     }) 
     .on('jcarouselcontrol:active', function() { 
      $(this).removeClass('inactive'); 
     }) 
     .jcarouselControl({ 
      target: '-=1' 
     }); 

    $('.next-stage') 
     .on('jcarouselcontrol:inactive', function() { 
      $(this).addClass('inactive'); 
     }) 
     .on('jcarouselcontrol:active', function() { 
      $(this).removeClass('inactive'); 
     }) 
     .jcarouselControl({ 
      target: '+=1' 
     }); 

    // Setup controls for the navigation carousel 
    $('.prev-navigation') 
     .on('jcarouselcontrol:inactive', function() { 
      $(this).addClass('inactive'); 
     }) 
     .on('jcarouselcontrol:active', function() { 
      $(this).removeClass('inactive'); 
     }) 
     .jcarouselControl({ 
      target: '-=1' 
     }); 

    $('.next-navigation') 
     .on('jcarouselcontrol:inactive', function() { 
      $(this).addClass('inactive'); 
     }) 
     .on('jcarouselcontrol:active', function() { 
      $(this).removeClass('inactive'); 
     }) 
     .jcarouselControl({ 
      target: '+=1' 
     }); 
} 
$(document).ready(function() { 
    ShowJsSlideShow(); 
}); 
    </script> 

是可以對同一拉同樣的網頁使用jQuery而不需要在服務器上的代碼方

+0

你需要上傳你的照片,不是來自PC的文件位置,互聯網不能像那樣工作。 –

+0

您可以在創建「幻燈片放映」的位置分享您的JavaScript代碼嗎? – Reza

回答

0

你可以試試。你必須糾正圖像位置,然後像你一樣編輯它。可能這會幫助你。請在你的頭文件中連接Bootstrap CDN。我認爲這就夠了。

<p> 1st carousel </p> 
<div class="1st_carousel_slider"> 
    <div id="carousel-example-generic" class="carousel slide" data-ride="carousel"> 
     <!-- Indicators --> 
     <ol class="carousel-indicators"> 
      <li data-target="#carousel-example-generic" data-slide-to="0" class="active"></li> 
      <li data-target="#carousel-example-generic" data-slide-to="1"></li> 
      <li data-target="#carousel-example-generic" data-slide-to="2"></li> 
     </ol> 

     <!-- Wrapper for slides --> 
     <div class="carousel-inner" role="listbox"> 
      <div class="item active"> 
       <img src="..." alt="..."> 
       <div class="carousel-caption"> 
        ... 
       </div> 
      </div> 
      <div class="item"> 
       <img src="..." alt="..."> 
       <div class="carousel-caption"> 
        ... 
       </div> 
      </div> 
      ... 
     </div> 

     <!-- Controls --> 
     <a class="left carousel-control" href="#carousel-example-generic" role="button" data-slide="prev"> 
      <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span> 
      <span class="sr-only">Previous</span> 
     </a> 
     <a class="right carousel-control" href="#carousel-example-generic" role="button" data-slide="next"> 
      <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span> 
      <span class="sr-only">Next</span> 
     </a> 
    </div> 
</div> 
<p> 2nd carousel </p> 
<div class="2st_carousel_slider"> 
    <div id="carousel-example-generic" class="carousel slide" data-ride="carousel"> 
     <!-- Indicators --> 
     <ol class="carousel-indicators"> 
      <li data-target="#carousel-example-generic" data-slide-to="0" class="active"></li> 
      <li data-target="#carousel-example-generic" data-slide-to="1"></li> 
      <li data-target="#carousel-example-generic" data-slide-to="2"></li> 
     </ol> 

     <!-- Wrapper for slides --> 
     <div class="carousel-inner" role="listbox"> 
      <div class="item active"> 
       <img src="..." alt="..."> 
       <div class="carousel-caption"> 
        ... 
       </div> 
      </div> 
      <div class="item"> 
       <img src="..." alt="..."> 
       <div class="carousel-caption"> 
        ... 
       </div> 
      </div> 
      ... 
     </div> 

     <!-- Controls --> 
     <a class="left carousel-control" href="#carousel-example-generic" role="button" data-slide="prev"> 
      <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span> 
      <span class="sr-only">Previous</span> 
     </a> 
     <a class="right carousel-control" href="#carousel-example-generic" role="button" data-slide="next"> 
      <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span> 
      <span class="sr-only">Next</span> 
     </a> 
    </div> 
</div> 

,並請關閉您的身體標記之前給siider間隔:( '轉盤')

$轉盤。({ 間隔:1000 })