mar*_*nes 2 javascript jquery jquery-plugins smooth-scrolling
我目前正在使用jQuery-Smooth-Scroll平滑地向上和向下滚动到我的一个页面上的各个锚位置(页面1).但是,我还希望能够做的是,从另一个页面(页面2)链接到Page1(将#bookmark附加到URL)并让jQuery-Smooth-Scroll选择我调用页面的事实使用#bookmark并在页面完成加载后顺利向下滚动到相关位置.我不知道这是否可能?
这是我正在使用的Smooth-Scroll版本:
https://github.com/kswedberg/jquery-smooth-scroll
我仍然是jQuery的新手,所以我可能会忽略一些明显的东西.
Ajma的答案应该足够了,但为了完整性:
alert(location.hash)
Run Code Online (Sandbox Code Playgroud)
编辑:一个更完整的例子:
// on document.ready {
if (location.hash != '') {
var a = $("a[name=" + location.hash.substring(1) + "]");
// note that according to w3c specs, the url hash can also refer to the id
// of an element. if so, the above statement becomes
// var a = $(location.hash);
if (a.length) {
$('html,body').animate({
scrollTop: $(a).offset().top
}, 'slow');
}
}
// }
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5145 次 |
| 最近记录: |