event.stopImmediatePropagation();适用于除火狐浏览器以外的所有浏览器
event.stopImmediatePropagation(); works in all browser except Firefox
我有一个jQuery代码用于创建图像轮播。我知道这不是最优雅的代码段。
jQuery(function(){
$(".project").css('max-height','180px'); //180px
var expanded = 0;
var position = 0;
x = 0;
$(".project").click(function(){
if (expanded == 0){
$(this).css('max-height','320px');
expanded = 1;
$(this).find('.projectcarousel').find('.control').fadeIn(300);
$(this).find('.projectcarousel').find('.control').css('display','block');
$(this).find('.projectdescription').find('.tags').fadeIn(500);
$(this).css('opacity','1');
}
else if (expanded == 1){
$(this).css('max-height','180px');
$(this).find('.projectcarousel').find('.control').fadeOut(300);
$(this).find('.projectdescription').find('.tags').fadeOut(500);
$(this).find('.viewscreen').find('.carousel').css('-moz-transform','translate(0,0)');
$(this).find('.viewscreen').find('.carousel').css('-webkit-transform','translate(0,0)');
$(this).find('.viewscreen').find('.carousel').css('-o-transform','translate(0,0)');
$(this).find('.viewscreen').find('.carousel').css('transform','translate(0,0)');
expanded = 0;
position = 0;
x = 0;
}
});
$('.prev').click(function(){
event.stopImmediatePropagation();
switch(position){
case 0:
x = "-420px"
position = 1;
break;
case 1:
x = "-840px"
position = 2;
break;
case 2:
x = "-1260px"
position = 3;
break;
case 3:
x = "-1680px"
position = 4;
break;
default:
x = 0;
position = 0;
}
$(this).parent().parent().next().find('.carousel').css('-moz-transform','translate('+x+',0)');
$(this).parent().parent().next().find('.carousel').css('-webkit-transform','translate('+x+',0)');
$(this).parent().parent().next().find('.carousel').css('-o-transform','translate('+x+',0)');
$(this).parent().parent().next().find('.carousel').css('transform','translate('+x+',0)');
});
$('.next').click(function(){
event.stopImmediatePropagation();
switch(position){
case 0:
x = "-1680px"
position = 4;
break;
case 1:
x = "0px"
position = 0;
break;
case 2:
x = "-420px"
position = 1;
break;
case 3:
x = "-840px"
position = 2;
break;
case 4:
x = "-1260px"
position = 3;
break;
default:
x = 0;
position = 0;
}
$(this).parent().parent().next().find('.carousel').css('-moz-transform','translate('+x+',0)');
$(this).parent().parent().next().find('.carousel').css('-webkit-transform','translate('+x+',0)');
$(this).parent().parent().next().find('.carousel').css('-o-transform','translate('+x+',0)');
$(this).parent().parent().next().find('.carousel').css('transform','translate('+x+',0)');
});
});
该event.stopImmediatePropagation();
正在Chrome,Opera和Safari上运行,但在Firefox中不起作用。我尝试使用 event.stopPropagation()
和 event.preventDefault();
但两个代码都不起作用。
我从Firefox得到的错误是"使用getPreventDefault()已被弃用。请改用默认预防"和"引用错误:未定义事件"。
我是否以错误的方式使用了代码,或者 Firefox 中是否存在我应该注意的错误?
对于所有 jQuery 事件处理程序,使用 jQuery 的规范化事件对象,该对象作为第一个参数传递给回调函数:
$('.next').click(function(e){ // added the 'e' parameter
e.stopImmediatePropagation(); // uses jQuery's event object, referenced by e
请注意,我已经将其命名为e
但您可以随意调用它,只要它是有效的JavaScript标识符。我选择e
因为它很短(只有一个字符),相对明确(我知道它指的是表示事件的对象),而且我不太可能隐藏任何其他具有相同名称的变量。
使用 event
1)
$('.prev').click(function(event){
event.stopImmediatePropagation();
2)
$('.next').click(function(event){
event.stopImmediatePropagation();
相关文章:
- 如何在火狐浏览器中禁用F5和刷新
- 在火狐浏览器卸载之前
- 如何在火狐浏览器上增加 IndexedDB 的配额
- 多个 socket.io 客户端连接不起作用(谷歌浏览器,火狐浏览器)
- 火狐浏览器不会在前进时触发流行状态事件
- 在火狐浏览器的画布上获取鼠标位置
- d3.火狐浏览器中的鼠标像素偏移量
- 使用量角器打开火狐浏览器的文件网址
- 火狐浏览器 iframe 设计模式不起作用
- $injector:nomod模块“应用程序”不可用!仅限火狐浏览器
- 以编程方式打开火狐浏览器并执行 POST 请求?[想法:MozRepl,建议?
- 为什么我在火狐浏览器中剪辑的图像中有边框而不是铬
- 火狐浏览器与 event.target.id 的问题
- 帖子数据在火狐浏览器上不起作用
- 动态.js在火狐浏览器上很慢
- 关闭火狐浏览器的平滑滚动
- 为什么选择选项上的 .click() 只适用于火狐浏览器
- 窗口绑定在火狐浏览器中不起作用
- event.stopImmediatePropagation();适用于除火狐浏览器以外的所有浏览器
- 是否应该在同一台计算机上的两个火狐浏览器共享相同的cookie