首页 > 解决方案 > 如何从 url 中删除 # 并在没有 # 的情况下使用 Javascript

问题描述

我有用于带有锚点的滑动页面的分页 jquery 并且工作得很好,但我想让它运行 whitout 来自 url ex: www.mysite.com/#aboutme <- 的 # 页面,点击

在此处查看插件:https ://github.com/alvarotrigo/pagePiling.js

这是我到目前为止所拥有的:

HTML:

<div class="collapse navbar-collapse sub-menu-bar" id="navbarSupportedContent">
   <ul class="navbar-nav m-auto">                        
     <li data-menuanchor="home" class="active"> <a href="">Home</a></li>
     <li data-menuanchor="aboutme"><a href="#despremine">About me</a></li>
   </ul>
</div> 

JS:

var myAnchors = [];
$( ".navbar-nav > li" ).each(function( index ) { myAnchors.push($(this).attr("data-menuanchor")); }); 

$('.fullpage-slider').pagepiling({
    scrollingSpeed: 280,
    navigation:false,
    menu: '.fullpage-progress-bar, .navbar-nav',
    sectionSelector: '.pp-scrollable',
    anchors: myAnchors,
    afterRender: function(anchorLink, index){ 
      NavbarColor(); 
    },
    afterLoad: function(anchorLink, index){ 
        $('.pp-scrollable .section-number').removeClass('show');
        $('.active .section-number').addClass('show');
        NavbarColor();
    } 

标签: javascripthtmljquerypagepiling.js

解决方案


pagePiling.js 网站上实际上有一个演示可以做到这一点: https ://alvarotrigo.com/pagePiling/examples/noAnchor.html

基本上,在初始化期间不要使用该anchors属性,你应该可以去:)


推荐阅读