【发布时间】:2014-01-10 03:39:27
【问题描述】:
我正在尝试使用事件委托重写一段 sn-p 代码(希望它不会与另一个 js 片段发生冲突)。但我已经破坏了代码
原创
//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);
});
【问题讨论】:
-
如果您想要准确的行为,请将其更改为
on("hover",".piccon", ...。