CSS:hover 图片缩放
2015-09-17 11:48
621 查看
前段时间看到有些网站上有这种效果,鼠标悬停到图上它会自己收缩,于是尝试实现一下,CSS3的动画,定义了两个类,然后用JQ hover事件分别分别给标签添加对应的动画类名,不过效果不好,在迅速来回移动鼠标的时候,动画会衔接不上,突然变大的感觉,原因是在CSS动画中写死了变化的起始和终止时图片的缩放比例,只有完全放大或者缩小之后再进行后续的动画才会感觉流畅,但用户鼠标不可能在图上悬停超过0.5秒再离开。
今天无意翻看到同类的效果,瞬间明白怎么回事,根本就不需要那么麻烦。
![](http://img.blog.csdn.net/20150917113521298?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
所以思维不能受局限了,看到这样的效果就去匆忙写动画, 实际上只是过渡效果。
<li class="flex-item"><a href=""><img src="./image/digital/03.jpg" alt=""><p>暖手宝<br/><em>¥99.00</em></p></a></li>
.productLargeAnimation{animation:ProtoLarge 0.5s ease 0s 1 normal; animation-fill-mode:both; -webkit-animation:ProtoLarge 0.5s ease 0s 1 normal; -webkit-animation-fill-mode:both; } .productSmallAnimation{animation:ProtoSmall 0.5s ease 0s 1 normal; animation-fill-mode:both; -webkit-animation:ProtoSmall 0.5s ease 0s 1 normal; -webkit-animation-fill-mode:both; } @keyframes ProtoLarge{0% {transform: scale(1);} 100% {transform: scale(1.03);} } @-webkit-keyframes ProtoLarge {0% {-webkit-transform: scale(1);} 100% {-webkit-transform: scale(1.03);} } @-moz-keyframes ProtoLarge {0% {-moz-transform: scale(1);} 100% {-moz-transform: scale(1.03);} } @-o-keyframes ProtoLarge {0% {-o-transform: scale(1);} 100% {-o-transform: scale(1.03);} } @keyframes ProtoSmall{0% {transform: scale(1.03);} 100% {transform: scale(1);} } @-webkit-keyframes ProtoSmall {0% {-webkit-transform: scale(1.03);} 100% {-webkit-transform: scale(1);} } @-moz-keyframes ProtoSmall {0% {-moz-transform: scale(1.03);} 100% {-moz-transform: scale(1);} } @-o-keyframes ProtoSmall {0% {-o-transform: scale(1.03);} 100% {-o-transform: scale(1);} } @keyframes ProtoSmall{0% {transform: scale(1.03);} 100% {transform: scale(1);} } @-webkit-keyframes ProtoSmall {0% {-webkit-transform: scale(1.03);} 100% {-webkit-transform: scale(1);} } @-moz-keyframes ProtoSmall {0% {-moz-transform: scale(1.03);} 100% {-moz-transform: scale(1);} } @-o-keyframes ProtoSmall {0% {-o-transform: scale(1.03);} 100% {-o-transform: scale(1);} }
$("a").hover(function() { var thatImage = $(this).children('img'); thatImage.removeClass('productSmallAnimation').addClass('productLargeAnimation'); }, function() { var thatImage = $(this).children('img'); thatImage.addClass("productSmallAnimation").removeClass('productLargeAnimation'); });
今天无意翻看到同类的效果,瞬间明白怎么回事,根本就不需要那么麻烦。
<div class="c"><a href=""><img src="a.jpg" alt=""></a><p>缩放动画</p></div>
.c{ width: 448px; height: 400px; } .c a{ display: block; width: 100%; height: 247px; overflow: hidden;} .c img{ -moz-transition: all 1s ease 0s; -o-transition: all 1s ease 0s; -webkit-transition: all 1s ease 0s; transition: all 1s ease 0s; } .c a:hover img{ transform: scale(1.15); -webkit-transform: scale(1.15); -moz-transform: scale(1.15); -o-transform: scale(1.15); }
所以思维不能受局限了,看到这样的效果就去匆忙写动画, 实际上只是过渡效果。
相关文章推荐
- CSS和JQ两种方式实现图片层上显示文字
- css3 box-sizing属性(规定尺寸)
- 怎样使用chrome调试前端html和css
- CSS让文本只显示一行,超出部分隐藏或以三个点结束
- DIV+CSS的经典翻页代码
- 使用CSS3实现百叶窗
- 基于CSS实现的4级下拉菜单效果代码
- html+css做页面如何不会乱
- CSS 符合习惯的代码规范
- css里面常用一些通用样式写法
- Word使用样式技巧:解决创建目录后出现的打印错误---超链接错误
- CSS样式小总结
- HTML&CSS Learning Notes 5
- css属性学习笔记
- 【搬运】CSS实现背景透明,文字不透明,兼容所有浏览器
- css中 outline 的使用
- css重点
- CSS hack方式
- 用CSS、HTML编写一个两列布局的网页,右侧宽度为200px,左侧自动扩展。
- CSS学习总结