我有这个小动画正在工作,但不是我想要的,当我悬停其中一个三角形带来隐藏的div时,我希望动画不会重置,而我正在徘徊三角形或隐藏div,希望我能让我明白。
动画如下:
$(function() {
$('.arrow-left').mouseover(function() {
$('body').stop( true, true ).css('right', 'auto').animate({
left: 300
});
$('#left-content').show();
});
$('.arrow-left').mouseleave(function() {
$('body').stop( true, true ).css('right', 'auto').animate({
left: 0
});
$('#left-content').hide();
});
$('.arrow-right').mouseover(function() {
$('body').stop( true, true ).css('left', 'auto').animate({
right: 300
});
$('#right-content').show();
});
$('.arrow-right').mouseleave(function() {
$('body').stop( true, true ).css('left', 'auto').animate({
right: 0
});
$('#right-content').hide();
});
});
#anim {
position: relative;
height: 100%;
min-height: 100%;
background-image: url("http://i.imgur.com/rxks29H.jpg");
background-image: no-repeat;
background-size: 100%;
}
#anim img {
position: relative;
height: 100%;
width: 100%;
}
.arrow-left {
padding: 5% 15px;
text-transform: uppercase;
position: absolute;
width: 14%;
left: 0;
z-index: 3;
top: 30%;
cursor: pointer;
}
.arrow-right {
padding: 5% 15px;
text-transform: uppercase;
position: absolute;
width: 14%;
right: 0;
z-index: 3;
top: 30%;
cursor: pointer;
}
.arrow-right h2 {
font-size: 28px;
color: #FFF;
}
.arrow-right:hover h2, .arrow-left:hover h2 {
color: #DDD;
text-decoration: underline;
}
.arrow-left h2 {
font-size: 28px;
color: #FFF;
}
body {
position: relative;
}
.hide {
display: none;
}
#left-content {
left: -300px;
height: 400px;
position: absolute;
top: -30%;
width: 300px;
}
#right-content {
right: -320px;
height: 400px;
position: absolute;
top: -30%;
width: 300px;
}
<section id="anim">
<img src="http://i.stack.imgur.com/Fbhc4.png">
<div class="arrow-right">
<h2>Scouting For Companies</h2>
<div id="right-content" class="hide">
<h3>Right content</h3>
<p>A paragraph goes here A paragraph goes here</p>
<p>A paragraph goes here A paragraph goes here</p>
<p>A paragraph goes here A paragraph goes here</p>
</div>
</div>
<div class="arrow-left">
<h2>Seeking For Ideas</h2>
<div id="left-content" class="hide">
<h3>Left content</h3>
<p>A paragraph goes here A paragraph goes here</p>
<p>A paragraph goes here A paragraph goes here</p>
<p>A paragraph goes here A paragraph goes here</p>
</div>
</div>
</section>
小提琴谢谢@ amir5000
编辑:似乎jsfiddle的行为与我的本地文件不同,如果我每次移动鼠标时都会打开index.html,动画会重置。答案 0 :(得分:2)
使用mouseenter事件而不是鼠标悬停。
$(function() {
$('.arrow-left').mouseenter(function() {
// ...
});
});