var bs = new Browser();
if(bs.userBrowser() == 'firefox'){
document.body.addEventListener("DOMMouseScroll", test, false);
}else {
document.body.onmousewheel = test;
}
function test() {
alert("---------");
}

代码中用到的Browser对象

/* 浏览器相关 */
var Browser = function() {
this.browserName = navigator.userAgent.toLowerCase();// agent
this.browserVersion = (this.browserName.match(/.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/) || [0, '0'])[1];// 浏览器版本
}
Browser.prototype.userBrowser = function(argument) {// 获取浏览器名称--chrome/firefox/ie/safari
if (/msie/i.test(this.browserName) && !/opera/.test(this.browserName)) {
return "ie";
} else if (/firefox/i.test(this.browserName)) {
return "firefox";
} else if (/chrome/i.test(this.browserName) && /webkit/i.test(this.browserName) && /mozilla/i.test(this.browserName)) {
return "chrome";
} else if (/opera/i.test(this.browserName)) {
return "opera";
} else if (/webkit/i.test(this.browserName) && !(/chrome/i.test(this.browserName) && /webkit/i.test(this.browserName) && /mozilla/i.test(this.browserName))) {
return "safari";
} else {
return "";
}
};

给浏览器绑定鼠标滚动事件(兼容FireFox)的更多相关文章

  1. 在FireFox浏览器上,用stopImmediatePropagation阻止冒泡鼠标滚动事件

    楔子 是不是在火狐用stopPropagation不太满意 很久没有笑过又不知为何 既然不快乐又不喜欢这里 不如一路向西用stopImmediatePropagation(其实我对浏览器的兼容性看不顺 ...

  2. JS鼠标滚动事件

    -----------------------------//鼠标滚动事件以下是JS临听鼠标滚动事件 并且还考虑到了各浏览器的兼容----------------------------------- ...

  3. js监控鼠标滚动事件

    //滚动动画 windowAddMouseWheel(); function windowAddMouseWheel() { var scrollFunc = function (e) { e = e ...

  4. js进阶 12-6 监听鼠标滚动事件和窗口改变事件怎么写

    js进阶 12-6 监听鼠标滚动事件和窗口改变事件怎么写 一.总结 一句话总结:滚动事件scroll(),浏览器窗口调整监听resize(),思考好监听对象. 1.滚动事件scroll()的监听对象是 ...

  5. vue组件添加鼠标滚动事件

    在一个组件标签上加鼠标滚动事件,应该写成    @mousewheel.native

  6. JS实现鼠标滚动事件,兼容IE9,FF,Chrome.

    <!-- 废话不多说,直接贴代码 --><script type="text/javascript" src="jquery.min.js"& ...

  7. 鼠标滚动事件 - onmousewheel

    1.Jquery-MouseWheel jquery默认是不支持支持鼠标滚轮事件(mousewheel) jquery MouseWheel下载:https://github.com/jquery/j ...

  8. js鼠标滚轮事件兼容

    JavaScript鼠标滚轮事件 IE6.0首先实现了鼠标的滚轮事件,其良好的交互效果得到认可,随后Opera.chrome.safari等主流浏览器都实现了该效果,不过存在着很大的兼容问题. 大多数 ...

  9. JavaScript一个鼠标滚动事件的实例

    <script type="text/javascript" src="./whenReady.js"></script> <!- ...

随机推荐

  1. 核PCA与PCA的精髓和核函数的映射实质

    1.PCA简介 遭遇维度危机的时候,进行特征选择有两种方法,即特征选择和特征抽取.特征选择即经过某种法则直接扔掉某些特征,特征抽取即利用映射的方法,将高维度的样本映射至低维度.PCA(或者K-L变换) ...

  2. cisco 2901 配置拨号上网

    1.输入en,然后输入密码确认后按conf t2.Router(config)# vpdn enable        interface dialer 1   // 进入拨号器13.Router(c ...

  3. ipcs、ipcrm命令

    进程间通信概述进程间通信有如下的目的:1.数据传输,一个进程需要将它的数据发送给另一个进程,发送的数据量在一个字节到几M之间:2.共享数据,多个进程想要操作共享数据,一个进程对数据的修改,其他进程应该 ...

  4. 编写html页面时常见的问题(转)

    编写html页面时常见的问题(一)   说到写页面,肯定有很多人在刚接触编写页面这一块时遇到很多细节和兼容性的问题,那么在这里我总结一些经常遇到的小问题.希望能够帮助学习页面搭建的初学者! 虽然说ie ...

  5. Linux包管理

    1.yum(Yellow dog Updater, Modified) yum是一个在Fedora(基于Linux的操作系统)和RedHat(基于Linux的操作系统)以及SUSE(基于Linux的操 ...

  6. From COM to COM 侯捷 1998.06.12

    摘要: 本文簡介 C++ Object Model 和 Component Object Model 的基本概念,並引介四本書籍: 1. Inside The C++ Object Model 2. ...

  7. vue 报错 Uncaught (in promise) error

    可尝试在then()后加上catch() ps:该图来自网络

  8. 【mysql存储引擎】

    看你的mysql现在已提供什么存储引擎: mysql> show engines;   看你的mysql当前默认的存储引擎: mysql> show variables like '%st ...

  9. C# EventHandler委托事件小结--百度

    最近遇到一个委托的问题,+=这个符号 this.Activated += new EventHandler(Form1_Activated);//Form1_Activated为方法名12 这个语句拆 ...

  10. JSONCPP开发环境搭建

    环境设置 项目地址 https://github.com/open-source-parsers/jsoncpp.git 操作系统 64位 Fedora 24 安装jsoncpp $ git clon ...