【发布时间】:2015-09-05 01:55:36
【问题描述】:
在我的网页中,我有一张图片,上面有一个按钮。我想在鼠标进入和离开图像时显示和隐藏按钮:
$('#UserImage').mouseenter(function()
{
$('#ButtonChange').show();
}).mouseout(function()
{
$('#ButtonChange').hide();
})
它正在工作,但是当鼠标进入按钮时,按钮包含在图像中,因此它被认为是离开图像,因此按钮被隐藏,然后在按钮被隐藏的同时,mouseenter 事件被再次触发,并且显示按钮会导致闪烁效果
有解决这个问题的建议吗?
编辑:
$('#UserImage').mouseenter(function() {
$('#ButtonChange').show();
}).mouseout(function() {
$('#ButtonChange').hide();
})
.imageUser {
width: 150px;
height: 200px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div style="position:relative;width=150px">
<img ID="UserImage" class="imageUser" ImageUrl="~/Images/logo.jpg" />
<input type="button" ID="ButtonChange" Text="Change" style="position: absolute;top: 180px;height:25px;left:0px;width:100px;display:none">
</div>
【问题讨论】:
-
请做一个小提琴
-
添加了代码sn-p
标签: javascript jquery html