javascript - 如何从 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();
}
解决方案
pagePiling.js 网站上实际上有一个演示可以做到这一点: https ://alvarotrigo.com/pagePiling/examples/noAnchor.html
基本上,在初始化期间不要使用该anchors
属性,你应该可以去:)
推荐阅读
- javascript - 如何使用 jquery 在最后一个单词之前得到一个单词
- docker - 驱动程序在端点 clickstre 上编程外部连接失败
- prestashop - prestashop 维护页面自定义 css 不起作用
- unity3d - 子弹射不准
- angular - Angular复杂的项目结构
- python - 在 python 中创建 venv 并克隆 git repo 的操作
- node.js - NestJS 和 MongoDB | CastError:模型“Player”的路径“_id”处的值“1”转换为 ObjectId 失败
- reactjs - 月度统计图表 Reactjs
- javascript - 在 JavaScript 中创建 DOM 对象
- xml - XSD - cvc-elt.4.2:无法将“{1}”解析为元素“{0}”的类型定义