Twitter-Bootstrap-3 Carousel Modifications

℡╲_俬逩灬. 提交于 2019-12-12 04:09:36

问题


So guys, I have a carousel which works perfectly. Now I want to be able to modify it slightly so heres my script:

<div id="myCarousel" class="carousel slide">
    <div class="carousel-inner">
        <div class="item active"  id="1"> 
            <center>Images go here!</center>
        </div>
        <div class="item" id="2"> 
            <center>Imsdfsdfsfsdfsdfsdfsfsdfsdf</center>
        </div>
        <div class="item" id="3"> 
            <center>Imasdfsdfsdfsdfre!</center>
        </div>       
    </div>

    <a class="carousel-control left" href="javascript:;" data-target="#myCarousel" data-slide="prev">
        <span class="icon-prev"></span>
    </a>
    <a class="carousel-control right" href="javascript:;" data-target="#myCarousel" data-slide="next">
        <span class="icon-next"></span>
    </a>

    <br /><br /> 
    <div class="container">
        <ul style="float:left; margin-top: 200px; display:inline-block;">
            <li style="display:inline-block;"><a href="javascript:;" data-target="#myCarousel" data-slide="prev">Dashobard</a></li>
            <li style="display:inline-block;"><a href="javascript:;" data-target="#myCarousel" data-slide="prev next">Timeline</a></li>
            <li style="display:inline-block;"><a href="javascript:;" data-target="#myCarousel" data-slide="prev">Visionboard</a></li>                                    
        </ul>
    </div>
</div>      

Works as you would expect - now underneath I would like to have 3 links say, link1, link2, link3 that when you click it changes the slide in the carousel, in addition to this I am looking to ad a captionhttp://jsfiddle.net/iamdanbarrett/CbtT9/ underneath each of those links. see my example image - I have tried using the current controls and tried to modify them with no success.

Here is a fiddle: Fiddle


回答1:


If you want to achieve something like this this is what you have to do:

HTML code:

<div id="myCarousel" class="carousel slide">
    <div class="carousel-inner">
        <div class="active item" id="id1">
            <img src="http://placehold.it/300x200/888&text=Item 1" />
        </div>
        <div class="item" id="id2">
            <img src="http://placehold.it/300x200/aaa&text=Item 2" />
        </div>
        <div class="item" id="id3">
            <img src="http://placehold.it/300x200/444&text=Item 3" />
        </div>     
    </div>

    <a class="carousel-control left" href="#myCarousel" data-slide="prev">&lsaquo;</a>
    <a class="carousel-control right" href="#myCarousel" data-slide="next">&rsaquo;</a>
</div>  

<div class="container">
    <ul>
        <li style="display:inline-block;"><a href="javascript:slideTo('0')">Dashobard</a></li>
        <li style="display:inline-block;"><a href="javascript: slideTo('1')">Timeline</a></li>
        <li style="display:inline-block;"><a href="javascript: slideTo('2')">Visionboard</a></li>                                       
    </ul>
</div>

JavaScript code:

function slideTo(valoare){
    if (valoare == 0) $('#myCarousel').carousel(0)
    if (valoare == 1) $('#myCarousel').carousel(1)
    if (valoare == 2) $('#myCarousel').carousel(2)    
}

And the CSS code i've used for this example:

#myCarousel {
  margin-top: 40px;
}

.carousel-linked-nav,
.item img {
  display: block; 
  margin: 0 auto;
}

.carousel-linked-nav {
  width: 120px;
  margin-bottom: 20px;   
}

.container {
    text-align: center;
}

ul {margin: 0;}

Here is the jsfiddle

This example uses .carousel(number)

Cycles the carousel to a particular frame (0 based, similar to an array).

Update 1:

  • Result here
  • Code here

Update 2:

  • Result here
  • Code here



回答2:


You can try something like this..

http://bootply.com/113737

This example uses the data-target and data-slide-to navigate to specific slide.



来源:https://stackoverflow.com/questions/23787751/twitter-bootstrap-3-carousel-modifications

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!