【发布时间】:2014-01-11 03:38:33
【问题描述】:
我将如何重写此代码以使绑定不会冲突?我有一个悬停效果的比例,一旦我单击目标图片(以显示 Youtube 视频),它就会停止响应。
<script type="text/javascript">
//to scale up on hover
$('#videoandmapwrap').on({
mouseenter: 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);
},
mouseleave: function () {
$(this).stop(true, false).animate({
width: current_w + 'px',
height: current_h + 'px'
}, 400);
}
}, 'img');
//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);
});
</script>
【问题讨论】:
-
我被引导相信使用事件委托重写代码可以解决问题,但事实并非如此!提前谢谢你!
标签: javascript jquery binding