0
我試圖用事件代理重寫一段代碼(希望它會停止與另一個js的snippiet衝突)。但我已經斷碼jquery事件代表團
原始
//to scale up on hover
var current_h = null;
var current_w = null;
$('.piccon').hover(
function(){
current_h = $(this, 'img')[0].height;
current_w = $(this, 'img')[0].width;
$(this).stop(true, false).animate({width: (current_w * 2.7), height: (current_h * 2.7)}, 900);
},
function(){
$(this).stop(true, false).animate({width: current_w + 'px', height: current_h + 'px'}, 400);
}
);
//使用事件代表團
//to scale up on hover
var current_h = null;
var current_w = null;
$('#videoandmapwrap').on("hover","img", function(event){
current_h = $(this, 'img')[0].height;
current_w = $(this, 'img')[0].width;
$(this).stop(true, false).animate({width: (current_w * 2.7), height: (current_h * 2.7)}, 900);
},
function(){
$(this).stop(true, false).animate({width: current_w + 'px', height: current_h + 'px'}, 400);
}
event.preventDefault();
);
顯示從後面佔位
//to reveal from behind placeholder picture
$('#videoandmapwrap').on("click","img",function(event){
event.preventDefault();
video = '<iframe class="piccon" width="200" height="200" src="'+ $(this).attr('data-video') +'"></iframe>';
$(this).replaceWith(video);
});
更改它開啓(「懸停」,「。piccon」,...,如果你想要確切的行爲。 –