我有一個用於創建圖像輪播的jQuery代碼。我知道這不是最優雅的一段代碼。event.stopImmediatePropagation();適用於除Firefox以外的所有瀏覽器
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的()已過時。使用defaultPrevented而不是'ReferenceError:event is not defined'。
我使用的代碼以錯誤的方式或者是有在Firefox中的錯誤,我應該知道的?
你所有的活動功能都缺少'event'(或類似)作爲參數。 – Zeta
讓我看看我有一個錯誤消息,說:*''ReferenceError:事件沒有定義'。「*哦,哪裏是事件定義,哪裏哦,它可以在哪裏? – epascarello