javascript - 使用无法在手机上正常工作的 anchor 标记从页面重定向到其他页面的特定部分

标签 javascript html css mobile

有人遇到过这个问题吗? 通过 anchor 标记重定向时,网站不会滚动到正确的位置。 例如,在 about.html 页面上,我单击一个 anchor 标记,将我带到 index.html#form。 它具有随机行为。有时会带我进入表格,有时不会。在手机上解决这个问题。

最佳答案

您网站 Assets 中的以下脚本 ~ js/script.js 是罪魁祸首:

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

    if(this.href != undefined){
      var a = this.href.split('#');
      if(a[1] != 'collapseOne' && a[1] != 'collapseTwo' && a[1] != 'collapseThree' && a[1] != 'collapseFour' && a[1] != 'collapseFive'
          && a[1] != 'collapseSix' && a[1] != 'collapseSeven' && a[1] != 'collapseEight' ) {
        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;
          }
        }
      } 
    }
  });
});

它提供平滑的滚动,并用 (root/index.html) 替换更改后的 URL (root/index.html#miniForm),这使得无法导航到特定的 div

您可以替换 URL 替换代码段,并可以使用提供的功能来实现平滑滚动。

关于javascript - 使用无法在手机上正常工作的 anchor 标记从页面重定向到其他页面的特定部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43428984/

相关文章:

javascript - 如何访问 angularjs 中 ng-repeat 中调用的组件中的索引?

html - 是否存在用于在本地测试网站的 Ipad 模拟器

css - Glyphicon 在本地工作但在 Heroku 上不工作

php - 从 JavaScript 数组对象中的值中删除引号

php - javascript、ajax、PHP 插入 onSubmit 不工作...POST 未设置

php - PHP/HTML:向mysql插入数据错误,请看看

javascript - 如果在 bootstrap 表中应用了 rowspan,则无法选择整行

javascript - 丑陋的引导日期选择器

javascript - Firefox 不加载脚本

javascript - Selenium 找不到元素的原因有哪些?