引言
一、CSS3图片动效基础
1. CSS3 3D转换
img {
transform: perspective(600px) rotateX(0deg);
transition: transform 2s;
}
img:hover {
transform: perspective(600px) rotateX(360deg);
}
2. CSS3 动画
CSS3的动画功能可以创建平滑的过渡效果。以下是一个简单的动画示例:
@keyframes rotate {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
img {
animation: rotate 2s linear infinite;
}
二、jQuery图片动效进阶
1. jQuery动画
$(document).ready(function() {
$("img").hover(
function() {
$(this).animate({ 'width': '150%' }, 'slow');
$(this).animate({ 'height': '150%' }, 'slow');
},
function() {
$(this).animate({ 'width': '100%' }, 'slow');
$(this).animate({ 'height': '100%' }, 'slow');
}
);
});
2. jQuery插件
$(document).ready(function() {
$('#carousel').cycle({
fx: 'scrollHorz',
next: '#next',
prev: '#prev'
});
});
三、实战技巧
1. 结合使用CSS3和jQuery
在实际项目中,我们可以结合使用CSS3和jQuery,以实现更丰富的动效。例如,使用CSS3创建基本效果,再用jQuery添加交互性。