最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Bootstrap carousel slide left to right - Stack Overflow

programmeradmin1浏览0评论

Hi i using bootstrap and created bootstrap carousel but i want it move from left to the right

this is my code on jsfiddle

on this code carousel move from right to the left

var direction = type == 'next' ? 'left' : 'right'

i changed right and left in var but there is a problem. next slide e in from right again

var direction = type == 'next' ? 'right' : 'left'

I hope you understand what i want :D

EDIT:

Finally I found the answer: I edited the twitter bootstrap.css

I Xchanged all left and right in .carousel class in bootstrap.css

Hi i using bootstrap and created bootstrap carousel but i want it move from left to the right

this is my code on jsfiddle

on this code carousel move from right to the left

var direction = type == 'next' ? 'left' : 'right'

i changed right and left in var but there is a problem. next slide e in from right again

var direction = type == 'next' ? 'right' : 'left'

I hope you understand what i want :D

EDIT:

Finally I found the answer: I edited the twitter bootstrap.css

I Xchanged all left and right in .carousel class in bootstrap.css

Share Improve this question edited May 28, 2015 at 8:56 YuZA asked Apr 30, 2015 at 8:20 YuZAYuZA 1151 gold badge3 silver badges12 bronze badges 4
  • I don't think it is possible. – ketan Commented Apr 30, 2015 at 11:40
  • Living forever just not possible ;-) – YuZA Commented Apr 30, 2015 at 13:16
  • Mr.YuZA, Can you share your code because i need same.Please help me – user6930268 Commented Sep 26, 2016 at 9:57
  • s8.picofile./file/8268947992/bootstrap.css.html – YuZA Commented Sep 28, 2016 at 15:54
Add a ment  | 

4 Answers 4

Reset to default 1

You can try to change in .carousel-control html code

data-slide="prev"
data-slide="next"

to

data-slide="next" 
data-slide="prev"     

:)

Bootstrap carousel by CSS only (right to left, RTL) HTML:

        <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>

CSS:

                /* Make the images wide and responsive. */
            #myCarousel img {
              height: auto;
              max-width: 100%;
              width: 100%;
            }

            /* Change the order of the indicators. 
               Return them to the center of the slide. */
            .carousel-indicators {
              width: auto;
              margin-left: 0;
              transform: translateX(-50%);
            }
            .carousel-indicators li {
              float: right;
              margin: 1px 4px;
            }
            .carousel-indicators .active {
              margin: 0 3px;
            }

            /* Change the direction of the transition. */
            @media all and (transform-3d), (-webkit-transform-3d) {
              .carousel-inner > .item.next,
              .carousel-inner > .item.active.right {
                left: 0;
                -webkit-transform: translate3d(-100%, 0, 0);
                transform: translate3d(-100%, 0, 0);
              }
              .carousel-inner > .item.prev,
              .carousel-inner > .item.active.left {
                left: 0;
                -webkit-transform: translate3d(100%, 0, 0);
                transform: translate3d(100%, 0, 0);
              }
            }

I also altered the .bootstrap css to achieve this effect. Instead of exchanging all lefts to rights in the css, I altered this line in the inner_carousel class:

"6s ease-in-out left;" to "6s ease-in-out right;"

Additionally, I swapped any calls of "100%" to "-100%" and "100%" to "-100%" in all child classes of the inner_carousel class.

In the Bootstrap v3.3.7 find the 'bootstrap.js' file

Now, find this code :

var delta = direction == 'prev' ? -1 : 1;

change it to :

var delta = direction == 'prev' ? 1 : -1;

Then, find these lines :

Carousel.prototype.next = function () {
    if (this.sliding)
        return
    return this.slide('next');
}

Carousel.prototype.prev = function () {
    if (this.sliding)
        return
    return this.slide('prev');
}

and change that to :

Carousel.prototype.next = function () {
    if (this.sliding)
        return
    return this.slide('prev');
}

Carousel.prototype.prev = function () {
    if (this.sliding)
        return
    return this.slide('next');
}
发布评论

评论列表(0)

  1. 暂无评论