jQuery   发布时间:2022-03-30  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了Jquery – 如何将mouseleave事件设置为after()生成div?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我使用下面的函数从中心放大div.因为jQuery生成元素无法再次被jQuery访问所以我将onmouSEOut属性放到生成的< div>.但是当我将鼠标移动到div的子元素时,会触发onmouSEOut事件并且不是我想要的.

那么,我该如何修复它还是有其他方法来做同样的@L_673_7@吗?

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;
@R_801_11442@kground: RGB(245,245,245);
overflow:hidden;
}

.bigger {
border:0;
@R_801_11442@kground: 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将被删除.

解决方法

只要鼠标离开目标元素或进入子元素,mouSEOut事件就会触发. IE有一个专有的mouSELEave事件,只有当鼠标完全离开目标元素时才会触发. jQuery使用mouSELEave函数模拟这个.我尝试了以下更改,我认为它会做你想要的:

...
des.after("<div class='" + nclass + "'>" + des.html() + "</div>");
    $("." + nclass).css({
        'width': nWidth,'top': top
    }).mouSELEave(function(){$(this).remove()});
...

大佬总结

以上是大佬教程为你收集整理的Jquery – 如何将mouseleave事件设置为after()生成div?全部内容,希望文章能够帮你解决Jquery – 如何将mouseleave事件设置为after()生成div?所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。