CSS3带方向感鼠标悬停图片动画特效

CSS3带方向感鼠标悬停图片动画特效

这是一款CSS3带方向感知的鼠标悬停图片动画特效。该特效在鼠标悬停到一组图片上面时,图片会根据鼠标所在位置发生旋转,并且旋转的角度始终根据鼠标所在位置而变化。

使用方法

HTML结构

1
2
3
4
5
6
7
<div class="cards-container">
    <div class="card"></div>
    <div class="card"></div>
    <div class="card"></div>
    <div class="card"></div>
    <div class="card"></div>
</div>

CSS样式

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
* {
    box-sizing: border-box;
}
 
body {
    background-image: url('../img/bg.jpg');
    background-size: cover;
    background-position: center center;
    display: flex;
    flex-direction: column;
    font-family: 'Muli';
    justify-content: center;
    align-items: center;
    height: 100vh;
    text-align: center;
}
 
.cards-container {
    display: flex;
    justify-content: center;
    perspective: 1000px;
    width: 100%;
}
 
.cards-container:hover .card {
    transform: rotateY(30deg);
}
 
.card {
    background-repeat: no-repeat;
    background-size: cover;
    background-position: center center;
    border-radius: 15px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.5);
    margin: 20px;
    height: 300px;
    transition: transform 0.2s ease-in-out;
    width: 20%;
    min-width: 100px;
}
 
.card:hover {
    transform: rotateY(0deg) !important;
}
 
.card:hover ~ .card {
    transform: rotateY(-30deg);
}
 
.card:nth-of-type(1) {
    background-image: url('../img/1.jpg');
}
 
.card:nth-of-type(2) {
    background-image: url('../img/2.jpg');
}
 
.card:nth-of-type(3) {
    background-image: url('../img/3.jpg');
}
 
.card:nth-of-type(4) {
    background-image: url('../img/4.jpg');
}
 
.card:nth-of-type(5) {
    background-image: url('../img/5.jpg');
}
 
@media screen and (max-width: 756px) {
    .card:nth-of-type(4), .card:nth-of-type(5) {
        display: none;
    }
}
 
 
/* SOCIAL PANEL CSS */
.social-panel-container {
    position: fixed;
    right: 0;
    bottom: 80px;
    transform: translateX(100%);
    transition: transform 0.4s ease-in-out;
}
 
.social-panel-container.visible {
    transform: translateX(-10px);
}
 
.social-panel {
    background-color: #fff;
   border-radius: 16px;
    box-shadow: 0 16px 31px -17px rgba(0,31,97,0.6);
    border: 5px solid #001F61;
   display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    font-family: 'Muli';
    position: relative;
    height: 169px;  
    width: 370px;
    max-width: calc(100% - 10px);
}
 
.social-panel button.close-btn {
    border: 0;
    color: #97A5CE;
   cursor: pointer;
    font-size: 20px;
    position: absolute;
    top: 5px;
    right: 5px;
}
 
.social-panel button.close-btn:focus {
    outline: none;
}
 
.social-panel p {
    background-color: #001F61;
   border-radius: 0 0 10px 10px;
    color: #fff;
   font-size: 14px;
    line-height: 18px;
    padding: 2px 17px 6px;
    position: absolute;
    top: 0;
    left: 50%;
    margin: 0;
    transform: translateX(-50%);
    text-align: center;
    width: 235px;
}
 
.social-panel p i {
    margin: 0 5px;
}
 
.social-panel p a {
    color: #FF7500;
   text-decoration: none;
}
 
.social-panel h4 {
    margin: 20px 0;
    color: #97A5CE;
   font-family: 'Muli';    
    font-size: 14px;    
    line-height: 18px;
    text-transform: uppercase;
}
 
.social-panel ul {
    display: flex;
    list-style-type: none;
    padding: 0;
    margin: 0;
}
 
.social-panel ul li {
    margin: 0 10px;
}
 
.social-panel ul li a {
    border: 1px solid #DCE1F2;
   border-radius: 50%;
    color: #001F61;
   font-size: 20px;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 50px;
    width: 50px;
    text-decoration: none;
}
 
.social-panel ul li a:hover {
    border-color: #FF6A00;
   box-shadow: 0 9px 12px -9px #FF6A00;
}
 
.floating-btn {
    border-radius: 26.5px;
    background-color: #001F61;
   border: 1px solid #001F61;
   box-shadow: 0 16px 22px -17px #03153B;
   color: #fff;
   cursor: pointer;
    font-size: 16px;
    line-height: 20px;
    padding: 12px 20px;
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 999;
}
 
.floating-btn:hover {
    background-color: #ffffff;
   color: #001F61;
}
 
.floating-btn:focus {
    outline: none;
}
 
@media screen and (max-width: 480px) {
 
    .social-panel-container.visible {
        transform: translateX(0px);
    }
     
    .floating-btn {
        right: 10px;
    }
}
温馨提示:此处内容需要评论本文后才能查看。
2

发表评论