我必须开发类似网站,例如http://www.unlocknrepair.com/ 在此网站中,当您将鼠标悬停在解锁或电话修复按钮上时,会出现下拉菜单。有没有办法让这个下拉菜单以有弹性的方式出现......就像我希望它在稳定之前稍微反弹一样。这是可能的jQuery中,但它可以使用只有CSS和JavaScript?在悬停时创建反弹效果
回答
如果实验CSS3是一个选项,你可以做到这一点,即使没有使用CSS动画与@keyframes
规则的JavaScript。
#parent {
position:relative;
height: 40px;
}
#onhover {
display: none;
position: absolute;
top: 0;
}
#parent:hover #onhover {
display: block;
top: 30px;
animation:mymove 0.8s linear;
-moz-animation:mymove 0.8s linear; /* Firefox */
-webkit-animation:mymove 0.8s linear; /* Safari and Chrome */
-o-animation:mymove 0.8s linear; /* Opera */
-ms-animation:mymove 0.8s linear; /* IE */
}
@keyframes mymove
{
0% {top:0px;}
10% {top:3px;}
40% {top:40px;}
60% {top:25px;}
80% {top:35px;}
100% {top:30px;}
}
@-moz-keyframes mymove /* Firefox */
{
0% {top:0px;}
10% {top:3px;}
40% {top:40px;}
60% {top:25px;}
80% {top:35px;}
100% {top:30px;}
}
@-webkit-keyframes mymove /* Safari and Chrome */
{
0% {top:0px;}
10% {top:3px;}
40% {top:40px;}
60% {top:25px;}
80% {top:35px;}
100% {top:30px;}
}
@-o-keyframes mymove /* Opera */
{
0% {top:0px;}
10% {top:3px;}
40% {top:40px;}
60% {top:25px;}
80% {top:35px;}
100% {top:30px;}
}
@-ms-keyframes mymove /* IE */
{
0% {top:0px;}
10% {top:3px;}
40% {top:40px;}
60% {top:25px;}
80% {top:35px;}
100% {top:30px;}
}
<div id="parent">hover me<div id="onhover">hovering</div></div>
另一种 “反弹” 动画:
$(function() {
$(document.body).delegate("img", "mouseenter", function() {
var $this = $(this).addClass("right");
setTimeout(function() {
$this.removeClass("right");
}, 2000);
});
});
body { font-size: .7em; font-family: Arial, Helvetica, "Liberation Sans", sans-serif; padding: 0 !important; }
img {
-moz-transition: -moz-transform 1s ease-in;
-webkit-transition: -webkit-transform 1s ease-in;
-o-transition: -o-transform 1s ease-in;
-ms-transition: -ms-transform 1s ease-in;
}
#anim.right {
-moz-animation-name: bounce;
-moz-animation-duration: 1s;
-moz-animation-iteration-count: 1;
-moz-transform: translate(400px);
-moz-transition: none;
-webkit-animation-name: bounce;
-webkit-animation-duration: 1s;
-webkit-animation-iteration-count: 1;
-webkit-transform: translate(400px);
-webkit-transition: none;
}
@-moz-keyframes bounce {
from {
-moz-transform: translate(0px);
-moz-animation-timing-function: ease-in;
}
60% {
-moz-transform: translate(400px);
-moz-animation-timing-function: ease-out;
}
73% {
-moz-transform: translate(360px);
-moz-animation-timing-function: ease-in;
}
86% {
-moz-transform: translate(400px);
-moz-animation-timing-function: ease-out;
}
93% {
-moz-transform: translate(380px);
-moz-animation-timing-function: ease-in;
}
to {
-moz-transform: translate(400px);
-moz-animation-timing-function: ease-out;
}
}
@-webkit-keyframes bounce {
from {
-webkit-transform: translate(0px);
-webkit-animation-timing-function: ease-in;
}
60% {
-webkit-transform: translate(400px);
-webkit-animation-timing-function: ease-out;
}
73% {
-webkit-transform: translate(360px);
-webkit-animation-timing-function: ease-in;
}
86% {
-webkit-transform: translate(400px);
-webkit-animation-timing-function: ease-out;
}
93% {
-webkit-transform: translate(380px);
-webkit-animation-timing-function: ease-in;
}
to {
-webkit-transform: translate(400px);
-webkit-animation-timing-function: ease-out;
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<img id="anim" src="http://hacks.mozilla.org/wp-content/uploads/2011/04/75px-Aurora210.png" width="75" height="75" />
见Mozilla Developer Network的详细信息和浏览器的兼容性。
老兄,这是一个很好的答案。我在悬停中显示一个菜单,如在问题中发布的网站上。这可以用你的方法来完成。 –
像我从显示:无显示:阻止悬停。那么上面的jsFiddle的动画就可以在那上面了。 –
这就是我的意思。 http://jsfiddle.net/7TsWs/3/ –
是的,它可以使用原生的JavaScript。 Take a look at this document
请注意,我链接到“easeOut”部分,因为我认为这代表球比他们的“反弹”跳得更好一些。
Here's a good example, further down the same page.
非常感谢,我想我将不得不花费大量时间来研究整个事情。大声笑。但是,我想我会这样做。谢谢你的链接。它也会在fuure中派上用场。 –
+1链接。 –
是的,我确实建议通过顶层的文档。 如果是,请将其标记为答案。 – Cerbrus
- 1. 创建悬停效果菜单中作出反应
- 2. 如何创建CSS3反弹效果
- 3. 悬停效果
- 4. 悬停效果
- 5. 对帖子的反向悬停效果
- 6. CSS悬停效果
- 7. 悬停效果jQuery
- 8. 悬停效果3
- 9. CSS悬停效果
- 10. jQuery悬停效果::
- 11. Javascript悬停效果
- 12. 同悬停效果
- 13. 悬停效果(CSS)
- 14. QPixmap悬停效果?
- 15. 在另一个div上悬停时触发悬停效果
- 16. 悬停效果在图标
- 17. jQuery悬停效果在表
- 18. 悬停在NSCollectionView效果
- 19. 悬停效果当悬停图像
- 20. 如何创建悬停弹出
- 21. 如何在livecode的按钮上创建鼠标悬停效果?
- 22. 如何在悬停上创建显示图像动画效果?
- 23. 如何在鼠标悬停上创建自动模糊效果
- 24. 在VB TreeView节点上创建“鼠标悬停”效果
- 25. 如何在通讯中创建悬停效果?
- 26. 如何在wxpython的StaticBitmap上创建悬停效果?
- 27. JQuery UI反弹效果 - 在输入div时只反弹一次
- 28. 悬停在兄弟姐妹停止悬停效果
- 29. 将鼠标悬停在图像上时创建简单的jQuery滑动效果
- 30. 悬停时的图像缩放效果
jQuery是CSS和JavaScript。 – Raptor
@ShivanRaptor Okie,我知道,但我不想包含jQuery现在在我的脚本因为我已经写了整个代码。我的意思是可以使用CSS和JavaScript来完成(困难的方法)。 –
jQuery是javascript,@ShivanRaptor的扩展。 _“是否有可能在jQuery中,或者只能使用javascript来完成”_是一个完全有效的问题。 (虽然它可能包含“本地”一词) – Cerbrus