问题

我在个人站点的左下角和右下角各自使用了如下代码来将页面滚动到顶部和底部:

$("body").animate({scrollTop:0},800);

$("body").animate({scrollTop:$(document).height()},800);

最近才忽然发现在Chrome浏览器下,上面的代码没有问题,而在Firefox下却是无效的。百度后才知道,原来这是因为这两个浏览器自身的问题导致的。

对于Chrome而言,支持的是这种写法:

$("body").animate({"scrollTop":top});

而对于Firefox,则是支持如下写法:

$("html").animate({"scrollTop":top});

之前就一直耳闻前端开发需要兼容不同浏览器,非常地麻烦,今天算是见识到了冰山一角。

解决方法

既然这两个浏览器各自支持一种标签选择器,那么只要把两者统合起来即可实现兼容:

$("html,body").animate({"scrollTop":top});

最终,将我的代码改成如下形式便没问题了:

$("html,body").animate({scrollTop:0},800);

$("html,body").animate({scrollTop:$(document).height()},800);

参考链接

随机推荐

  1. ESP8266串口模块的基本使用【转】

    本文转载自:http://www.shaoguoji.cn/2017/01/15/ESP8266-usage/ ESP8266是一款超低功耗的UART-WiFi 透传模块,拥有业内极富竞争力的封装尺寸 ...

  2. html-webpack-plugin 中使用 title选项设置模版中的值无效

    原文地址:https://segmentfault.com/q/1010000004555431 webpack.config.js配置: var webpack = require("we ...

  3. Linux学习之路(五)压缩命令

    常用压缩格式: .zip .gz .bz2 常用压缩格式: .tar.gz .tar.bz2 .zip格式压缩 .zip 压缩文件名 源文件 #压缩文件 .zip -r 压缩文件名 源目录 #压缩目录 ...

  4. Highcharts小数保留两位方法

    tooltip: { valueSuffix: '%', formatter:function(){ return''+this.series.name+' '+Highcharts.numberFo ...

  5. linux增加vlan网卡配置

    1.编辑文件/etc/sysconfig/network在里面添加一行:VLAN=yes2.再生成网卡设备的配置文件ifcfg-eth1.10和ifcfg-eth1.240cd /etc/syscon ...

  6. CodeForces - 1005E2:Median on Segments (General Case Edition) (函数的思想)

    You are given an integer sequence a1,a2,…,ana1,a2,…,an. Find the number of pairs of indices (l,r)(l, ...

  7. manacher(无讲解)

    BZOJ3325: [Scoi2013]密码 https://lydsy.com/JudgeOnline/problem.php?id=3325 分析: 根据前i个字符和一些不等和相等条件就可以确定每 ...

  8. ACM学习历程—SNNUOJ 1116 A Simple Problem(递推 && 逆元 && 组合数学 && 快速幂)(2015陕西省大学生程序设计竞赛K题)

    Description Assuming a finite – radius “ball” which is on an N dimension is cut with a “knife” of N- ...

  9. ACM学习历程——UVA10112 Myacm Triangles(计算几何,多边形与点的包含关系)

    Description   Problem B: Myacm Triangles Problem B: Myacm Triangles Source file: triangle.{c, cpp, j ...

  10. Tensorflow知识点学习

    1.TensorFlow中Tensor维度理解: (1)对于2维Tensor 0维对应列 1维对应行 (2)维度操作举例: 对于k维的,tf.reduce_sum(x, axis=k-1)的结果是对最 ...