因此,这是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上,代码可以正常工作而没有任何问题。但是,当我尝试将其插入我的文本编辑器并运行它时,开发人员工具发出了警告,指出“顶部”未定义-但它在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>
尝试单击引发“未定义的顶部”错误的链接,检查并检查其href属性是否已定义且不为空。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句