transform实现音乐盒代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
* {
margin: 0;
padding: 0;
}
body {
background: skyblue;
}
img {
vertical-align: bottom;
}
.box {
width: 300px;
height: 300px;
margin: 100px auto;
/* 相对定位 */
position: relative;
}
.box img {
border-radius: 50%;
/* 使用绝对定位,让元素重叠到一起 */
position: absolute;
left: 0;
top: 0;
}
.box .img1 {
z-index: 10;
/* 设置过渡 */
transition: all 1.5s;
/* 改变变形原点 */
transform-origin: center bottom;
}
.box:hover .img1 {
/* 沿着X轴旋转 */
transform: rotateX(180deg);
}
</style>
</head>
<body>
<div class="box">
<img src="./images/musict.jpg" class="img1" />
<img src="./images/musicb.jpg" class="img2" />
</div>
</body>
</html>
总结
通过2张图片重叠,使用css3 transform属性实现音乐盒翻转效果