我坚持使用这个javascript / jquery代码

时间:2014-04-22 03:59:07

标签: javascript jquery html css

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上,代码工作正常没有任何问题。但是当我尝试将其插入我的文本编辑器并运行它时,开发人员工具发出警告,指出“顶部”未定义 - 但它在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>

1 个答案:

答案 0 :(得分:0)

尝试点击抛出“top”未定义“错误的链接,检查并检查其href属性是否已定义且不为空。