항목에서 슬라이드 슬라이드를 부트 스트랩하는 속도를 어떻게 제어 할 수 있습니까?


답변:


116

속도는 API로 제어 할 수 없습니다. 그것을 담당하는 CSS를 수정할 수 있지만. 에서 carousel.less파일 찾기

.item {
    display: none;
    position: relative;
    .transition(.6s ease-in-out left);
}

.6s원하는대로 변경 합니다.


.less를 사용하지 않는 경우 bootstrap.css파일 에서 찾으십시오 .

.carousel-inner > .item {
    position: relative;
    display: none;
    -webkit-transition: 0.6s ease-in-out left;
    -moz-transition: 0.6s ease-in-out left;
    -o-transition: 0.6s ease-in-out left;
    transition: 0.6s ease-in-out left;
}

0.6s원하는 시간으로 변경 합니다. 아래 함수 호출에서 시간을 편집 할 수도 있습니다.

.emulateTransitionEnd(2000) 

에서 bootstrap.js함수 Carousel.prototype.slide. 전환을 동기화하고 전환이 끝나기 전에 슬라이드가 사라지는 것을 방지합니다.

2014 년 7 월 8 일 수정

@YellowShark가 지적했듯이 JS의 편집은 더 이상 필요하지 않습니다. CSS 변경 사항 만 적용하십시오.

편집 20/8/2015 이제 css 파일을 편집 한 후 CAROUSEL.TRANSITION_DURATION (bootstrap.js에서) 또는 c.TRANSITION_DURATION (bootstrap.min.js를 사용하는 경우)을 편집하고 그 안의 값을 변경하면됩니다. (기본값은 600). 최종 값은 css 파일에 입력 한 값과 동일해야합니다 (예 : css의 10s = .js의 10000).

16/01/2018 편집 Bootstrap 4의 경우 전환 시간을 예를 들어 2 초로 변경하려면 다음을 추가하십시오.

$(document).ready(function() {
  jQuery.fn.carousel.Constructor.TRANSITION_DURATION = 2000  // 2 seconds
});

사이트의 JS 파일에

.carousel-inner .carousel-item {
  transition: -webkit-transform 2s ease;
  transition: transform 2s ease;
  transition: transform 2s ease, -webkit-transform 2s ease;
}

사이트의 CSS 파일에.


1
답장을 보내 주셔서 감사합니다! 후자를 내 메인 .html 페이지의 스타일에 넣으려고 시도하고 .6을 .1로 변경했지만 크롬을 사용하여 효과가없는 것 같습니다.
genxgeek

명확하지 않습니다. 부트 스트랩 파일을 수정하려고 했습니까? 아니면 그냥 CSS에이 항목을 추가 했습니까? 부트 스트랩 파일을 편집하는 것이 더 안전합니다. 그렇지 않으면 스타일이 마지막으로로드되는지 확인하고 부트 스트랩 스타일을 덮어 써야합니다.
Dmitry Efimenko 2013-06-27

2
자바 스크립트 (더 이상)를 수정할 필요가 없다는 점을 지적하고 싶었습니다. 이제 코드의 해당 줄이 .css ( 'transition-duration') 값을 가져 오므 로 위에서 설명한대로 CSS를 추가하면됩니다. 그게 다야. (또한 캐 러셀 항목에 "슬라이드"클래스가 있는지 확인하십시오. 문서에 언급되어 있는지 확실하지 않습니다.)
YellowShark 2014 년

5
Bootstrap 3 (v3.3.5, 어쨌든)에서 JS는 더 이상 CSS에서 해당 기간 값을 가져 오지 않습니다. 다음 과 같이 Bootstrap을 수정하지 않고 쉽게 설정할 수 있습니다 .jQuery.fn.carousel.Constructor.TRANSITION_DURATION = 1000;
Walf

1
jQuery.fn.carousel.Constructor.TRANSITION_DURATION은 undefined를 반환합니다. 어떻게 바꾸나요? 전환이 작동하고 느리게 미끄러지지 만 밖으로 나가는 이미지가 표시됩니다. 없음; 너무 빨리.

95

캐 러셀을 포함하여 작성 data-interval하십시오 div.

<div id="myCarousel" class="carousel slide" data-ride="carousel" data-interval="500">

w3schools 에서 가져온 예 .


더 적절한 방식으로 질문의 형식을 지정하십시오. Btw. 링크 만 좋은 답변으로 간주되지 않습니다.
ckruczek

1
경고 : "데이터 간격"은 밀리 초 단위로 측정됩니다. 500 = 0.5 초 (매우 빠름). 슬라이드에 표시 할 텍스트가있는 경우 10000 (10 초)이 더 좋습니다. 잘 작동합니다. 나는 그것이 받아 들여진 대답이어야한다고 생각한다.
Renascienza

19
이 대답은 틀 렸습니다 . data-interval새 슬라이드가 이동하는 시간 범위를 결정합니다. 슬라이드 하나가 이동하는 데 걸리는 시간은 결정되지 않습니다.
user31782

1
고마워 친구, 내 하루를 구했다. +1하고 이것은 bootstrap.css 파일을 편집하기보다는 정답으로 확인되어야합니다.
FONGOH MARTIN

2
나는이 정확한 대답을 찾고 있었지만 이전에 다른 대답을 시도했지만 슬라이드 속도와 관련이 있다는 것을 깨닫기 전에이 대답은 슬라이드 사이의 간격을 다룹니다. 이 답변을 포함 해 주셔서 감사합니다. 이것이 제가 원했던 것이었기 때문입니다! (비록 500도 빠르고,하지만 그건 다른 이야기)
말라기

13

기본 DIV의 간격을 데이터 간격 태그로 설정해야합니다. 그것은 잘 작동하고 다른 슬라이드에 다른 시간을 줄 수 있습니다.

<div class="carousel" data-interval="5000">

예를 들어 주시겠습니까? diff 슬라이드에 대해 다른 시간 간격을 제공해야하며 이는 API 호출에서 반환 된 컨트롤러에서 구성됩니다. 슬라이더를 사용하여 웹 페이지도 표시 할 수 있습니까?
Archna

1
data-interval은 애니메이션 기간이 아닌 새 슬라이드가 이동하는 시간 범위를 결정합니다.
Ricardo Vigatti 19.01.24

11

트위터 부트 스트랩 3 :

다른 답변에 지정된대로 CSS 전환을 변경해야합니다.

.carousel-inner > .item {
    position: relative;
    display: none;
    -webkit-transition: 0.6s ease-in-out left;
    -moz-transition: 0.6s ease-in-out left;
    -o-transition: 0.6s ease-in-out left;
    transition: 0.6s ease-in-out left;
}

0.6 초 ~ 1.5 초 (예 :)

또한 변경해야 할 Javascript가 있습니다. bootstrap.js에는 다음 행이 있습니다.

.emulateTransitionEnd(600)

이 값은 밀리 초 단위로 변경해야합니다. 따라서 1.5 초 동안 숫자를 1500으로 변경합니다.

.emulateTransitionEnd(1500)

크리스, 대단해. 감사!
genxgeek 2013 년

8

내가 주목 한 한 가지는 Bootstrap 3이 a .6s0.6s. 따라서 다음과 같이 전환 기간을 명시 적으로 정의해야 할 수도 있습니다 (CSS)

    .carousel-inner>.item {
    -webkit-transition: 0.9s ease-in-out left;
    transition: 0.9s ease-in-out left;
    -webkit-transition: 0.9s, ease-in-out, left;
    -moz-transition: .9s, ease-in-out, left;
    -o-transition: .9s, ease-in-out, left;
    transition: .9s, ease-in-out, left;
    }

1
나를 위해 일하지 않는다 :( 그것은 변화가없는 차처럼 여전히 빠르게 굴러 간다 (나는 1.6으로 바꿨다)
Andiana

7

Bootstrap 4에서는 다음 CSS를 사용하십시오.

.carousel .carousel-item {
    transition-duration: 3s;
}

3s원하는 기간으로 변경하십시오 .


1
:) 아주 아주 좋은
모하메드 Baashar

6

나를 위해 내 견해 끝에 이것을 추가하기 위해 노력했습니다.

<script type="text/javascript">
$(document).ready(function(){
     $("#myCarousel").carousel({
         interval : 8000,
         pause: false
     });
});
</script>

8 초 간격을 캐 러셀에 제공합니다.


3

어떤 바로 사용 외부 코드가 필요 data-interval=""속성

자세한 정보는 getbootstrap을 방문하십시오 .

<div id="carouselExampleCaptions" class="carousel slide" data-ride="carousel" data-interval="2500">

변경 속도 변경 "2500"을 원할 때


2

예를 들어 여러 캐 러셀 중 하나에서만 특정 조건에 따라 속도를 변경하기 위해 프로그래밍 방식으로 수행해야하는 경우 다음과 같이 할 수 있습니다.

Html이 다음과 같은 경우 :

<div id="theSlidesList" class="carousel-inner" role="listbox">
  <div id="Slide_00" class="item active"> ...
  <div id="Slide_01" class="item"> ...
  ...
</div>

JavaScript는 다음과 같습니다.

$( "#theSlidesList" ).find( ".item" ).css( "-webkit-transition", "transform 1.9s ease-in-out 0s" ).css( "transition", "transform 1.9s ease-in-out 0s" )

다른 브라우저를 포함하려면 .css (...)를 더 추가하십시오.


2

bootstrap.min.js하나를 포함 하거나 압축하지 않은 후 다음 과 같이 간격을 매개 변수로 추가 할 수 있습니다 jQuery("#numbers").carousel({'interval':900 });.


2

부트 스트랩의 js 파일을 변경하지 않으려면 원하는 값을 jquery 플러그인 (bootsrap 3.3.6)에 직접 삽입 할 수도 있습니다.

물론이를 위해서는 캐 러셀이 data-ride 속성을 통해 직접 활성화되는 것이 아니라 js를 통해 수동으로 활성화되어야합니다.

예를 들면 :

var interval = 3500;
$.fn.carousel.Constructor.TRANSITION_DURATION = interval - 500;
elem.carousel({
    interval : interval
});

이 편집에 당신을 필요로하지 않기 때문에이 방법 같은 I bootstrap.js, 그리고 "unupdateable".. 만들기
TryingToImprove

(200)로 변경 한 후, 나는 이미지가 전환의 중간에 거 사라지는 맞아, 더 이상 부드러운 애니메이션을 볼 수 없습니다
TomSawyer

안녕하세요 @TomSawyer-애니메이션은 CSS를 통해 유지되지만 TRANSITON_DURATION이 전체 전환을 처리 할 수있을만큼 충분히 길다는 것이 중요합니다. 자바 스크립트에서는 in클래스가 설정되고 다시 제거 될 때 정의 합니다. 애니메이션을 단축하려면 less 파일에서 정의 된 위치를 확인하십시오.
Andreas

2

scss가있는 부트 스트랩 4의 경우 $carousel-transition-duration다음 _variables.scss과 같이 구성 변수 를 덮어 쓸 수 있습니다 .

$carousel-transition-duration: 2s;

또는 요소 개별 기간에 대해

.carousel-item {
    transition-duration: 2s;
}

css / scss에서 특정 요소의.


1

나를 위해 일한 것은 bootstrap.js 에서 간격 을 변경하는 것이 었습니다.

  Carousel.DEFAULTS = {
    interval: 2000,      // <----- change this
    pause: 'hover',
    wrap: true,
    keyboard: true
  }

1
이는 개별 애니메이션의 속도가 아니라 애니메이션의 빈도를 제어합니다.
Walf

1

이전 답변을 보완하려면 CSS 파일을 편집 한 후 CAROUSEL.TRANSITION_DURATION( bootstrap.js에서 ) 또는 c.TRANSITION_DURATION( bootstrap.min.js 를 사용하는 경우 ) 편집 하고 그 안의 값 (기본값은 600)을 변경하면됩니다. 최종 값은 CSS 파일에 입력 한 값과 동일해야합니다 (예 : CSS의 10s = .js의 10000).

Carousel.VERSION  = '3.3.2'
Carousel.TRANSITION_DURATION = xxxxx /* Your number here*/
Carousel.DEFAULTS = {
interval: 5000 /* you could change this value too, but to add data-interval="xxxx" to your html it's fine too*/
pause: 'hover',
wrap: true,
keyboard: true
}

1

부트 스트랩 3.3.5에 대해 슬라이드가 들어오고 나가는 속도 (슬라이드 변경 사이의 시간이 아닌 간격이라고 함)를 편집하려는 경우 | CDN 부트 스트랩 스타일을로드 한 후 다음 클래스를 사용하여 자신의 CSS 스타일 시트에서 스타일을 덮어 씁니다. 1.5는 시간 변화입니다.

.carousel-inner > .item {
-webkit-transition: 1.5s ease-in-out ;
-o-transition: 1.5s ease-in-out ;
transition: 1.5s ease-in-out ;
}
.carousel-inner > .item {
-webkit-transition: -webkit-transform 1.5s ease-in-out;
-o-transition: -o-transform 1.5s ease-in-out;
transition: transform 1.5s ease-in-out;

}

그 후에 자바 스크립트에서 캐 러셀 기능을 교체해야합니다. 이렇게하려면로드 후 기본 bootstrap.min.js 함수를 덮어 씁니다. (제 생각에는 부트 스트랩 파일을 직접 덮어 쓰는 것은 좋지 않습니다.) 따라서 mynewscript.js를 만들고 bootstrap.min.js 다음에로드하고 새 캐 러셀 기능을 추가합니다. 편집 할 유일한 줄은이 줄입니다. Carousel.TRANSITION_DURATION = 1500. 1500은 1.5입니다. 도움이 되었기를 바랍니다.

    +function ($) {
  'use strict';

  // CAROUSEL CLASS DEFINITION
  // =========================

  var Carousel = function (element, options) {
    this.$element    = $(element)
    this.$indicators = this.$element.find('.carousel-indicators')
    this.options     = options
    this.paused      = null
    this.sliding     = null
    this.interval    = null
    this.$active     = null
    this.$items      = null

    this.options.keyboard && this.$element.on('keydown.bs.carousel', $.proxy(this.keydown, this))

    this.options.pause == 'hover' && !('ontouchstart' in document.documentElement) && this.$element
      .on('mouseenter.bs.carousel', $.proxy(this.pause, this))
      .on('mouseleave.bs.carousel', $.proxy(this.cycle, this))
  }

  Carousel.VERSION  = '3.3.5'

  Carousel.TRANSITION_DURATION = 1500

  Carousel.DEFAULTS = {
    interval: 5000,
    pause: 'hover',
    wrap: true,
    keyboard: true
  }

  Carousel.prototype.keydown = function (e) {
    if (/input|textarea/i.test(e.target.tagName)) return
    switch (e.which) {
      case 37: this.prev(); break
      case 39: this.next(); break
      default: return
    }

    e.preventDefault()
  }

  Carousel.prototype.cycle = function (e) {
    e || (this.paused = false)

    this.interval && clearInterval(this.interval)

    this.options.interval
      && !this.paused
      && (this.interval = setInterval($.proxy(this.next, this), this.options.interval))

    return this
  }

  Carousel.prototype.getItemIndex = function (item) {
    this.$items = item.parent().children('.item')
    return this.$items.index(item || this.$active)
  }

  Carousel.prototype.getItemForDirection = function (direction, active) {
    var activeIndex = this.getItemIndex(active)
    var willWrap = (direction == 'prev' && activeIndex === 0)
                || (direction == 'next' && activeIndex == (this.$items.length - 1))
    if (willWrap && !this.options.wrap) return active
    var delta = direction == 'prev' ? -1 : 1
    var itemIndex = (activeIndex + delta) % this.$items.length
    return this.$items.eq(itemIndex)
  }

  Carousel.prototype.to = function (pos) {
    var that        = this
    var activeIndex = this.getItemIndex(this.$active = this.$element.find('.item.active'))

    if (pos > (this.$items.length - 1) || pos < 0) return

    if (this.sliding)       return this.$element.one('slid.bs.carousel', function () { that.to(pos) }) // yes, "slid"
    if (activeIndex == pos) return this.pause().cycle()

    return this.slide(pos > activeIndex ? 'next' : 'prev', this.$items.eq(pos))
  }

  Carousel.prototype.pause = function (e) {
    e || (this.paused = true)

    if (this.$element.find('.next, .prev').length && $.support.transition) {
      this.$element.trigger($.support.transition.end)
      this.cycle(true)
    }

    this.interval = clearInterval(this.interval)

    return this
  }

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

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

  Carousel.prototype.slide = function (type, next) {
    var $active   = this.$element.find('.item.active')
    var $next     = next || this.getItemForDirection(type, $active)
    var isCycling = this.interval
    var direction = type == 'next' ? 'left' : 'right'
    var that      = this

    if ($next.hasClass('active')) return (this.sliding = false)

    var relatedTarget = $next[0]
    var slideEvent = $.Event('slide.bs.carousel', {
      relatedTarget: relatedTarget,
      direction: direction
    })
    this.$element.trigger(slideEvent)
    if (slideEvent.isDefaultPrevented()) return

    this.sliding = true

    isCycling && this.pause()

    if (this.$indicators.length) {
      this.$indicators.find('.active').removeClass('active')
      var $nextIndicator = $(this.$indicators.children()[this.getItemIndex($next)])
      $nextIndicator && $nextIndicator.addClass('active')
    }

    var slidEvent = $.Event('slid.bs.carousel', { relatedTarget: relatedTarget, direction: direction }) // yes, "slid"
    if ($.support.transition && this.$element.hasClass('slide')) {
      $next.addClass(type)
      $next[0].offsetWidth // force reflow
      $active.addClass(direction)
      $next.addClass(direction)
      $active
        .one('bsTransitionEnd', function () {
          $next.removeClass([type, direction].join(' ')).addClass('active')
          $active.removeClass(['active', direction].join(' '))
          that.sliding = false
          setTimeout(function () {
            that.$element.trigger(slidEvent)
          }, 0)
        })
        .emulateTransitionEnd(Carousel.TRANSITION_DURATION)
    } else {
      $active.removeClass('active')
      $next.addClass('active')
      this.sliding = false
      this.$element.trigger(slidEvent)
    }

    isCycling && this.cycle()

    return this
  }


  // CAROUSEL PLUGIN DEFINITION
  // ==========================

  function Plugin(option) {
    return this.each(function () {
      var $this   = $(this)
      var data    = $this.data('bs.carousel')
      var options = $.extend({}, Carousel.DEFAULTS, $this.data(), typeof option == 'object' && option)
      var action  = typeof option == 'string' ? option : options.slide

      if (!data) $this.data('bs.carousel', (data = new Carousel(this, options)))
      if (typeof option == 'number') data.to(option)
      else if (action) data[action]()
      else if (options.interval) data.pause().cycle()
    })
  }

  var old = $.fn.carousel

  $.fn.carousel             = Plugin
  $.fn.carousel.Constructor = Carousel


  // CAROUSEL NO CONFLICT
  // ====================

  $.fn.carousel.noConflict = function () {
    $.fn.carousel = old
    return this
  }


  // CAROUSEL DATA-API
  // =================

  var clickHandler = function (e) {
    var href
    var $this   = $(this)
    var $target = $($this.attr('data-target') || (href = $this.attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '')) // strip for ie7
    if (!$target.hasClass('carousel')) return
    var options = $.extend({}, $target.data(), $this.data())
    var slideIndex = $this.attr('data-slide-to')
    if (slideIndex) options.interval = false

    Plugin.call($target, options)

    if (slideIndex) {
      $target.data('bs.carousel').to(slideIndex)
    }

    e.preventDefault()
  }

  $(document)
    .on('click.bs.carousel.data-api', '[data-slide]', clickHandler)
    .on('click.bs.carousel.data-api', '[data-slide-to]', clickHandler)

  $(window).on('load', function () {
    $('[data-ride="carousel"]').each(function () {
      var $carousel = $(this)
      Plugin.call($carousel, $carousel.data())
    })
  })

}(jQuery);

1

CSS에서 :

.carousel-item {
    transition-duration: 1.5s, 1.5s;
}

시간은 캐 러셀에 대해 정의 된 데이터 간격에 포함됩니다.

도움이 되었기를 바랍니다 ... :)


0

모든 캐 러셀

  <script type="text/javascript">
              $(document).ready(function () {
            $('.carousel').carousel({
                interval: 15000
            })
        });

    </script>

대답과 함께 제공하십시오 설명
팬더

1
다시 한번 이것은 전환 시간이 아니라 단순히 간격을 결정합니다
Tim Hallman 2017 년


0

main.js 파일 또는 bootstrap.js에서 autoplayTimeout 의 값을 변경하십시오.

    $('.carousel').each(function () {
        $(this).owlCarousel({
            nav: $(this).data('nav'),
            dots: $(this).data('dots'),
            loop: $(this).data('loop'),
            margin: $(this).data('space'),
            center: $(this).data('center'),
            dotsSpeed: $(this).data('speed'),
            autoplay: $(this).data('autoplay'),
            transitionStyle: $(this).data('transition'),
            animateOut: $(this).data('animate-out'),
            animateIn: $(this).data('animate-in'),
            autoplayTimeout: 3000,
            responsive: {
                0: {
                    items: 1,
                },
                400: {
                    items: $(this).data('slide-sm'),
                },
                700: {
                    items: $(this).data('slide-md'),
                },
                1000: {
                    items: $(this).data('slide'),
                }
            }
        });
    });


0

이것을 사용할 수 있습니다

<div id="carouselExampleSlidesOnly" class="carousel slide" data-ride="carousel" data-interval="4000">

data-interval="1000"1 초 후 다음 사진이있을 위치를 추가하기 만하면 됩니다.


-1

ngCarousel 모듈을 사용하는 경우 @ ng-bootstrap / ng-bootstrap / carousel-config.js 파일에서 간격 변수를 다음과 같이 편집하십시오.

var NgbCarouselConfig = /** @class */ (function () {
function NgbCarouselConfig() {
    this.interval = 10000;
    this.wrap = true;
    ...
}
...
당사 사이트를 사용함과 동시에 당사의 쿠키 정책개인정보 보호정책을 읽고 이해하였음을 인정하는 것으로 간주합니다.
Licensed under cc by-sa 3.0 with attribution required.