$('a.gotoheader').click(function(){
// 讓捲軸移動到 0 的位置
$('html, body').scrollTop();
// ignore link "#" method
return false;
});
//在scroll時加入動畫效果
$('a.gotoheader').click(function(){
// 修正 Opera 問題
var $body = (window.opera) ? (document.compatMode == "CSS1Compat" ? $('html') : $('body')) : $('html,body');
$body.animate({
scrollTop:
}, ); return false;
});
//scroll到頁面指定的位置,最後再加上easeOutBounce 的動畫效果
$('a.gotoheader').click(function(){
// 修正 Opera 問題
var $body = (window.opera) ? (document.compatMode == "CSS1Compat" ? $('html') : $('body')) : $('html,body');
$body.animate({
scrollTop: $('#header').offset().top
}, , 'easeOutBounce'); return false;
});

想要ignore link "#" method, 當click一個link時,page不要跳轉,可使用

<a href="javascript:void(0);">Example</a>

來代替

<a href="#">Example</a>

也可以使用上面例子中提到在,onclick事件觸發後的function中 return false;

另外一種方法就是使用 event.preventDefault(); 取消事件的預設行為

<!DOCTYPE html>
<html>
<head>
<title>preventDefault example</title>
</head> <body>
<p>Please click on the checkbox control.</p>
<form>
<label for="id-checkbox">Checkbox</label>
<input type="checkbox" id="id-checkbox"/>
</form>
<script>
document.querySelector("#id-checkbox").addEventListener("click", function(event){
alert("preventDefault will stop you from checking this checkbox!")
event.preventDefault();
}, false);
</script>
</body>
</html>

最新文章

  1. [转](二)unity4.6Ugui中文教程文档-------概要-UGUI Canvas
  2. UnityException: Texture is not readable
  3. DOM笔记(九):引用类型、基本包装类型和单体内置对象
  4. 当调用List Remove 失效时 [C#] .
  5. 使用get方式提交数据
  6. 教你50招提升ASP.NET性能(二十三):StringBuilder不适用于所有字符串连接的场景;String.Join可能是
  7. 使用AndroidScreenSlidePager开源库
  8. node http.request请求
  9. [转] ubuntu 12.04 安装 nginx+php+mysql web服务器
  10. 给Eclipse安装Google app engine插件
  11. Linux下tomcat的安装详解
  12. BOM API
  13. Java框架概述
  14. 记我的第二次自动化尝试——selenium+pageobject+pagefactory实现自动化下单、退款、撤销回归测试
  15. [Swift]LeetCode715. Range 模块 | Range Module
  16. Scala(四) —— 集合
  17. JS操作字符串
  18. php重定向http请求
  19. select函数用法详解
  20. MySQL基础(二):视图、触发器、函数、事务、存储过程

热门文章

  1. NOIP2013积木大赛 [贪心]
  2. codepush安装
  3. 批量把pod实例调成0
  4. Launch4j:An error occurred while starting the application.解决方案
  5. 使用pytesseract进行图像识别
  6. 笔记-读官方Git教程(1)~认识Git
  7. FCS省选模拟赛 Day4
  8. Redis哨兵参数
  9. DM中将有缝隙的面体缝合为实体
  10. 使用ListView应该注意的地方