Unidirectional Bootstrap 3 carousel Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)jQuery image carouselCarousel for websiteTwitter-bootstrap add-onThumbnails for bootstrap carousel jQuery pluginBootstrap Tabs With SammyJsBootstrap Data Table generationBootstrap show many move one carousel modificationBootstrap WordPress Carousel Recent PostsBootstrap responsive layoutBootstrap file input stylerHTML/bootstrap demo page

What are the motives behind Cersei's orders given to Bronn?

Did Xerox really develop the first LAN?

WAN encapsulation

Should I call the interviewer directly, if HR aren't responding?

What's the purpose of writing one's academic bio in 3rd person?

Is a manifold-with-boundary with given interior and non-empty boundary essentially unique?

Why is high voltage dangerous?

ListPlot join points by nearest neighbor rather than order

Is above average number of years spent on PhD considered a red flag in future academia or industry positions?

How can whole tone melodies sound more interesting?

What makes black pepper strong or mild?

What does '1 unit of lemon juice' mean in a grandma's drink recipe?

3 doors, three guards, one stone

Is there a documented rationale why the House Ways and Means chairman can demand tax info?

Is it true that "carbohydrates are of no use for the basal metabolic need"?

Why does Python start at index 1 when iterating an array backwards?

What is this single-engine low-wing propeller plane?

Bonus calculation: Am I making a mountain out of a molehill?

What happens to sewage if there is no river near by?

IndentationError when pasting code in Python 3 interpreter mode

Right-skewed distribution with mean equals to mode?

How much radiation do nuclear physics experiments expose researchers to nowadays?

How discoverable are IPv6 addresses and AAAA names by potential attackers?

How do I stop a creek from eroding my steep embankment?



Unidirectional Bootstrap 3 carousel



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)jQuery image carouselCarousel for websiteTwitter-bootstrap add-onThumbnails for bootstrap carousel jQuery pluginBootstrap Tabs With SammyJsBootstrap Data Table generationBootstrap show many move one carousel modificationBootstrap WordPress Carousel Recent PostsBootstrap responsive layoutBootstrap file input stylerHTML/bootstrap demo page



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1












$begingroup$


I am working on a custom Bootstrap 3 carousel, with vertical, unidirectional, slide transitions.



I want to prevent slide transitions from overlapping when the bullets are clicked in random order and rapid succession.



I came up with this solution that relies on disabling them as long as a slide transition is in progress, then enabling them between transitions:






var carouselDuration = function() 
$.fn.carousel.Constructor.TRANSITION_DURATION = 1000;


carouselDuration();
// While a transition is in progress (slide event), do this
$('#myCarousel').on('slide.bs.carousel', function (e)
var $indicator = $(this).find('.carousel-indicators>li');
$indicator.css('pointer-events', 'none');
);

// While a transition has finished (slid event), do this
$('#myCarousel').on('slid.bs.carousel', function (e)
var $indicator = $(this).find('.carousel-indicators>li');
$indicator.css('pointer-events', 'auto');
);

.carousel.vertical 
position: relative;


.carousel.vertical .carousel-inner
height: 100%;
width: auto;


.carousel.vertical .carousel-inner>.item
width: auto;
transition: 1s ease-in-out;
transform: translate3d(0, 100%, 0);
top: 0;


.carousel.vertical .carousel-inner>.next,
.carousel.vertical .carousel-inner>.prev,
.carousel.vertical .carousel-inner>.right
transform: translate3d(0, 100%, 0);
top: 0;


.carousel.vertical .carousel-inner>.left,
.carousel.vertical .carousel-inner>.prev.right,
.carousel.vertical .carousel-inner>.next.left,
.carousel.vertical .carousel-inner>.active
transform: translate3d(0, 0, 0);
top: 0;


.carousel.vertical .carousel-inner>.active.right,
.carousel.vertical .carousel-inner>.active.left
transform: translate3d(0, -100%, 0);
top: 0;


.carousel.vertical .carousel-indicators
display: inline-block;
width: auto;
padding: 0;
margin: 0;
left: auto;
right: 10px;
bottom: 2px;
z-index: 9;
font-size: 0;


.carousel.vertical .carousel-indicators li
border: none;
cursor: pointer;
display: inline-block;
width: 18px;
height: 18px;
text-indent: -9999px;
background: url("https://grgs.ro/1/i/sprite.png") no-repeat -528px -502px;


.carousel.vertical .carousel-indicators li.active
background-position: -528px -524px;

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>


<div class="container">
<div id="myCarousel" class="carousel vertical slide" data-ride="carousel" data-interval="9000">
<!-- Wrapper for slides -->
<div class="carousel-inner">
<div class="item active">
<img src="https://picsum.photos/1200/300/?gravity=east" alt="">
</div>

<div class="item">
<img src="https://picsum.photos/1200/300/?gravity=south" alt="">
</div>

<div class="item">
<img src="https://picsum.photos/1200/300/?gravity=west" alt="">
</div>
</div>

<!-- Indicators -->
<ol class="carousel-indicators">
<li data-target="#myCarousel" data-slide-to="0" class="active"></li>
<li data-target="#myCarousel" data-slide-to="1"></li>
<li data-target="#myCarousel" data-slide-to="2"></li>
</ol>
</div>
</div>





Still, I am looking for a queuing mechanism, as it is more natural and elegant.










share|improve this question











$endgroup$


















    1












    $begingroup$


    I am working on a custom Bootstrap 3 carousel, with vertical, unidirectional, slide transitions.



    I want to prevent slide transitions from overlapping when the bullets are clicked in random order and rapid succession.



    I came up with this solution that relies on disabling them as long as a slide transition is in progress, then enabling them between transitions:






    var carouselDuration = function() 
    $.fn.carousel.Constructor.TRANSITION_DURATION = 1000;


    carouselDuration();
    // While a transition is in progress (slide event), do this
    $('#myCarousel').on('slide.bs.carousel', function (e)
    var $indicator = $(this).find('.carousel-indicators>li');
    $indicator.css('pointer-events', 'none');
    );

    // While a transition has finished (slid event), do this
    $('#myCarousel').on('slid.bs.carousel', function (e)
    var $indicator = $(this).find('.carousel-indicators>li');
    $indicator.css('pointer-events', 'auto');
    );

    .carousel.vertical 
    position: relative;


    .carousel.vertical .carousel-inner
    height: 100%;
    width: auto;


    .carousel.vertical .carousel-inner>.item
    width: auto;
    transition: 1s ease-in-out;
    transform: translate3d(0, 100%, 0);
    top: 0;


    .carousel.vertical .carousel-inner>.next,
    .carousel.vertical .carousel-inner>.prev,
    .carousel.vertical .carousel-inner>.right
    transform: translate3d(0, 100%, 0);
    top: 0;


    .carousel.vertical .carousel-inner>.left,
    .carousel.vertical .carousel-inner>.prev.right,
    .carousel.vertical .carousel-inner>.next.left,
    .carousel.vertical .carousel-inner>.active
    transform: translate3d(0, 0, 0);
    top: 0;


    .carousel.vertical .carousel-inner>.active.right,
    .carousel.vertical .carousel-inner>.active.left
    transform: translate3d(0, -100%, 0);
    top: 0;


    .carousel.vertical .carousel-indicators
    display: inline-block;
    width: auto;
    padding: 0;
    margin: 0;
    left: auto;
    right: 10px;
    bottom: 2px;
    z-index: 9;
    font-size: 0;


    .carousel.vertical .carousel-indicators li
    border: none;
    cursor: pointer;
    display: inline-block;
    width: 18px;
    height: 18px;
    text-indent: -9999px;
    background: url("https://grgs.ro/1/i/sprite.png") no-repeat -528px -502px;


    .carousel.vertical .carousel-indicators li.active
    background-position: -528px -524px;

    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>


    <div class="container">
    <div id="myCarousel" class="carousel vertical slide" data-ride="carousel" data-interval="9000">
    <!-- Wrapper for slides -->
    <div class="carousel-inner">
    <div class="item active">
    <img src="https://picsum.photos/1200/300/?gravity=east" alt="">
    </div>

    <div class="item">
    <img src="https://picsum.photos/1200/300/?gravity=south" alt="">
    </div>

    <div class="item">
    <img src="https://picsum.photos/1200/300/?gravity=west" alt="">
    </div>
    </div>

    <!-- Indicators -->
    <ol class="carousel-indicators">
    <li data-target="#myCarousel" data-slide-to="0" class="active"></li>
    <li data-target="#myCarousel" data-slide-to="1"></li>
    <li data-target="#myCarousel" data-slide-to="2"></li>
    </ol>
    </div>
    </div>





    Still, I am looking for a queuing mechanism, as it is more natural and elegant.










    share|improve this question











    $endgroup$














      1












      1








      1





      $begingroup$


      I am working on a custom Bootstrap 3 carousel, with vertical, unidirectional, slide transitions.



      I want to prevent slide transitions from overlapping when the bullets are clicked in random order and rapid succession.



      I came up with this solution that relies on disabling them as long as a slide transition is in progress, then enabling them between transitions:






      var carouselDuration = function() 
      $.fn.carousel.Constructor.TRANSITION_DURATION = 1000;


      carouselDuration();
      // While a transition is in progress (slide event), do this
      $('#myCarousel').on('slide.bs.carousel', function (e)
      var $indicator = $(this).find('.carousel-indicators>li');
      $indicator.css('pointer-events', 'none');
      );

      // While a transition has finished (slid event), do this
      $('#myCarousel').on('slid.bs.carousel', function (e)
      var $indicator = $(this).find('.carousel-indicators>li');
      $indicator.css('pointer-events', 'auto');
      );

      .carousel.vertical 
      position: relative;


      .carousel.vertical .carousel-inner
      height: 100%;
      width: auto;


      .carousel.vertical .carousel-inner>.item
      width: auto;
      transition: 1s ease-in-out;
      transform: translate3d(0, 100%, 0);
      top: 0;


      .carousel.vertical .carousel-inner>.next,
      .carousel.vertical .carousel-inner>.prev,
      .carousel.vertical .carousel-inner>.right
      transform: translate3d(0, 100%, 0);
      top: 0;


      .carousel.vertical .carousel-inner>.left,
      .carousel.vertical .carousel-inner>.prev.right,
      .carousel.vertical .carousel-inner>.next.left,
      .carousel.vertical .carousel-inner>.active
      transform: translate3d(0, 0, 0);
      top: 0;


      .carousel.vertical .carousel-inner>.active.right,
      .carousel.vertical .carousel-inner>.active.left
      transform: translate3d(0, -100%, 0);
      top: 0;


      .carousel.vertical .carousel-indicators
      display: inline-block;
      width: auto;
      padding: 0;
      margin: 0;
      left: auto;
      right: 10px;
      bottom: 2px;
      z-index: 9;
      font-size: 0;


      .carousel.vertical .carousel-indicators li
      border: none;
      cursor: pointer;
      display: inline-block;
      width: 18px;
      height: 18px;
      text-indent: -9999px;
      background: url("https://grgs.ro/1/i/sprite.png") no-repeat -528px -502px;


      .carousel.vertical .carousel-indicators li.active
      background-position: -528px -524px;

      <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
      <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>


      <div class="container">
      <div id="myCarousel" class="carousel vertical slide" data-ride="carousel" data-interval="9000">
      <!-- Wrapper for slides -->
      <div class="carousel-inner">
      <div class="item active">
      <img src="https://picsum.photos/1200/300/?gravity=east" alt="">
      </div>

      <div class="item">
      <img src="https://picsum.photos/1200/300/?gravity=south" alt="">
      </div>

      <div class="item">
      <img src="https://picsum.photos/1200/300/?gravity=west" alt="">
      </div>
      </div>

      <!-- Indicators -->
      <ol class="carousel-indicators">
      <li data-target="#myCarousel" data-slide-to="0" class="active"></li>
      <li data-target="#myCarousel" data-slide-to="1"></li>
      <li data-target="#myCarousel" data-slide-to="2"></li>
      </ol>
      </div>
      </div>





      Still, I am looking for a queuing mechanism, as it is more natural and elegant.










      share|improve this question











      $endgroup$




      I am working on a custom Bootstrap 3 carousel, with vertical, unidirectional, slide transitions.



      I want to prevent slide transitions from overlapping when the bullets are clicked in random order and rapid succession.



      I came up with this solution that relies on disabling them as long as a slide transition is in progress, then enabling them between transitions:






      var carouselDuration = function() 
      $.fn.carousel.Constructor.TRANSITION_DURATION = 1000;


      carouselDuration();
      // While a transition is in progress (slide event), do this
      $('#myCarousel').on('slide.bs.carousel', function (e)
      var $indicator = $(this).find('.carousel-indicators>li');
      $indicator.css('pointer-events', 'none');
      );

      // While a transition has finished (slid event), do this
      $('#myCarousel').on('slid.bs.carousel', function (e)
      var $indicator = $(this).find('.carousel-indicators>li');
      $indicator.css('pointer-events', 'auto');
      );

      .carousel.vertical 
      position: relative;


      .carousel.vertical .carousel-inner
      height: 100%;
      width: auto;


      .carousel.vertical .carousel-inner>.item
      width: auto;
      transition: 1s ease-in-out;
      transform: translate3d(0, 100%, 0);
      top: 0;


      .carousel.vertical .carousel-inner>.next,
      .carousel.vertical .carousel-inner>.prev,
      .carousel.vertical .carousel-inner>.right
      transform: translate3d(0, 100%, 0);
      top: 0;


      .carousel.vertical .carousel-inner>.left,
      .carousel.vertical .carousel-inner>.prev.right,
      .carousel.vertical .carousel-inner>.next.left,
      .carousel.vertical .carousel-inner>.active
      transform: translate3d(0, 0, 0);
      top: 0;


      .carousel.vertical .carousel-inner>.active.right,
      .carousel.vertical .carousel-inner>.active.left
      transform: translate3d(0, -100%, 0);
      top: 0;


      .carousel.vertical .carousel-indicators
      display: inline-block;
      width: auto;
      padding: 0;
      margin: 0;
      left: auto;
      right: 10px;
      bottom: 2px;
      z-index: 9;
      font-size: 0;


      .carousel.vertical .carousel-indicators li
      border: none;
      cursor: pointer;
      display: inline-block;
      width: 18px;
      height: 18px;
      text-indent: -9999px;
      background: url("https://grgs.ro/1/i/sprite.png") no-repeat -528px -502px;


      .carousel.vertical .carousel-indicators li.active
      background-position: -528px -524px;

      <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
      <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>


      <div class="container">
      <div id="myCarousel" class="carousel vertical slide" data-ride="carousel" data-interval="9000">
      <!-- Wrapper for slides -->
      <div class="carousel-inner">
      <div class="item active">
      <img src="https://picsum.photos/1200/300/?gravity=east" alt="">
      </div>

      <div class="item">
      <img src="https://picsum.photos/1200/300/?gravity=south" alt="">
      </div>

      <div class="item">
      <img src="https://picsum.photos/1200/300/?gravity=west" alt="">
      </div>
      </div>

      <!-- Indicators -->
      <ol class="carousel-indicators">
      <li data-target="#myCarousel" data-slide-to="0" class="active"></li>
      <li data-target="#myCarousel" data-slide-to="1"></li>
      <li data-target="#myCarousel" data-slide-to="2"></li>
      </ol>
      </div>
      </div>





      Still, I am looking for a queuing mechanism, as it is more natural and elegant.






      var carouselDuration = function() 
      $.fn.carousel.Constructor.TRANSITION_DURATION = 1000;


      carouselDuration();
      // While a transition is in progress (slide event), do this
      $('#myCarousel').on('slide.bs.carousel', function (e)
      var $indicator = $(this).find('.carousel-indicators>li');
      $indicator.css('pointer-events', 'none');
      );

      // While a transition has finished (slid event), do this
      $('#myCarousel').on('slid.bs.carousel', function (e)
      var $indicator = $(this).find('.carousel-indicators>li');
      $indicator.css('pointer-events', 'auto');
      );

      .carousel.vertical 
      position: relative;


      .carousel.vertical .carousel-inner
      height: 100%;
      width: auto;


      .carousel.vertical .carousel-inner>.item
      width: auto;
      transition: 1s ease-in-out;
      transform: translate3d(0, 100%, 0);
      top: 0;


      .carousel.vertical .carousel-inner>.next,
      .carousel.vertical .carousel-inner>.prev,
      .carousel.vertical .carousel-inner>.right
      transform: translate3d(0, 100%, 0);
      top: 0;


      .carousel.vertical .carousel-inner>.left,
      .carousel.vertical .carousel-inner>.prev.right,
      .carousel.vertical .carousel-inner>.next.left,
      .carousel.vertical .carousel-inner>.active
      transform: translate3d(0, 0, 0);
      top: 0;


      .carousel.vertical .carousel-inner>.active.right,
      .carousel.vertical .carousel-inner>.active.left
      transform: translate3d(0, -100%, 0);
      top: 0;


      .carousel.vertical .carousel-indicators
      display: inline-block;
      width: auto;
      padding: 0;
      margin: 0;
      left: auto;
      right: 10px;
      bottom: 2px;
      z-index: 9;
      font-size: 0;


      .carousel.vertical .carousel-indicators li
      border: none;
      cursor: pointer;
      display: inline-block;
      width: 18px;
      height: 18px;
      text-indent: -9999px;
      background: url("https://grgs.ro/1/i/sprite.png") no-repeat -528px -502px;


      .carousel.vertical .carousel-indicators li.active
      background-position: -528px -524px;

      <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
      <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>


      <div class="container">
      <div id="myCarousel" class="carousel vertical slide" data-ride="carousel" data-interval="9000">
      <!-- Wrapper for slides -->
      <div class="carousel-inner">
      <div class="item active">
      <img src="https://picsum.photos/1200/300/?gravity=east" alt="">
      </div>

      <div class="item">
      <img src="https://picsum.photos/1200/300/?gravity=south" alt="">
      </div>

      <div class="item">
      <img src="https://picsum.photos/1200/300/?gravity=west" alt="">
      </div>
      </div>

      <!-- Indicators -->
      <ol class="carousel-indicators">
      <li data-target="#myCarousel" data-slide-to="0" class="active"></li>
      <li data-target="#myCarousel" data-slide-to="1"></li>
      <li data-target="#myCarousel" data-slide-to="2"></li>
      </ol>
      </div>
      </div>





      var carouselDuration = function() 
      $.fn.carousel.Constructor.TRANSITION_DURATION = 1000;


      carouselDuration();
      // While a transition is in progress (slide event), do this
      $('#myCarousel').on('slide.bs.carousel', function (e)
      var $indicator = $(this).find('.carousel-indicators>li');
      $indicator.css('pointer-events', 'none');
      );

      // While a transition has finished (slid event), do this
      $('#myCarousel').on('slid.bs.carousel', function (e)
      var $indicator = $(this).find('.carousel-indicators>li');
      $indicator.css('pointer-events', 'auto');
      );

      .carousel.vertical 
      position: relative;


      .carousel.vertical .carousel-inner
      height: 100%;
      width: auto;


      .carousel.vertical .carousel-inner>.item
      width: auto;
      transition: 1s ease-in-out;
      transform: translate3d(0, 100%, 0);
      top: 0;


      .carousel.vertical .carousel-inner>.next,
      .carousel.vertical .carousel-inner>.prev,
      .carousel.vertical .carousel-inner>.right
      transform: translate3d(0, 100%, 0);
      top: 0;


      .carousel.vertical .carousel-inner>.left,
      .carousel.vertical .carousel-inner>.prev.right,
      .carousel.vertical .carousel-inner>.next.left,
      .carousel.vertical .carousel-inner>.active
      transform: translate3d(0, 0, 0);
      top: 0;


      .carousel.vertical .carousel-inner>.active.right,
      .carousel.vertical .carousel-inner>.active.left
      transform: translate3d(0, -100%, 0);
      top: 0;


      .carousel.vertical .carousel-indicators
      display: inline-block;
      width: auto;
      padding: 0;
      margin: 0;
      left: auto;
      right: 10px;
      bottom: 2px;
      z-index: 9;
      font-size: 0;


      .carousel.vertical .carousel-indicators li
      border: none;
      cursor: pointer;
      display: inline-block;
      width: 18px;
      height: 18px;
      text-indent: -9999px;
      background: url("https://grgs.ro/1/i/sprite.png") no-repeat -528px -502px;


      .carousel.vertical .carousel-indicators li.active
      background-position: -528px -524px;

      <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
      <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>


      <div class="container">
      <div id="myCarousel" class="carousel vertical slide" data-ride="carousel" data-interval="9000">
      <!-- Wrapper for slides -->
      <div class="carousel-inner">
      <div class="item active">
      <img src="https://picsum.photos/1200/300/?gravity=east" alt="">
      </div>

      <div class="item">
      <img src="https://picsum.photos/1200/300/?gravity=south" alt="">
      </div>

      <div class="item">
      <img src="https://picsum.photos/1200/300/?gravity=west" alt="">
      </div>
      </div>

      <!-- Indicators -->
      <ol class="carousel-indicators">
      <li data-target="#myCarousel" data-slide-to="0" class="active"></li>
      <li data-target="#myCarousel" data-slide-to="1"></li>
      <li data-target="#myCarousel" data-slide-to="2"></li>
      </ol>
      </div>
      </div>






      javascript jquery css animation twitter-bootstrap






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 21 '18 at 20:19









      Sᴀᴍ Onᴇᴌᴀ

      10.6k62168




      10.6k62168










      asked Nov 13 '18 at 13:19









      Razvan ZamfirRazvan Zamfir

      12212




      12212




















          1 Answer
          1






          active

          oldest

          votes


















          0












          $begingroup$

          Feedback



          The code seems fairly concise, though I do have suggestions below that can simplify it even more. I was hoping there was some class name applied to the element with class carousel during the slide transition but apparently the bootstrap code does not do that, though you could use the event callback functions to apply the class name yourself. That way the CSS style for pointer-events can be moved into the CSS.



          Because the .on() method accepts multiple events separated by a space, you can use one call for both events, and a single Partially applied function to call the .toggleClass() method, which will add and then remove a class to the carousel element:



          var carouselCollection = $('#myCarousel');
          carouselCollection.on('slide.bs.carousel slid.bs.carousel',
          carouselCollection.toggleClass.bind(carouselCollection, 'sliding'));


          Then the CSS can contain the style:



          .carousel.vertical.sliding .carousel-indicators li 
          pointer-events: none;



          See that working in the rewritten code below.



          I don't see much point in creating the function carouselDuration() and calling it immediately afterwards but then never again. Why not just move that single line out where it is called? I could see a point in doing that after some condition is met (e.g. DOM ready, jQuery/carousel ready, etc).



          Some of the CSS rulesets are a bit redundant. For instance, some of the top: 0 rulesets should be cascadable from .carousel.vertical .carousel-inner>.item and apply to the next three subsequent selectors.



          Also, I believe I was able to remove this block without any adverse affects. Are there really elements with class .right and .left or are those for the left/right controls that aren't being used?




          .carousel.vertical .carousel-inner>.next,
          .carousel.vertical .carousel-inner>.prev,
          .carousel.vertical .carousel-inner>.right
          transform: translate3d(0, 100%, 0);
          top: 0;




          Suggestions



          It would likely help to define that value for the duration as a constant (and if you are using ecmascript-6 then use const) at the top of the code, so it can be easily modified in the future if necessary.




          While there are only a couple redundant DOM queries (e.g. $(#myCarousel)) it would be wise to cache those in a variable.




          The event handler functions are very redundant, and violate the Don't Repeat Yourself principle. The only thing that appears to change is the value assigned to the CSS style pointer-events. If the approach mentioned above with the .toggleClass() method doesn't work, the common code in the two callback functions could be abstracted into a single function that accepts the value for that CSS style, and then Partially applied functions could be created with Function.bind() to fix the value to apply to the style.



          var carouselCollection = $('#myCarousel');

          function setPointerEventsOnListItems(value, e)
          var $indicator = carouselCollection.find('.carousel-indicators>li');
          $indicator.css('pointer-events', value);

          // While a transition is in progress (slide event), do this
          carouselCollection.on('slide.bs.carousel', setPointerEventsOnListItems.bind(null, 'none'));

          // While a transition has finished (slid event), do this
          carouselCollection.on('slid.bs.carousel', setPointerEventsOnListItems.bind(null, 'auto'));



          As you likely know, the jQuery DOM ready function would be good to use so as to avoid accidentally accessing the DOM before it is ready (though that isn't a problem as much nowdays with modern browsers and adding the script tags to the end of the <body>). An IIFE could also be used instead of that jQuery DOM ready callback.




          Rewritten code



          The code below utilizes the advice above, though utilizes the .toggleClass() method.






          var DURATION = 1000; //could use const instead of var if supporting es-6
          $(function() //DOM ready callback
          $.fn.carousel.Constructor.TRANSITION_DURATION = DURATION;
          var carouselCollection = $('#myCarousel');
          // While a transition is in progress (slide event), do this
          carouselCollection.on('slide.bs.carousel slid.bs.carousel', carouselCollection.toggleClass.bind(carouselCollection, 'sliding'));
          );

          .carousel.vertical 
          position: relative;


          .carousel.vertical .carousel-inner
          height: 100%;
          width: auto;


          .carousel.vertical .carousel-inner>.item
          width: auto;
          transition: 1s ease-in-out;
          transform: translate3d(0, 100%, 0);
          top: 0;


          .carousel.vertical .carousel-inner>.left,
          .carousel.vertical .carousel-inner>.prev.right,
          .carousel.vertical .carousel-inner>.next.left,
          .carousel.vertical .carousel-inner>.active
          transform: translate3d(0, 0, 0);


          .carousel.vertical .carousel-inner>.active.right,
          .carousel.vertical .carousel-inner>.active.left
          transform: translate3d(0, -100%, 0);


          .carousel.vertical .carousel-indicators
          display: inline-block;
          width: auto;
          padding: 0;
          margin: 0;
          left: auto;
          right: 10px;
          bottom: 2px;
          z-index: 9;
          font-size: 0;


          .carousel.vertical .carousel-indicators li
          border: none;
          cursor: pointer;
          display: inline-block;
          width: 18px;
          height: 18px;
          text-indent: -9999px;
          background: url("https://grgs.ro/1/i/sprite.png") no-repeat -528px -502px;


          .carousel.vertical.sliding .carousel-indicators li
          pointer-events: none;

          .carousel.vertical .carousel-indicators li.active
          background-position: -528px -524px;

          <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
          <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
          <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>


          <div class="container">
          <div id="myCarousel" class="carousel vertical slide" data-ride="carousel" data-interval="9000">
          <!-- Wrapper for slides -->
          <div class="carousel-inner">
          <div class="item active">
          <img src="https://picsum.photos/1200/300/?gravity=east" alt="">
          </div>

          <div class="item">
          <img src="https://picsum.photos/1200/300/?gravity=south" alt="">
          </div>

          <div class="item">
          <img src="https://picsum.photos/1200/300/?gravity=west" alt="">
          </div>
          </div>

          <!-- Indicators -->
          <ol class="carousel-indicators">
          <li data-target="#myCarousel" data-slide-to="0" class="active"></li>
          <li data-target="#myCarousel" data-slide-to="1"></li>
          <li data-target="#myCarousel" data-slide-to="2"></li>
          </ol>
          </div>
          </div>








          share|improve this answer











          $endgroup$












          • $begingroup$
            Thank a lot for the feedback and the effort to rewrite the code. Can you help with the queuing mechanism or some other solution that would make the slider more user-friendly, meaning the the user would not have to click (temporarily) inactive bullets?
            $endgroup$
            – Razvan Zamfir
            Nov 27 '18 at 11:04










          • $begingroup$
            Please provide an answer to the topic An improvable use case of the Swiper slider. Thanks!
            $endgroup$
            – Razvan Zamfir
            Nov 27 '18 at 11:10










          • $begingroup$
            I hope you don’t get the wrong impression about this site, though maybe you have, since many answers offer a rewrite- especially easy with questions involving JS because snippets make it simple for demonstrating. Requests for code implementations are off-topic for this site.
            $endgroup$
            – Sᴀᴍ Onᴇᴌᴀ
            Nov 27 '18 at 11:55











          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "196"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f207554%2funidirectional-bootstrap-3-carousel%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0












          $begingroup$

          Feedback



          The code seems fairly concise, though I do have suggestions below that can simplify it even more. I was hoping there was some class name applied to the element with class carousel during the slide transition but apparently the bootstrap code does not do that, though you could use the event callback functions to apply the class name yourself. That way the CSS style for pointer-events can be moved into the CSS.



          Because the .on() method accepts multiple events separated by a space, you can use one call for both events, and a single Partially applied function to call the .toggleClass() method, which will add and then remove a class to the carousel element:



          var carouselCollection = $('#myCarousel');
          carouselCollection.on('slide.bs.carousel slid.bs.carousel',
          carouselCollection.toggleClass.bind(carouselCollection, 'sliding'));


          Then the CSS can contain the style:



          .carousel.vertical.sliding .carousel-indicators li 
          pointer-events: none;



          See that working in the rewritten code below.



          I don't see much point in creating the function carouselDuration() and calling it immediately afterwards but then never again. Why not just move that single line out where it is called? I could see a point in doing that after some condition is met (e.g. DOM ready, jQuery/carousel ready, etc).



          Some of the CSS rulesets are a bit redundant. For instance, some of the top: 0 rulesets should be cascadable from .carousel.vertical .carousel-inner>.item and apply to the next three subsequent selectors.



          Also, I believe I was able to remove this block without any adverse affects. Are there really elements with class .right and .left or are those for the left/right controls that aren't being used?




          .carousel.vertical .carousel-inner>.next,
          .carousel.vertical .carousel-inner>.prev,
          .carousel.vertical .carousel-inner>.right
          transform: translate3d(0, 100%, 0);
          top: 0;




          Suggestions



          It would likely help to define that value for the duration as a constant (and if you are using ecmascript-6 then use const) at the top of the code, so it can be easily modified in the future if necessary.




          While there are only a couple redundant DOM queries (e.g. $(#myCarousel)) it would be wise to cache those in a variable.




          The event handler functions are very redundant, and violate the Don't Repeat Yourself principle. The only thing that appears to change is the value assigned to the CSS style pointer-events. If the approach mentioned above with the .toggleClass() method doesn't work, the common code in the two callback functions could be abstracted into a single function that accepts the value for that CSS style, and then Partially applied functions could be created with Function.bind() to fix the value to apply to the style.



          var carouselCollection = $('#myCarousel');

          function setPointerEventsOnListItems(value, e)
          var $indicator = carouselCollection.find('.carousel-indicators>li');
          $indicator.css('pointer-events', value);

          // While a transition is in progress (slide event), do this
          carouselCollection.on('slide.bs.carousel', setPointerEventsOnListItems.bind(null, 'none'));

          // While a transition has finished (slid event), do this
          carouselCollection.on('slid.bs.carousel', setPointerEventsOnListItems.bind(null, 'auto'));



          As you likely know, the jQuery DOM ready function would be good to use so as to avoid accidentally accessing the DOM before it is ready (though that isn't a problem as much nowdays with modern browsers and adding the script tags to the end of the <body>). An IIFE could also be used instead of that jQuery DOM ready callback.




          Rewritten code



          The code below utilizes the advice above, though utilizes the .toggleClass() method.






          var DURATION = 1000; //could use const instead of var if supporting es-6
          $(function() //DOM ready callback
          $.fn.carousel.Constructor.TRANSITION_DURATION = DURATION;
          var carouselCollection = $('#myCarousel');
          // While a transition is in progress (slide event), do this
          carouselCollection.on('slide.bs.carousel slid.bs.carousel', carouselCollection.toggleClass.bind(carouselCollection, 'sliding'));
          );

          .carousel.vertical 
          position: relative;


          .carousel.vertical .carousel-inner
          height: 100%;
          width: auto;


          .carousel.vertical .carousel-inner>.item
          width: auto;
          transition: 1s ease-in-out;
          transform: translate3d(0, 100%, 0);
          top: 0;


          .carousel.vertical .carousel-inner>.left,
          .carousel.vertical .carousel-inner>.prev.right,
          .carousel.vertical .carousel-inner>.next.left,
          .carousel.vertical .carousel-inner>.active
          transform: translate3d(0, 0, 0);


          .carousel.vertical .carousel-inner>.active.right,
          .carousel.vertical .carousel-inner>.active.left
          transform: translate3d(0, -100%, 0);


          .carousel.vertical .carousel-indicators
          display: inline-block;
          width: auto;
          padding: 0;
          margin: 0;
          left: auto;
          right: 10px;
          bottom: 2px;
          z-index: 9;
          font-size: 0;


          .carousel.vertical .carousel-indicators li
          border: none;
          cursor: pointer;
          display: inline-block;
          width: 18px;
          height: 18px;
          text-indent: -9999px;
          background: url("https://grgs.ro/1/i/sprite.png") no-repeat -528px -502px;


          .carousel.vertical.sliding .carousel-indicators li
          pointer-events: none;

          .carousel.vertical .carousel-indicators li.active
          background-position: -528px -524px;

          <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
          <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
          <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>


          <div class="container">
          <div id="myCarousel" class="carousel vertical slide" data-ride="carousel" data-interval="9000">
          <!-- Wrapper for slides -->
          <div class="carousel-inner">
          <div class="item active">
          <img src="https://picsum.photos/1200/300/?gravity=east" alt="">
          </div>

          <div class="item">
          <img src="https://picsum.photos/1200/300/?gravity=south" alt="">
          </div>

          <div class="item">
          <img src="https://picsum.photos/1200/300/?gravity=west" alt="">
          </div>
          </div>

          <!-- Indicators -->
          <ol class="carousel-indicators">
          <li data-target="#myCarousel" data-slide-to="0" class="active"></li>
          <li data-target="#myCarousel" data-slide-to="1"></li>
          <li data-target="#myCarousel" data-slide-to="2"></li>
          </ol>
          </div>
          </div>








          share|improve this answer











          $endgroup$












          • $begingroup$
            Thank a lot for the feedback and the effort to rewrite the code. Can you help with the queuing mechanism or some other solution that would make the slider more user-friendly, meaning the the user would not have to click (temporarily) inactive bullets?
            $endgroup$
            – Razvan Zamfir
            Nov 27 '18 at 11:04










          • $begingroup$
            Please provide an answer to the topic An improvable use case of the Swiper slider. Thanks!
            $endgroup$
            – Razvan Zamfir
            Nov 27 '18 at 11:10










          • $begingroup$
            I hope you don’t get the wrong impression about this site, though maybe you have, since many answers offer a rewrite- especially easy with questions involving JS because snippets make it simple for demonstrating. Requests for code implementations are off-topic for this site.
            $endgroup$
            – Sᴀᴍ Onᴇᴌᴀ
            Nov 27 '18 at 11:55















          0












          $begingroup$

          Feedback



          The code seems fairly concise, though I do have suggestions below that can simplify it even more. I was hoping there was some class name applied to the element with class carousel during the slide transition but apparently the bootstrap code does not do that, though you could use the event callback functions to apply the class name yourself. That way the CSS style for pointer-events can be moved into the CSS.



          Because the .on() method accepts multiple events separated by a space, you can use one call for both events, and a single Partially applied function to call the .toggleClass() method, which will add and then remove a class to the carousel element:



          var carouselCollection = $('#myCarousel');
          carouselCollection.on('slide.bs.carousel slid.bs.carousel',
          carouselCollection.toggleClass.bind(carouselCollection, 'sliding'));


          Then the CSS can contain the style:



          .carousel.vertical.sliding .carousel-indicators li 
          pointer-events: none;



          See that working in the rewritten code below.



          I don't see much point in creating the function carouselDuration() and calling it immediately afterwards but then never again. Why not just move that single line out where it is called? I could see a point in doing that after some condition is met (e.g. DOM ready, jQuery/carousel ready, etc).



          Some of the CSS rulesets are a bit redundant. For instance, some of the top: 0 rulesets should be cascadable from .carousel.vertical .carousel-inner>.item and apply to the next three subsequent selectors.



          Also, I believe I was able to remove this block without any adverse affects. Are there really elements with class .right and .left or are those for the left/right controls that aren't being used?




          .carousel.vertical .carousel-inner>.next,
          .carousel.vertical .carousel-inner>.prev,
          .carousel.vertical .carousel-inner>.right
          transform: translate3d(0, 100%, 0);
          top: 0;




          Suggestions



          It would likely help to define that value for the duration as a constant (and if you are using ecmascript-6 then use const) at the top of the code, so it can be easily modified in the future if necessary.




          While there are only a couple redundant DOM queries (e.g. $(#myCarousel)) it would be wise to cache those in a variable.




          The event handler functions are very redundant, and violate the Don't Repeat Yourself principle. The only thing that appears to change is the value assigned to the CSS style pointer-events. If the approach mentioned above with the .toggleClass() method doesn't work, the common code in the two callback functions could be abstracted into a single function that accepts the value for that CSS style, and then Partially applied functions could be created with Function.bind() to fix the value to apply to the style.



          var carouselCollection = $('#myCarousel');

          function setPointerEventsOnListItems(value, e)
          var $indicator = carouselCollection.find('.carousel-indicators>li');
          $indicator.css('pointer-events', value);

          // While a transition is in progress (slide event), do this
          carouselCollection.on('slide.bs.carousel', setPointerEventsOnListItems.bind(null, 'none'));

          // While a transition has finished (slid event), do this
          carouselCollection.on('slid.bs.carousel', setPointerEventsOnListItems.bind(null, 'auto'));



          As you likely know, the jQuery DOM ready function would be good to use so as to avoid accidentally accessing the DOM before it is ready (though that isn't a problem as much nowdays with modern browsers and adding the script tags to the end of the <body>). An IIFE could also be used instead of that jQuery DOM ready callback.




          Rewritten code



          The code below utilizes the advice above, though utilizes the .toggleClass() method.






          var DURATION = 1000; //could use const instead of var if supporting es-6
          $(function() //DOM ready callback
          $.fn.carousel.Constructor.TRANSITION_DURATION = DURATION;
          var carouselCollection = $('#myCarousel');
          // While a transition is in progress (slide event), do this
          carouselCollection.on('slide.bs.carousel slid.bs.carousel', carouselCollection.toggleClass.bind(carouselCollection, 'sliding'));
          );

          .carousel.vertical 
          position: relative;


          .carousel.vertical .carousel-inner
          height: 100%;
          width: auto;


          .carousel.vertical .carousel-inner>.item
          width: auto;
          transition: 1s ease-in-out;
          transform: translate3d(0, 100%, 0);
          top: 0;


          .carousel.vertical .carousel-inner>.left,
          .carousel.vertical .carousel-inner>.prev.right,
          .carousel.vertical .carousel-inner>.next.left,
          .carousel.vertical .carousel-inner>.active
          transform: translate3d(0, 0, 0);


          .carousel.vertical .carousel-inner>.active.right,
          .carousel.vertical .carousel-inner>.active.left
          transform: translate3d(0, -100%, 0);


          .carousel.vertical .carousel-indicators
          display: inline-block;
          width: auto;
          padding: 0;
          margin: 0;
          left: auto;
          right: 10px;
          bottom: 2px;
          z-index: 9;
          font-size: 0;


          .carousel.vertical .carousel-indicators li
          border: none;
          cursor: pointer;
          display: inline-block;
          width: 18px;
          height: 18px;
          text-indent: -9999px;
          background: url("https://grgs.ro/1/i/sprite.png") no-repeat -528px -502px;


          .carousel.vertical.sliding .carousel-indicators li
          pointer-events: none;

          .carousel.vertical .carousel-indicators li.active
          background-position: -528px -524px;

          <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
          <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
          <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>


          <div class="container">
          <div id="myCarousel" class="carousel vertical slide" data-ride="carousel" data-interval="9000">
          <!-- Wrapper for slides -->
          <div class="carousel-inner">
          <div class="item active">
          <img src="https://picsum.photos/1200/300/?gravity=east" alt="">
          </div>

          <div class="item">
          <img src="https://picsum.photos/1200/300/?gravity=south" alt="">
          </div>

          <div class="item">
          <img src="https://picsum.photos/1200/300/?gravity=west" alt="">
          </div>
          </div>

          <!-- Indicators -->
          <ol class="carousel-indicators">
          <li data-target="#myCarousel" data-slide-to="0" class="active"></li>
          <li data-target="#myCarousel" data-slide-to="1"></li>
          <li data-target="#myCarousel" data-slide-to="2"></li>
          </ol>
          </div>
          </div>








          share|improve this answer











          $endgroup$












          • $begingroup$
            Thank a lot for the feedback and the effort to rewrite the code. Can you help with the queuing mechanism or some other solution that would make the slider more user-friendly, meaning the the user would not have to click (temporarily) inactive bullets?
            $endgroup$
            – Razvan Zamfir
            Nov 27 '18 at 11:04










          • $begingroup$
            Please provide an answer to the topic An improvable use case of the Swiper slider. Thanks!
            $endgroup$
            – Razvan Zamfir
            Nov 27 '18 at 11:10










          • $begingroup$
            I hope you don’t get the wrong impression about this site, though maybe you have, since many answers offer a rewrite- especially easy with questions involving JS because snippets make it simple for demonstrating. Requests for code implementations are off-topic for this site.
            $endgroup$
            – Sᴀᴍ Onᴇᴌᴀ
            Nov 27 '18 at 11:55













          0












          0








          0





          $begingroup$

          Feedback



          The code seems fairly concise, though I do have suggestions below that can simplify it even more. I was hoping there was some class name applied to the element with class carousel during the slide transition but apparently the bootstrap code does not do that, though you could use the event callback functions to apply the class name yourself. That way the CSS style for pointer-events can be moved into the CSS.



          Because the .on() method accepts multiple events separated by a space, you can use one call for both events, and a single Partially applied function to call the .toggleClass() method, which will add and then remove a class to the carousel element:



          var carouselCollection = $('#myCarousel');
          carouselCollection.on('slide.bs.carousel slid.bs.carousel',
          carouselCollection.toggleClass.bind(carouselCollection, 'sliding'));


          Then the CSS can contain the style:



          .carousel.vertical.sliding .carousel-indicators li 
          pointer-events: none;



          See that working in the rewritten code below.



          I don't see much point in creating the function carouselDuration() and calling it immediately afterwards but then never again. Why not just move that single line out where it is called? I could see a point in doing that after some condition is met (e.g. DOM ready, jQuery/carousel ready, etc).



          Some of the CSS rulesets are a bit redundant. For instance, some of the top: 0 rulesets should be cascadable from .carousel.vertical .carousel-inner>.item and apply to the next three subsequent selectors.



          Also, I believe I was able to remove this block without any adverse affects. Are there really elements with class .right and .left or are those for the left/right controls that aren't being used?




          .carousel.vertical .carousel-inner>.next,
          .carousel.vertical .carousel-inner>.prev,
          .carousel.vertical .carousel-inner>.right
          transform: translate3d(0, 100%, 0);
          top: 0;




          Suggestions



          It would likely help to define that value for the duration as a constant (and if you are using ecmascript-6 then use const) at the top of the code, so it can be easily modified in the future if necessary.




          While there are only a couple redundant DOM queries (e.g. $(#myCarousel)) it would be wise to cache those in a variable.




          The event handler functions are very redundant, and violate the Don't Repeat Yourself principle. The only thing that appears to change is the value assigned to the CSS style pointer-events. If the approach mentioned above with the .toggleClass() method doesn't work, the common code in the two callback functions could be abstracted into a single function that accepts the value for that CSS style, and then Partially applied functions could be created with Function.bind() to fix the value to apply to the style.



          var carouselCollection = $('#myCarousel');

          function setPointerEventsOnListItems(value, e)
          var $indicator = carouselCollection.find('.carousel-indicators>li');
          $indicator.css('pointer-events', value);

          // While a transition is in progress (slide event), do this
          carouselCollection.on('slide.bs.carousel', setPointerEventsOnListItems.bind(null, 'none'));

          // While a transition has finished (slid event), do this
          carouselCollection.on('slid.bs.carousel', setPointerEventsOnListItems.bind(null, 'auto'));



          As you likely know, the jQuery DOM ready function would be good to use so as to avoid accidentally accessing the DOM before it is ready (though that isn't a problem as much nowdays with modern browsers and adding the script tags to the end of the <body>). An IIFE could also be used instead of that jQuery DOM ready callback.




          Rewritten code



          The code below utilizes the advice above, though utilizes the .toggleClass() method.






          var DURATION = 1000; //could use const instead of var if supporting es-6
          $(function() //DOM ready callback
          $.fn.carousel.Constructor.TRANSITION_DURATION = DURATION;
          var carouselCollection = $('#myCarousel');
          // While a transition is in progress (slide event), do this
          carouselCollection.on('slide.bs.carousel slid.bs.carousel', carouselCollection.toggleClass.bind(carouselCollection, 'sliding'));
          );

          .carousel.vertical 
          position: relative;


          .carousel.vertical .carousel-inner
          height: 100%;
          width: auto;


          .carousel.vertical .carousel-inner>.item
          width: auto;
          transition: 1s ease-in-out;
          transform: translate3d(0, 100%, 0);
          top: 0;


          .carousel.vertical .carousel-inner>.left,
          .carousel.vertical .carousel-inner>.prev.right,
          .carousel.vertical .carousel-inner>.next.left,
          .carousel.vertical .carousel-inner>.active
          transform: translate3d(0, 0, 0);


          .carousel.vertical .carousel-inner>.active.right,
          .carousel.vertical .carousel-inner>.active.left
          transform: translate3d(0, -100%, 0);


          .carousel.vertical .carousel-indicators
          display: inline-block;
          width: auto;
          padding: 0;
          margin: 0;
          left: auto;
          right: 10px;
          bottom: 2px;
          z-index: 9;
          font-size: 0;


          .carousel.vertical .carousel-indicators li
          border: none;
          cursor: pointer;
          display: inline-block;
          width: 18px;
          height: 18px;
          text-indent: -9999px;
          background: url("https://grgs.ro/1/i/sprite.png") no-repeat -528px -502px;


          .carousel.vertical.sliding .carousel-indicators li
          pointer-events: none;

          .carousel.vertical .carousel-indicators li.active
          background-position: -528px -524px;

          <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
          <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
          <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>


          <div class="container">
          <div id="myCarousel" class="carousel vertical slide" data-ride="carousel" data-interval="9000">
          <!-- Wrapper for slides -->
          <div class="carousel-inner">
          <div class="item active">
          <img src="https://picsum.photos/1200/300/?gravity=east" alt="">
          </div>

          <div class="item">
          <img src="https://picsum.photos/1200/300/?gravity=south" alt="">
          </div>

          <div class="item">
          <img src="https://picsum.photos/1200/300/?gravity=west" alt="">
          </div>
          </div>

          <!-- Indicators -->
          <ol class="carousel-indicators">
          <li data-target="#myCarousel" data-slide-to="0" class="active"></li>
          <li data-target="#myCarousel" data-slide-to="1"></li>
          <li data-target="#myCarousel" data-slide-to="2"></li>
          </ol>
          </div>
          </div>








          share|improve this answer











          $endgroup$



          Feedback



          The code seems fairly concise, though I do have suggestions below that can simplify it even more. I was hoping there was some class name applied to the element with class carousel during the slide transition but apparently the bootstrap code does not do that, though you could use the event callback functions to apply the class name yourself. That way the CSS style for pointer-events can be moved into the CSS.



          Because the .on() method accepts multiple events separated by a space, you can use one call for both events, and a single Partially applied function to call the .toggleClass() method, which will add and then remove a class to the carousel element:



          var carouselCollection = $('#myCarousel');
          carouselCollection.on('slide.bs.carousel slid.bs.carousel',
          carouselCollection.toggleClass.bind(carouselCollection, 'sliding'));


          Then the CSS can contain the style:



          .carousel.vertical.sliding .carousel-indicators li 
          pointer-events: none;



          See that working in the rewritten code below.



          I don't see much point in creating the function carouselDuration() and calling it immediately afterwards but then never again. Why not just move that single line out where it is called? I could see a point in doing that after some condition is met (e.g. DOM ready, jQuery/carousel ready, etc).



          Some of the CSS rulesets are a bit redundant. For instance, some of the top: 0 rulesets should be cascadable from .carousel.vertical .carousel-inner>.item and apply to the next three subsequent selectors.



          Also, I believe I was able to remove this block without any adverse affects. Are there really elements with class .right and .left or are those for the left/right controls that aren't being used?




          .carousel.vertical .carousel-inner>.next,
          .carousel.vertical .carousel-inner>.prev,
          .carousel.vertical .carousel-inner>.right
          transform: translate3d(0, 100%, 0);
          top: 0;




          Suggestions



          It would likely help to define that value for the duration as a constant (and if you are using ecmascript-6 then use const) at the top of the code, so it can be easily modified in the future if necessary.




          While there are only a couple redundant DOM queries (e.g. $(#myCarousel)) it would be wise to cache those in a variable.




          The event handler functions are very redundant, and violate the Don't Repeat Yourself principle. The only thing that appears to change is the value assigned to the CSS style pointer-events. If the approach mentioned above with the .toggleClass() method doesn't work, the common code in the two callback functions could be abstracted into a single function that accepts the value for that CSS style, and then Partially applied functions could be created with Function.bind() to fix the value to apply to the style.



          var carouselCollection = $('#myCarousel');

          function setPointerEventsOnListItems(value, e)
          var $indicator = carouselCollection.find('.carousel-indicators>li');
          $indicator.css('pointer-events', value);

          // While a transition is in progress (slide event), do this
          carouselCollection.on('slide.bs.carousel', setPointerEventsOnListItems.bind(null, 'none'));

          // While a transition has finished (slid event), do this
          carouselCollection.on('slid.bs.carousel', setPointerEventsOnListItems.bind(null, 'auto'));



          As you likely know, the jQuery DOM ready function would be good to use so as to avoid accidentally accessing the DOM before it is ready (though that isn't a problem as much nowdays with modern browsers and adding the script tags to the end of the <body>). An IIFE could also be used instead of that jQuery DOM ready callback.




          Rewritten code



          The code below utilizes the advice above, though utilizes the .toggleClass() method.






          var DURATION = 1000; //could use const instead of var if supporting es-6
          $(function() //DOM ready callback
          $.fn.carousel.Constructor.TRANSITION_DURATION = DURATION;
          var carouselCollection = $('#myCarousel');
          // While a transition is in progress (slide event), do this
          carouselCollection.on('slide.bs.carousel slid.bs.carousel', carouselCollection.toggleClass.bind(carouselCollection, 'sliding'));
          );

          .carousel.vertical 
          position: relative;


          .carousel.vertical .carousel-inner
          height: 100%;
          width: auto;


          .carousel.vertical .carousel-inner>.item
          width: auto;
          transition: 1s ease-in-out;
          transform: translate3d(0, 100%, 0);
          top: 0;


          .carousel.vertical .carousel-inner>.left,
          .carousel.vertical .carousel-inner>.prev.right,
          .carousel.vertical .carousel-inner>.next.left,
          .carousel.vertical .carousel-inner>.active
          transform: translate3d(0, 0, 0);


          .carousel.vertical .carousel-inner>.active.right,
          .carousel.vertical .carousel-inner>.active.left
          transform: translate3d(0, -100%, 0);


          .carousel.vertical .carousel-indicators
          display: inline-block;
          width: auto;
          padding: 0;
          margin: 0;
          left: auto;
          right: 10px;
          bottom: 2px;
          z-index: 9;
          font-size: 0;


          .carousel.vertical .carousel-indicators li
          border: none;
          cursor: pointer;
          display: inline-block;
          width: 18px;
          height: 18px;
          text-indent: -9999px;
          background: url("https://grgs.ro/1/i/sprite.png") no-repeat -528px -502px;


          .carousel.vertical.sliding .carousel-indicators li
          pointer-events: none;

          .carousel.vertical .carousel-indicators li.active
          background-position: -528px -524px;

          <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
          <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
          <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>


          <div class="container">
          <div id="myCarousel" class="carousel vertical slide" data-ride="carousel" data-interval="9000">
          <!-- Wrapper for slides -->
          <div class="carousel-inner">
          <div class="item active">
          <img src="https://picsum.photos/1200/300/?gravity=east" alt="">
          </div>

          <div class="item">
          <img src="https://picsum.photos/1200/300/?gravity=south" alt="">
          </div>

          <div class="item">
          <img src="https://picsum.photos/1200/300/?gravity=west" alt="">
          </div>
          </div>

          <!-- Indicators -->
          <ol class="carousel-indicators">
          <li data-target="#myCarousel" data-slide-to="0" class="active"></li>
          <li data-target="#myCarousel" data-slide-to="1"></li>
          <li data-target="#myCarousel" data-slide-to="2"></li>
          </ol>
          </div>
          </div>








          var DURATION = 1000; //could use const instead of var if supporting es-6
          $(function() //DOM ready callback
          $.fn.carousel.Constructor.TRANSITION_DURATION = DURATION;
          var carouselCollection = $('#myCarousel');
          // While a transition is in progress (slide event), do this
          carouselCollection.on('slide.bs.carousel slid.bs.carousel', carouselCollection.toggleClass.bind(carouselCollection, 'sliding'));
          );

          .carousel.vertical 
          position: relative;


          .carousel.vertical .carousel-inner
          height: 100%;
          width: auto;


          .carousel.vertical .carousel-inner>.item
          width: auto;
          transition: 1s ease-in-out;
          transform: translate3d(0, 100%, 0);
          top: 0;


          .carousel.vertical .carousel-inner>.left,
          .carousel.vertical .carousel-inner>.prev.right,
          .carousel.vertical .carousel-inner>.next.left,
          .carousel.vertical .carousel-inner>.active
          transform: translate3d(0, 0, 0);


          .carousel.vertical .carousel-inner>.active.right,
          .carousel.vertical .carousel-inner>.active.left
          transform: translate3d(0, -100%, 0);


          .carousel.vertical .carousel-indicators
          display: inline-block;
          width: auto;
          padding: 0;
          margin: 0;
          left: auto;
          right: 10px;
          bottom: 2px;
          z-index: 9;
          font-size: 0;


          .carousel.vertical .carousel-indicators li
          border: none;
          cursor: pointer;
          display: inline-block;
          width: 18px;
          height: 18px;
          text-indent: -9999px;
          background: url("https://grgs.ro/1/i/sprite.png") no-repeat -528px -502px;


          .carousel.vertical.sliding .carousel-indicators li
          pointer-events: none;

          .carousel.vertical .carousel-indicators li.active
          background-position: -528px -524px;

          <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
          <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
          <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>


          <div class="container">
          <div id="myCarousel" class="carousel vertical slide" data-ride="carousel" data-interval="9000">
          <!-- Wrapper for slides -->
          <div class="carousel-inner">
          <div class="item active">
          <img src="https://picsum.photos/1200/300/?gravity=east" alt="">
          </div>

          <div class="item">
          <img src="https://picsum.photos/1200/300/?gravity=south" alt="">
          </div>

          <div class="item">
          <img src="https://picsum.photos/1200/300/?gravity=west" alt="">
          </div>
          </div>

          <!-- Indicators -->
          <ol class="carousel-indicators">
          <li data-target="#myCarousel" data-slide-to="0" class="active"></li>
          <li data-target="#myCarousel" data-slide-to="1"></li>
          <li data-target="#myCarousel" data-slide-to="2"></li>
          </ol>
          </div>
          </div>





          var DURATION = 1000; //could use const instead of var if supporting es-6
          $(function() //DOM ready callback
          $.fn.carousel.Constructor.TRANSITION_DURATION = DURATION;
          var carouselCollection = $('#myCarousel');
          // While a transition is in progress (slide event), do this
          carouselCollection.on('slide.bs.carousel slid.bs.carousel', carouselCollection.toggleClass.bind(carouselCollection, 'sliding'));
          );

          .carousel.vertical 
          position: relative;


          .carousel.vertical .carousel-inner
          height: 100%;
          width: auto;


          .carousel.vertical .carousel-inner>.item
          width: auto;
          transition: 1s ease-in-out;
          transform: translate3d(0, 100%, 0);
          top: 0;


          .carousel.vertical .carousel-inner>.left,
          .carousel.vertical .carousel-inner>.prev.right,
          .carousel.vertical .carousel-inner>.next.left,
          .carousel.vertical .carousel-inner>.active
          transform: translate3d(0, 0, 0);


          .carousel.vertical .carousel-inner>.active.right,
          .carousel.vertical .carousel-inner>.active.left
          transform: translate3d(0, -100%, 0);


          .carousel.vertical .carousel-indicators
          display: inline-block;
          width: auto;
          padding: 0;
          margin: 0;
          left: auto;
          right: 10px;
          bottom: 2px;
          z-index: 9;
          font-size: 0;


          .carousel.vertical .carousel-indicators li
          border: none;
          cursor: pointer;
          display: inline-block;
          width: 18px;
          height: 18px;
          text-indent: -9999px;
          background: url("https://grgs.ro/1/i/sprite.png") no-repeat -528px -502px;


          .carousel.vertical.sliding .carousel-indicators li
          pointer-events: none;

          .carousel.vertical .carousel-indicators li.active
          background-position: -528px -524px;

          <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
          <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
          <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>


          <div class="container">
          <div id="myCarousel" class="carousel vertical slide" data-ride="carousel" data-interval="9000">
          <!-- Wrapper for slides -->
          <div class="carousel-inner">
          <div class="item active">
          <img src="https://picsum.photos/1200/300/?gravity=east" alt="">
          </div>

          <div class="item">
          <img src="https://picsum.photos/1200/300/?gravity=south" alt="">
          </div>

          <div class="item">
          <img src="https://picsum.photos/1200/300/?gravity=west" alt="">
          </div>
          </div>

          <!-- Indicators -->
          <ol class="carousel-indicators">
          <li data-target="#myCarousel" data-slide-to="0" class="active"></li>
          <li data-target="#myCarousel" data-slide-to="1"></li>
          <li data-target="#myCarousel" data-slide-to="2"></li>
          </ol>
          </div>
          </div>






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 5 mins ago

























          answered Nov 21 '18 at 20:19









          Sᴀᴍ OnᴇᴌᴀSᴀᴍ Onᴇᴌᴀ

          10.6k62168




          10.6k62168











          • $begingroup$
            Thank a lot for the feedback and the effort to rewrite the code. Can you help with the queuing mechanism or some other solution that would make the slider more user-friendly, meaning the the user would not have to click (temporarily) inactive bullets?
            $endgroup$
            – Razvan Zamfir
            Nov 27 '18 at 11:04










          • $begingroup$
            Please provide an answer to the topic An improvable use case of the Swiper slider. Thanks!
            $endgroup$
            – Razvan Zamfir
            Nov 27 '18 at 11:10










          • $begingroup$
            I hope you don’t get the wrong impression about this site, though maybe you have, since many answers offer a rewrite- especially easy with questions involving JS because snippets make it simple for demonstrating. Requests for code implementations are off-topic for this site.
            $endgroup$
            – Sᴀᴍ Onᴇᴌᴀ
            Nov 27 '18 at 11:55
















          • $begingroup$
            Thank a lot for the feedback and the effort to rewrite the code. Can you help with the queuing mechanism or some other solution that would make the slider more user-friendly, meaning the the user would not have to click (temporarily) inactive bullets?
            $endgroup$
            – Razvan Zamfir
            Nov 27 '18 at 11:04










          • $begingroup$
            Please provide an answer to the topic An improvable use case of the Swiper slider. Thanks!
            $endgroup$
            – Razvan Zamfir
            Nov 27 '18 at 11:10










          • $begingroup$
            I hope you don’t get the wrong impression about this site, though maybe you have, since many answers offer a rewrite- especially easy with questions involving JS because snippets make it simple for demonstrating. Requests for code implementations are off-topic for this site.
            $endgroup$
            – Sᴀᴍ Onᴇᴌᴀ
            Nov 27 '18 at 11:55















          $begingroup$
          Thank a lot for the feedback and the effort to rewrite the code. Can you help with the queuing mechanism or some other solution that would make the slider more user-friendly, meaning the the user would not have to click (temporarily) inactive bullets?
          $endgroup$
          – Razvan Zamfir
          Nov 27 '18 at 11:04




          $begingroup$
          Thank a lot for the feedback and the effort to rewrite the code. Can you help with the queuing mechanism or some other solution that would make the slider more user-friendly, meaning the the user would not have to click (temporarily) inactive bullets?
          $endgroup$
          – Razvan Zamfir
          Nov 27 '18 at 11:04












          $begingroup$
          Please provide an answer to the topic An improvable use case of the Swiper slider. Thanks!
          $endgroup$
          – Razvan Zamfir
          Nov 27 '18 at 11:10




          $begingroup$
          Please provide an answer to the topic An improvable use case of the Swiper slider. Thanks!
          $endgroup$
          – Razvan Zamfir
          Nov 27 '18 at 11:10












          $begingroup$
          I hope you don’t get the wrong impression about this site, though maybe you have, since many answers offer a rewrite- especially easy with questions involving JS because snippets make it simple for demonstrating. Requests for code implementations are off-topic for this site.
          $endgroup$
          – Sᴀᴍ Onᴇᴌᴀ
          Nov 27 '18 at 11:55




          $begingroup$
          I hope you don’t get the wrong impression about this site, though maybe you have, since many answers offer a rewrite- especially easy with questions involving JS because snippets make it simple for demonstrating. Requests for code implementations are off-topic for this site.
          $endgroup$
          – Sᴀᴍ Onᴇᴌᴀ
          Nov 27 '18 at 11:55

















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Code Review Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          Use MathJax to format equations. MathJax reference.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f207554%2funidirectional-bootstrap-3-carousel%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          名間水力發電廠 目录 沿革 設施 鄰近設施 註釋 外部連結 导航菜单23°50′10″N 120°42′41″E / 23.83611°N 120.71139°E / 23.83611; 120.7113923°50′10″N 120°42′41″E / 23.83611°N 120.71139°E / 23.83611; 120.71139計畫概要原始内容臺灣第一座BOT 模式開發的水力發電廠-名間水力電廠名間水力發電廠 水利署首件BOT案原始内容《小檔案》名間電廠 首座BOT水力發電廠原始内容名間電廠BOT - 經濟部水利署中區水資源局

          Prove that NP is closed under karp reduction?Space(n) not closed under Karp reductions - what about NTime(n)?Class P is closed under rotation?Prove or disprove that $NL$ is closed under polynomial many-one reductions$mathbfNC_2$ is closed under log-space reductionOn Karp reductionwhen can I know if a class (complexity) is closed under reduction (cook/karp)Check if class $PSPACE$ is closed under polyonomially space reductionIs NPSPACE also closed under polynomial-time reduction and under log-space reduction?Prove PSPACE is closed under complement?Prove PSPACE is closed under union?

          Is my guitar’s action too high? Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)Strings too stiff on a recently purchased acoustic guitar | Cort AD880CEIs the action of my guitar really high?Μy little finger is too weak to play guitarWith guitar, how long should I give my fingers to strengthen / callous?When playing a fret the guitar sounds mutedPlaying (Barre) chords up the guitar neckI think my guitar strings are wound too tight and I can't play barre chordsF barre chord on an SG guitarHow to find to the right strings of a barre chord by feel?High action on higher fret on my steel acoustic guitar