我被这个javascript/jquery代码卡住了
I am stuck with this javascript/jquery code
http://jsfiddle.net/YtJcL/
下面是jsfiddle.net 的代码
$(".scroll").click(function(event){
event.preventDefault();
//calculate destination place
var dest=0;
if($(this.hash).offset().top > $(document).height()-$(window).height()){
dest=$(document).height()-$(window).height();
}else{
dest=$(this.hash).offset().top;
}
//go to destination
$('html,body').animate({scrollTop:dest}, 1000,'swing');
});
问题是,在JSFiddle上,代码运行良好,没有任何问题。但是,当我尝试将它插入文本编辑器并运行它时,开发人员工具会发出警告,指出"top"是未定义的——但它在JSFiddle中运行得非常好。
有人知道为什么吗?
::编辑::这是中的内容
<head>
<script src="ajax.googleapis.com/ajax/libs/jquery-1.11.0.js"></script>
<script src="bootstrap.min.js"></script>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<link rel="shortcut icon" href="../../assets/ico/favicon.ico">
<script type="text/javascript" src="app.js"></script>
<title>M Y | Portfolio</title>
<!-- Bootstrap core CSS -->
<link href="bootstrap.min.css" rel="stylesheet">
<link href="carousel.css" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="jumbotron.css" rel="stylesheet">
</head>
尝试单击引发"top"is undefined"错误的链接,检查它并检查其href属性是否已定义且不为空。
相关文章:
- 如何动态插入jquery代码
- 如何在php变量中嵌入JQuery代码
- 将 jQuery 代码添加到 Index.aspx 页面
- 元素在我的代码中不会.fadeTo.Don'I don’我不知道;s错误的JavaScript、JQuery、H
- jquery代码在Mozilla中有效,但在其他浏览器上无效
- Jquery:代码在rails中的页面加载时未执行
- 您有更好的动态方式来缩短复杂的代码jquery吗
- Don't工作警报代码jQuery
- <script src=“//代码.jquery.com/jquery-1.11.1.min.js”></
- 如何确保我的值已添加并存在,然后运行另一个代码jquery
- 命令代码jquery文件错误
- 解释此代码 jQuery
- 使用 JavaScript 编写 HTML 代码 (jquery)
- 将 Ruby 数组传递给 Ruby on Rails 中 Haml 视图中的 JavaScript 代码 (jquery
- 通过国家代码jquery获取时区
- 什么是错误的这个自动完成代码(JQuery-UI自动完成)
- 抓取国家从谷歌地理代码jquery
- 检查列表中的元素是否有来自变量的SRC,然后运行代码- jQuery / Javascript
- 在附加代码jquery中包含附加内容
- 将变量php问题化为代码jquery