简体   繁体   English

根据网址滚动网页

[英]Scroll webpage based on url

So I'm building a website that's basically one page but the links at the top just scroll to a different location on the page. 因此,我正在构建一个基本上是一页的网站,但是顶部的链接只是滚动到页面上的其他位置。 Here's an example: http://evanstoddard.site90.net . 这是一个示例: http : //evanstoddard.site90.net

If I were to give a link to, in the example above, the about page I would simply give that person a link that looked like http://evanstoddard.site90.net/#about and that link would go to the about section of that website. 如果要在上面的示例中为about页面提供一个链接,我只需给该人一个看起来像http://evanstoddard.site90.net/#about的链接,该链接将转到的about部分。该网站。

Let's say I wanted to do the same thing except instead of adding the '#about" I would use /about . So it would end up looking like http://evanstoddard.site90.net/about but do the exact same thing as #about . This would be better for SEO I'm assuming. 假设我想做同样的事情,除了不添加'#about“我将使用/about 。所以最终看起来像http://evanstoddard.site90.net/about,但做的却与#about完全相同#about这将是搜索引擎优化,我假设更好。

Any help would gladly be appreciated. 任何帮助将不胜感激。 Or even a "you're crazy... it will never work" ;) 甚至是“您疯了……它将永远无法工作”;)

Long story short, I want to display ' http://evanstoddard.site90.net/about ' and have it do the exact same thing as ' http://evanstoddard.site90.net/#about ' 长话短说,我想显示“ http://evanstoddard.site90.net/about ”,并使其与“ http://evanstoddard.site90.net/#about ”完全相同

You're not crazy at all and it will work :) 您一点也不疯,它会起作用的:)

You should edit your .htaccess so that everything after your domain would be sent to the same page (index.php I assume) as GET params and work from there. 您应该编辑.htaccess文件,以便将域之后的所有内容都发送到与GET参数相同的页面(我假设是index.php)并从那里进行工作。 Now you can get the URL on page load using javascriptO OR "digest" the parameters in PHP and output it to the client side. 现在,您可以使用javascriptO或“摘要” PHP中的参数来获取页面加载时的URL,并将其输出到客户端。 jQuery scrollTo might help you with scrolling to whatever you need. jQuery scrollTo可能会帮助您滚动到所需的内容。

That's how it might be done in .htaccess (that's how it's done in Kohana): 这就是在.htaccess中完成的方式(在Kohana中完成了):

RewriteRule .* index.php/$0 [PT]

And this should help you with scrolling. 应该可以帮助您进行滚动。

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

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