Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/438.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/apache-spark/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
javascript滚动不工作_Javascript_Jquery_Html_Ruby On Rails - Fatal编程技术网

javascript滚动不工作

javascript滚动不工作,javascript,jquery,html,ruby-on-rails,Javascript,Jquery,Html,Ruby On Rails,我希望我的链接向下滚动页面到目标内容 这是我的脚本(在head标签中): jQuery(文档).ready(函数($){ $(“.scroll”)。单击(函数(事件){ event.preventDefault(); $('html,body').animate({scrollTop:$(this.hash.offset().top},1200); }); }); 以下是我的链接(在body标签内): 这些代码块在我的application.html.erb中 提前谢谢你 检查$(thi

我希望我的链接向下滚动页面到目标内容

这是我的脚本(在head标签中):


jQuery(文档).ready(函数($){
$(“.scroll”)。单击(函数(事件){
event.preventDefault();
$('html,body').animate({scrollTop:$(this.hash.offset().top},1200);
});
});
以下是我的链接(在body标签内):


这些代码块在我的application.html.erb中

提前谢谢你

检查$(this.hash).offset().top值; log($(this.hash).offset().top);
看这个

我的问题不在上面的代码中,但实际上我的application.js缺少require_树行,因此它不会加载其他js文件。虽然下面的答案不是我问题的解决方案(这就是为什么我没有选择它)@yodfz_cn非常有用,谢谢

它实际上指向目标内容,但动画不会工作,我的意思是,它不是一个平滑的过渡。这是我得到的:未捕获类型错误:无法读取未定义(索引)的属性“top”):80(匿名函数)到底什么是未定义的,你知道吗?this.hash未定义,编辑它,那么,this.hash从哪里来?或者什么是杂烩?
<script type="text/javascript">
    jQuery(document).ready(function($) {
        $(".scroll").click(function(event){     
            event.preventDefault();
        $('html,body').animate({scrollTop:$(this.hash).offset().top},1200);
        });
    });
</script>
<%= link_to 'Plataformas', root_path + '#plataformas', class: "scroll" %>
<%= link_to 'Contato', root_path + '#contato', class: "scroll" %>