【问题标题】:Close Modal After Smooth Scrolling Reaches Anchor平滑滚动到达锚点后关闭模态
【发布时间】:2016-03-03 20:46:48
【问题描述】:

我正在使用 Bootstrap,而常规导航当前使用平滑滚动脚本,该脚本可以转到页面的各个部分。

对于移动设备,我有一个全屏导航模式,一旦您单击汉堡包图标就会打开。它也将使用平滑滚动,但是一旦您单击菜单中的链接并将您带到该部分,我似乎无法关闭模式。

脚本

$(function() {
  $('a[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;
      }
    }
  });
$('#myModal').modal('hide');
});

【问题讨论】:

    标签: jquery twitter-bootstrap bootstrap-modal smooth-scrolling


    【解决方案1】:
    $('#myModal').hide();
    

    或许

    $('#myModal').remove();
    

    【讨论】:

    • 我发现了错误。我只是将它添加到菜单滚动后立即触发。所以就在 return 语句之前。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-05-05
    • 1970-01-01
    • 2015-07-29
    • 2014-10-26
    • 2023-04-02
    • 1970-01-01
    • 2013-08-14
    相关资源
    最近更新 更多