我想使用 bootsraps 轮播和 jquery 的平滑滚动。
下面是我实现平滑滚动的方法:
$('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
}, 2000);
return false;
}
}
});
我假设此代码会阻止轮播按钮的功能。如何以不影响轮播按钮的方式修改它。
请注意,我是网络开发的初学者。
谢谢。
最佳答案
如果我正确理解了这个问题,我认为你可以做以下两件事之一:
Namespace平滑滚动点击事件以避免与 轮播。
例如
$('a').on('click.scroll', function() {…})
- 允许event propagation在平滑滚动功能中删除
return false;
希望对您有所帮助!
关于javascript - click.function 和 Bootstrap 的轮播按钮之间的冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35398055/