简体   繁体   中英

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. 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. 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. 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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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