繁体   English   中英

带有网址的一页网站导航

[英]navigation for one-page site with url

我有一个一页网站,并在其上链接如<a href="#block1">link1</a> 浏览器地址栏显示site.com/#block1

我希望浏览器输入类似于site.com/block1的行,然后单击链接site.com/block1后,浏览器将打开滚动页面至所需的块。

这个jsfiddle很简单,但是不起作用http://jsfiddle.net/26LRA/2/

应该没有魔术,没有php,cms,sql和其他插件。 仅纯javascript / jquery

添加:我根据需要为您提供了该站点http://www.ascensionlatorre.com ,但我无法理解其代码

您的意思是您只想明显地更改URL:

$("#name0 a").click(function(e) {
    e.preventDefault();
    var id = $(this).attr('href').substring(1);
    $('html,body').animate({scrollTop: $('#'+id).offset().top}, 'fast');
    window.history.pushState("", "", '/' + id);
});

为了使链接真正起作用,您需要mod_rewrite ,进行.htaccess并添加:

RewriteRule ^portfolio$ /index.php/#$1 [QSA,NE]

阅读网址

var path = document.location.pathname;
path = path.substring(path.lastIndexOf('/'), 1);
if(path){
    $('html,body').animate({scrollTop: $('#'+path).offset().top}, 'fast');
}

我认为执行此操作的正确方法是在.htaccess中使用mod_rewrite。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM