我使用下面的函数从中心放大div。导致jQuery生成元素无法再次被jQuery访问,所以我把onmouseout
属性放到了生成的<div>
。但是当我将鼠标移动到div的子元素时,触发了onmouseout事件,这不是什么问题我想要。jquery - 如何将mouseleave事件设置为after()生成div?
那么,我该如何解决这个问题,或者有没有其他方法可以达到同样的效果呢?
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
将被删除。
使用。 on()或。 live()取决于你的jQuery版本 – kennypu
你能在jsfiddle.net上设置一个例子吗? –
发布您的'html/css'以及 –