简体   繁体   English

单页网站网址?id = 1#anchor

[英]Single page site url?id=1#anchor

I have a single page site on which I show a few lines of the 2 latest news on the start page. 我有一个页面网站,在该网站上,我会在首页上显示几行2条最新新闻。 When you click the read more link, the page should scroll to the news section and there you should read the full news. 当您单击“阅读更多”链接时,页面应滚动到新闻部分,在那里您应阅读完整新闻。 The scroll part/show full news are ok but I have no idea how to put them together. 滚动部分/显示完整新闻是可以的,但是我不知道如何将它们放在一起。 This URL format is not working www.example.com?id=1#news. 此URL格式无法正常运行www.example.com?id=1#news。 It either does not scroll or it just jumps to the news section. 它要么不滚动,要么跳到新闻部分。 TX 德克萨斯州

EDIT: In the end I am using the data-elemid to pass the newsId variable to an ajax call. 编辑:最后,我使用data-elemid将newsId变量传递给ajax调用。 Everything works as it should now. 一切正常。

Try something like this: 尝试这样的事情:

$(function(){
    var hash = window.location.hash;
    if(hash != "") scrollTo(hash);
});

This will check if the current URL has a hash, if it does, then call the scrollTo() method (you should replace this with your own scroll method). 这将检查当前URL是否具有哈希(如果有),然后调用scrollTo()方法(您应将其替换为自己的scroll方法)。

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

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