Javascript-JQuery:从左到右滑动菜单
Javascript-JQuery: sliding menu going left-to-right?
我有一段文本放在浏览器外部,我希望它在光标悬停在另一段文本上时显示。下面是我的代码:
HTML文件
<div class="panel_help">
<div class="help_text">
<h4>Τι κάνω?</h4>
<p>This is the text that is hidden and needs to appear...</p>
</div>
<p class="slide_help"><strong>Show text</strong></p>
</div>
CSS文件 .help_text {
color: aliceblue;
display:block;
position:fixed;
right: -9em;
top: 6em;
width:150px;
height:20px;
font-size: 18px;
border-top-left-radius:5px;
border-bottom-left-radius:5px;
}
.slide_help {
color: aliceblue;
right: 10px;
top: 4.5em;
position: fixed;
font-size: 150%;
}
JS文件
$(".panel_help").mouseenter(function() {
$(".help_text").animate({right: "1.5em"},'slow');
$(".slide_help").animate({right: "9em"}, 'slow');
});
$(".panel_help").mouseleave(function() {
$(".help_text").animate({right: "-9em"},'slow');
$(".slide_help").animate({right: "1em"}, 'slow');
});
问题是,有时需要两个动画停止,所以它左-右-左-右,然后停止!我做错了什么吗?我是JQuery的新手…谢谢!
放下JavaScript/jQuery,使用CSS。
.help_text {
right: -9em;
}
.slide_help {
right: 1em;
}
.help_text, .slide_help {
-webkit-transition: right 0.4s linear;
-moz-transition: right 0.4s linear;
-ms-transition: right 0.4s linear;
-o-transition: right 0.4s linear;
transition: right 0.4s linear;
}
.panel_help:hover .help_text {
right: 1.5em;
}
.panel_help:hover .slide_help {
right: 9em;
}
这样你就不用使用jQuery事件了,它有时不能正常工作
在animate(...)
之前添加.stop()
以停止当前动画:
$('.panel_help').mouseenter(function() {
$('.help_text').stop().animate({right: '1.5em'}, 'slow');
$('.slide_help').stop().animate({right: '9em'}, 'slow');
});
$('.panel_help').mouseleave(function() {
$('.help_text').stop().animate({right: '-9em'}, 'slow');
$('.slide_help').stop().animate({right: '1em'}, 'slow');
});
.stop() | jQuery API Documentation
问题是,您需要在鼠标离开该区域时完成动画。如果没有,动画将不会停止。
尝试在初始化每个动画之前设置stop():
$(".help_text").stop().animate({right: "1.5em"},'slow');
$(".slide_help")stop().animate({right: "9em"}, 'slow');
相关文章:
- 框从左到右自动隐藏
- 如何告诉D3使树状图垂直(自上而下),而不是从左到右
- 使用CSS/JS从左到右堆叠框
- 从上到下,从左到右更改图像的加载
- 统一呈现高图表.js图表,而不是从左到右
- 从左到右移动对象
- 如何在HTML中加载图像,例如iPad网站从左到右滑动
- 使用jquery在连续循环中从左到右的文本动画
- jQuery动画-使图像从左到右可见
- 文本中从左到右褪色的问题
- 缓慢淡入或从左到右加载带有加载后延迟的图像
- 文本下划线动画从左到右
- 从左到右为SVG制作动画
- 如何使用jQuery从左到右切换来包含关闭按钮
- 从左到右动态移动元素进行选择
- Javascript从左到右添加动态列表项,然后向下添加——而不仅仅是向下
- 从左到右移动整个页面
- 左菜单栏活动和从左到右滑块动画
- 如何用jQuery创建幻灯片菜单(从右到左/从左到右)
- Javascript-JQuery:从左到右滑动菜单