使用锚标签的平滑滚动时左右轮播控件不起作用 [英] Left and Right Carousel Controls not Working when Smooth Scroll for Anchor Tags Used

查看:103
本文介绍了使用锚标签的平滑滚动时左右轮播控件不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下脚本来平滑锚标记的滚动效果:

I am using the following script for smooth scroll effect for anchor tags:

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

使用此脚本后,Bootstrap Carousel的向左和向右控件停止工作.

After using this script the Left and Right controls for Bootstrap Carousel stopped working.

<a class="left carousel-control" href="#home-carousel" role="button" data-slide="prev">
                <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
                <span class="sr-only">Previous</span>
            </a>
            <a class="right carousel-control" href="#home-carousel" role="button" data-slide="next">
                <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
                <span class="sr-only">Next</span>
            </a>

我该如何解决?

推荐答案

然后,您只需编辑代码即可进行平滑滚动,具体取决于您是否具有ID header-menu或类header-menu

Then you just have to edit you code for the smooth scroll like this, depending if you have the ID header-menu or class header-menu

更改

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

到(如果使用ID标头菜单)

to (if you use the ID header-menu)

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

或(如果使用类标题菜单):

or (if you use the class header-menu):

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

这样,您将只将平滑滚动效果集中在菜单href元素上,并且脚本不会与您的bootstrap hrefs冲突".

This way you will only focus the smooth scroll effect on the menu href elements, and the script will not "collide" with you bootstrap hrefs.

这篇关于使用锚标签的平滑滚动时左右轮播控件不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆