Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Twitter Bootstrap Carousel: Right & Left arrows not working

The arrows for BS carousel are not moving the items back and forth

I'm suspecting this might be either a CSS issue or have something to do with the fact that the carousel is being used inside the tabs.

like image 458
farjam Avatar asked Oct 18 '25 07:10

farjam


1 Answers

I had the same problem, it was caused because my page was scroll based so I put in a little script to smooth the scroll of every link which started with # . This screwed the left and right buttons because they use href="#myCarousel".
To solve this problem I added an exception to the script like down here.
This is the script before I modified it:

$(function() {
    $('a[href*=#]:not([href=#])').click(function() {
        if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
            var target = $(this.hash);
            target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
            if (target.length) {
                $('html,body').animate({
                    scrollTop: target.offset().top
                }, 1000);
                return false;
            }
        }
    });
});

And I just added an exception with thw href attribute:

$(function() {
    $('a[href*=#]:not([href=#])').click(function() {
        if( $(this).attr("href")=="#myCarousel") return;//This is the exception
        if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
            var target = $(this.hash);
            target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
            if (target.length) {
                $('html,body').animate({
                    scrollTop: target.offset().top
                }, 1000);
                return false;
            }
        }
    });
});

This answer is year and a half late but I hope it helps someone else.

edit 3/12/2015:
You can also use the data-target attribute instead of href

like image 146
Mark E Avatar answered Oct 19 '25 23:10

Mark E



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!