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的作用就是获取当前链接的标签值
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的作用就是获取当前链接的标签值
相关文章推荐
- window.location.hash属性介绍 ajax后退按钮失效问题
- window.location.hash属性介绍
- window.location.hash属性介绍
- window.location.hash属性介绍
- window.location.hash属性介绍
- window对象的status、location、name、self、opener属性的使用
- bobowindow.location.hash 属性使用说明
- location.href target属性
- window.location 对象所包含的属性
- window.location.hash属性介绍
- TWebBrowser 与 MSHTML(4): location、history、screen、navigator 对象的属性与方法纵览
- window.location.hash属性介绍
- window.location.hash属性介绍
- window.location.hash属性介绍
- window.location.hash属性介绍
- window.location.hash属性介绍
- window.location.hash属性介绍
- 【js与jquery】window.location.hash属性介绍
- javascript window对象的status、location、name、self、opener属性的使用
- window对象的status、location、name、self、opener属性的使用