|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
6 W. i7 y; W% R; p: A; h/ D1 n点击图片方法JS动画效果
, U" t. s. o! O E* H* W& C4 I5 g! z$ F
[mw_shl_code=html,true]<html lang="en">. w( g0 F6 w: m$ w/ q9 U
7 V* M, P3 _5 r% m<head>
3 L2 w) _9 i4 d <meta charset="UTF-8">4 K# i& y" O) r
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7 P1 I7 n6 ~# v/ p+ X+ L, r7 h <meta http-equiv="X-UA-Compatible" content="ie=edge">- A' E. I9 m+ K7 v6 i0 x
<title>Popup Model</title>
4 r2 m! V$ K6 F$ u% ^
8 w; O1 ?* c3 _$ ]* w+ W <style>/ D$ @; I5 B; z1 f; |- v
/* 弹窗背景 */
6 q1 p% O! R' O .model {( p4 I; a0 `3 x( X& ~4 Z
display: none;
0 T. Q. r) L3 v l position: fixed;
% a9 G9 R0 H3 m7 C! j0 ? /* Stay in place */
) L9 O1 p! o% H z-index: 1;
, R& H; p+ T* y$ u& B6 l& A3 X /* Sit on top */* C# ]% h+ [5 C* D5 q
padding-top: 100px;( Z% B$ y* @* P; B& y0 V, S
/* Location of the box */8 D* u# m2 D. Q. \
left: 0;' V L! Z( |5 I1 r! ~
top: 0;8 C/ J- W; b% X; \
width: 100%;
0 k9 ]: k4 O, V /* Full width */
3 c" y4 w# p7 x) k! R; X+ \+ d height: 100%;$ _4 ]( t* |. u6 E
/* Full height */
5 X' s3 E8 J+ k overflow: auto;6 i1 I+ R2 k0 p9 J4 H, ]
/* Enable scroll if needed */
9 R% l8 D* C" S- X9 k background-color: rgb(0, 0, 0);( s: k- s- i+ Q( a" T
/* Fallback color */
# L, Q0 N! h! x6 m4 r background-color: rgba(0, 0, 0, 0.9);
+ }# Y& f, @/ |1 W! A) P /* Black w/ opacity */4 J* n9 L* C k: ?' U
}
* G' p+ c% s* f+ s x
% a7 J, v. ]+ T% ]. i/ W1 W /* 图片 */
3 F" b; n9 Z3 Q& M .modelContent {, @. [4 A1 c- M q) }( h' X1 \& C
margin: auto;
; X! O b% `# V' S% l' T n3 G display: block;
1 `5 Y# [' d+ j width: 80%;6 u0 f$ Y7 u4 ]% A$ \* C( E
max-width: 700px;
( m% w1 v4 U; ^7 S5 y0 U/ m }2 _) A# ~& r2 e) v0 G2 M; b
( e$ p4 s$ [4 u9 n! y! a! o /* 文本内容 */" k9 ?, S5 t4 ~' }; A6 f
#caption {7 A7 k% @# E/ n! q& m4 O" a; D9 m
margin: auto;
: m! S, c0 t+ G/ F7 A display: block;
9 Q& u% G' f7 l9 x; V width: 80%;/ @# r3 g+ N0 o* ]5 h0 i& _
max-width: 700px;" b# H7 T! Y9 u5 i
text-align: center;
4 d" @" O/ [ ^' f color: #ccc;
: s: \; @! t# T& D padding: 10px 0;; B% \& H& u! |
height: 150px;' y' F* v: k2 V) l# N2 e3 A8 L j
}$ @ H5 \* N; A. {+ O l
/* 添加动画 */
5 C) z$ Q9 _. U.modelContent, #caption {
0 w: V3 m7 i1 N2 @9 r animation-name: zoom;
( C; Q, N8 K, }, h% p6 G animation-duration: 0.6s;
; h6 A( o) }0 A1 b& V -webkit-animation-name: zoom;: i& X! V. L8 E' Q$ p; r% k/ Z
-webkit-animation-duration: 0.6s;- l& g! h/ c+ H6 ?
}
0 s6 W$ }2 e0 x$ o. q' R& |2 J( I
@keyframes zoom {8 S& q4 B% ~8 }1 m; P
from {-webkit-transform:scale(0)} 5 C6 ]9 j+ S5 n! [& H; L9 @! }% l
to {-webkit-transform:scale(1)}+ Q4 G7 C3 x$ }. Y" K3 _9 ^
}
% Z- W1 b) k2 k" n$ U7 X0 h. P3 w q& b6 l
#myImg {
- w5 B" O8 E9 J* L2 M border-radius: 5px;$ i5 O5 N: r7 F) M8 {" k/ p- @
cursor: pointer;3 @9 h$ ~* q' b3 Y# P' E
transition: 0.3s; k) L( a5 N. ?6 c3 k
}
. l7 ]4 O1 T6 q) Q% u8 j6 W
# d* V1 Y u5 b# H #myImg:hover {. P: T/ P, ]; k6 _
opacity: 0.7;7 }- q' ?: K8 y# n, X% M
}
$ Q* M2 Z6 j' u* ?( U3 i
7 ~8 w% X) [7 k2 @0 P F /* 关闭按钮 */$ X1 s. ]& F% T* i {2 Z
.close {. a, D$ {8 p+ q7 T) }5 V1 [, j
position: absolute;! r( C4 i8 h2 V8 y" c% v8 `& P$ Y
top: 15px;
! I2 @3 y4 g/ G5 T: ]6 y$ k right: 35px;
' e& ^+ r [* p, M2 c7 g color: #f1f1f1;+ U, a- I' u) \% c% z% D
font-size: 40px;$ d4 X7 o- ]! K0 ]2 D4 F7 q, _7 S
font-weight: bold;; C9 k3 [" ^% w! W7 x) F# h
transition: 0.3s;2 c; T6 i+ `8 O: Z
}
+ E7 Q# v& ]% N- ^8 _- @3 B2 l
# z8 w0 n7 Q+ D/ t9 l- ^ .close:hover,
' ` H' Y" s0 i4 i8 ]$ e q .close:focus {$ e5 g$ s0 O3 q- Z. T0 U" \, v
color: #bbb;' ^- P2 Z# ~6 X7 w, b
cursor: pointer;+ ]( ?* G! J6 c+ Y- B
text-decoration: none;8 w1 y d6 U. E( ?* ?% G+ }0 g3 {0 F+ P
}( b/ f7 C6 Y) U3 D( |
</style>, v2 B; ?+ Y: a9 o
</head>! C) p2 Q3 N* Z1 \- `$ i# m& {; Z
* f# O" ~) k' N8 y5 v4 _9 m& V
<body>8 W/ E) q8 `) h2 x
: m# d* J9 B6 J <img src="./img/Logo.png" alt="This is a logo" id="myImg" width="300" height="200" alt="This is a test ">1 c+ t# u. X' ? V$ G) j( [/ B# ]
/ \& V- b. } L& `! N$ y% i
" v3 h$ B/ p% \. z' G* F <div id="model" class="model">) T1 e3 T1 a: F3 o
1 W s% Q8 u4 j2 i7 g' M
& ^1 M. ^' n! [# e# k p <span class="close">× </span>' J; M" ?' L. B' d! ]
6 R- W; l( H- s8 ~ <img id='img01' class="modelContent">- N2 G9 C4 O/ N1 T, e9 a
) I. D; O/ d6 z3 A) @; F' h <div id="caption"></div>9 E: l' v# U; E/ P
' @& o8 P2 s3 [( n* D
- \7 w5 _+ c; k& @5 D7 ~
</div>) p5 R+ f( S( z; T
! }8 O) N0 V5 Q( L' W
$ m$ e- K) ]5 p. Z8 v3 x* |
; ?& A0 P' c D1 O/ c <script>
7 k6 V( N# ^ n8 h9 o- n1 o4 ?5 u! T0 b6 Q$ u
var imgx = document.getElementById('myImg');# g; l5 b3 y! J
var modelx = document.getElementById('model');
. S1 n7 F6 ?' | var modelcontentx = document.getElementById('img01');
. L% ~ `7 A4 b$ h) h var captioNX = document.getElementById('caption');4 W3 F9 r# p1 Q' B$ z
( F y3 S4 A" C/ P }
imgx.onclick = function () {- E; f# ^6 T0 B/ b/ K
modelx.style.display = "block";' l, V7 l" g) V5 j8 g
modelcontentx.src = this.src;" M8 s+ V. Q4 i1 f0 F% n
captionx.innerHTML = this.alt;, H7 r% l' \* g3 _( u- I
" }* O& d: m- c }
. g7 C& F5 \. U9 }# [, V, V. p5 @
* K, E( x, q T; h
& B+ P7 U3 e+ |! V7 K: ~- C6 b </script>; _* E1 W6 B/ d% v
2 h6 [4 l8 l9 c) g% Y4 r
8 Q7 z" h: U& ^, i5 O* J8 x
4 _/ b7 |/ a1 v; x' X3 _, H( a; H, d' C# n# n
</body>) [! q0 @7 ?0 ^
+ Q; l1 \: R y& j
</html>[/mw_shl_code]
* M( W. `/ ?, A7 V: e2 C% W |
|