Answer the question
In order to leave comments, you need to log in
JS scroll script conflict with Bootstrap?
Good day.
I'm building a website with Bootstrap. When adding a carousel, there is a conflict with the script for scrolling through the page.
When you click on the slider link, it jumps to the anchor of the block.
Scroll script:
/**
* scroll-menu
*/
!function ($) {
var menu_selector = ".scroll-menu";
function onScroll(){
var scroll_top = $(document).scrollTop();
$(menu_selector + " a").each(function(){
var hash = $(this).attr("href");
var target = $(hash);
if (target.position().top <= scroll_top && target.position().top + target.outerHeight() > scroll_top) {
$(menu_selector + " a.active").removeClass("active");
$(this).addClass("active");
} else {
$(this).removeClass("active");
}
});
}
$(document).ready(function () {
$(document).on("scroll", onScroll);
$("a[href^=#]").click(function(e){
e.preventDefault();
$(document).off("scroll");
$(menu_selector + " a.active").removeClass("active");
$(this).addClass("active");
var hash = $(this).attr("href");
var target = $(hash);
$("html, body").animate({scrollTop: target.offset().top}, 500, function(){
window.location.hash = hash;
$(document).on("scroll", onScroll);
});
});
});
}(window.jQuery);
<div class="carousel-control">
<a class="carousel-control-prev" href="#carousel-example-generic" role="button" data-slide="prev">Previous</a>
<a class="carousel-control-next" href="#carousel-example-generic" role="button" data-slide="next">Next</a>
</div>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question