您的位置:首页 > 其它

location对象的href和hash属性

2016-11-26 17:10 316 查看
今天看到了一段代码

jQuery(document).ready(function($) {
$(".scroll").click(function(event){

event.preventDefault();
$('html,body').animate({scrollTop:$(this.hash).offset().top},1000);
});
});

当页面加载完成是。获取给.sroller对象绑定了click事件,当点击事件发生时,给html和body添加了一个animate动画。

给scrollTop属性赋值,用到了this.hash。

查阅文档,了解hash属性属于location对象。

window.location.href可以给页面重定向,跳转。而window.location.hash作用是设置当前链接的标签值;

例如window.location.hash='test'就是http://admin/test

而获取this.hash的作用就是获取当前链接的标签值
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  hash