平滑滚动问题 [英] Smooth Scrolling Issue
本文介绍了平滑滚动问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用以下js代码在页面上进行平滑滚动.问题是使用以下JS后,我无法使用MyCarousel导航.无论如何,有没有修复我下面的js,所以它不会影响我的轮播导航.发生此问题是由于轮播导航上的#
(href =#myCarousel").因此,在那种情况下,该问题如何解决.
I am using following js code for the smooth scrolling on the page. The issue is I am not able to use the navigation of mycarousel after using following JS . Is there anyway to fix my following js so it doesnot effect my carousel to navigate. This issue is happening because of #
(href="#myCarousel") on the carousel navigation. So in that case how can the issue be resolved.
$(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;
}
}
});
});
我的轮播导航:
<a class="left carousel-control" href="#myCarousel" data-slide="prev"><span class="glyphicon glyphicon-chevron-left"></span></a>
<a class="right carousel-control" href="#myCarousel" data-slide="next"><span class="glyphicon glyphicon-chevron-right"></span></a>
推荐答案
这对我有用.我替换了
$('a[href*=#]:not([href=#])').click(function() {
使用
$('a[href*=#]:not([href=#carousel-example-generic])').click(function() {
其中#carousel-example-generic可以是控件所指向的轮播的名称
where #carousel-example-generic can be the name of the carousel that the controls are pointing to
这篇关于平滑滚动问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文