我使用下面的函数从中心放大一个 div。导致jQuery无法再次访问jQuery生成元素,因此我将onmouseout
属性添加到生成的<div>
.但是当我将鼠标移动到div的子元素中时,会触发onmouseout事件,这不是我想要的.
那么,我该如何解决它,或者有没有其他方法可以达到同样的效果?
shows = $(".shows");
shows.bind('mouseenter', function() {
enlargeCenter($(this), 1.8, 'bigger');
});
function enlargeCenter(des, ratio, nclass) {
var oWidth = des.width();
var oHeight = des.height();
var nHeight = oHeight * ratio;
var nWidth = oWidth * ratio;
var left = des.position().left;
var top = des.position().top;
left = (oWidth - nWidth) / 2 - oWidth;
top = (oHeight - nHeight) /2;
des.after("<div class='" + nclass + "' onmouseout='remove()'>" + des.html() + "</div>");
$("." + nclass).css({
'width': nWidth,
'height': nHeight,
'left': left,
'top': top
});
}
这是CSS代码
.shows, .bigger {
float:left;
width:200px;
height:250px;
position: relative;
left:0;
top:0;
border:1px #ccc solid;
background: RGB(245,245,245);
overflow:hidden;
}
.bigger {
border:0;
background: white;
box-shadow: #ccc 0 0 5px;
-moz-box-shadow: #ccc 0 0 5px;
-ms-box-shadow: #ccc 0 0 5px;
-webkit-box-shadow: #ccc 0 0 5px;
}
HTML
<div class="container">
<div class="shows">
<p>odfelakjfelkavjekvaelkfjjjj</p>
</div>
</div>
如果您移动鼠标,<p>
该onmouseout
事件将被触发并且较大的div
将被删除。