Bootstrap Carousel Jumps to top of page when advancing

前端 未结 12 2347
挽巷
挽巷 2021-02-15 03:20

When I advance the slider manually, the slider jumps to the top of the page. How can I prevent this from happening? Help much appreciated! Here\'s the code:

<         


        
12条回答
  •  没有蜡笔的小新
    2021-02-15 03:34

    You can either do this inline (less clean) :

    
      
    
    
      
    
    

    or you can do globally assuming you remove the href="#controlid :

    $('body').on('click','.carousel-control',function() {
       $(this).closest('.carousel').carousel( $(this).data('slide') );
    });
    

    or you can do it individually by being more specific in your selector

    $('body').on('click','#carouselID .carousel-control',function() {
       $(this).closest('.carousel').carousel( $(this).data('slide') );
    });
    

提交回复
热议问题