Smooth Scrolling Issue

痴心易碎 提交于 2019-12-11 20:19:40

问题


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;
      }
    }
  });
});

MY Carousel Navigation:

<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>

回答1:


Replace this

$('a[href*=#]:not([href=#])').click(function() {

with:

$('a[href*=#]:not([href=#media])').click(function () { 

Happy coding!




回答2:


This worked for me. I replaced

$('a[href*=#]:not([href=#])').click(function() {

with

$('a[href*=#]:not([href=#carousel-example-generic])').click(function() {

where #carousel-example-generic can be the name of the carousel that the controls are pointing to



来源:https://stackoverflow.com/questions/20046956/smooth-scrolling-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!