How can I move to an anchor on a page when I'm using Sammy.js? [duplicate]

孤者浪人 提交于 2019-12-19 08:51:56

问题


Possible Duplicate:
How to scroll HTML page to given anchor using jQuery or Javascript?

I'm using Sammy.js, and it handles all the client-side URL navigation. I want to navigate to /page#fragment, but the page wont actually go to #fragment. How can I make it do that, either automatically, or by writing code to go to the fragment?


回答1:


Sammy doesnt automatically trigger the route, so in your handler you need to add:

hash = window.location.hash
if(hash != '') { 
    window.location.hash = hash;
}


来源:https://stackoverflow.com/questions/10113103/how-can-i-move-to-an-anchor-on-a-page-when-im-using-sammy-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!