【问题标题】:Why onclick event doesn't work in Firefox? [duplicate]为什么 onclick 事件在 Firefox 中不起作用? [复制]
【发布时间】:2015-12-06 15:25:42
【问题描述】:

我有一个可以在 Chrome 中运行的 javascript 代码,但它拒绝在 Mozilla Firefox 中运行。为什么会这样?

我的Codepen sandbox

HTML

<div class="scroll-arrows">CLICK TO SCROLL</div>

CSS

body{
  height: 2000vh;
}

JS

$(document).on('click', '.scroll-arrows', function() {
  return $('body').animate({
    scrollTop: 400
  }, 'slow');
});

【问题讨论】:

  • 问题不在于处理“点击”事件;效果很好,因为快速介绍 console.log() 呼叫会告诉您。
  • 要处理 FF,请使用 $('html, body').animate({...});。仅供参考,您的 return 声明在这里没有任何意义

标签: javascript jquery html firefox


【解决方案1】:

正如Animate scrollTop not working in firefox中已经提到的那样

你必须使用$('body,html').animate( {scrollTop: 400}, 'slow');

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-02
    • 1970-01-01
    • 2018-11-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多