|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
. v4 b4 C2 A0 U" K8 T点击图片方法JS动画效果
9 ]& t5 f, L6 S% g$ Z7 x6 I
# Y; W" b; S t/ c/ B[mw_shl_code=html,true]<html lang="en">; O, s2 I5 h6 Q1 m a2 O- N+ C# b
& B7 E1 Z! d) ~) U; Y
<head>
n" P# `: R& A1 K! r; j <meta charset="UTF-8">" j" x$ u; Y+ T2 ^ L) S; L- U2 c
<meta name="viewport" content="width=device-width, initial-scale=1.0">2 I u( @+ {: n& ~9 [7 {( i
<meta http-equiv="X-UA-Compatible" content="ie=edge">% z( k6 m- X+ P
<title>Popup Model</title>
& n" z: i$ i) n' _4 l5 b- j
2 H6 P0 J( Q, w' M9 L' X$ J <style>
$ x; x0 I0 v: N. u5 `) k. q /* 弹窗背景 */# [8 o5 x5 @! k7 U
.model {7 H+ X+ B3 H4 V- `+ v4 m+ R8 S( o* r
display: none;
) h! Z" R( Q2 t position: fixed;) j. w. m+ V+ Q
/* Stay in place */
# T- I4 m. e @2 M# M z-index: 1;* ^' y$ h4 q! n, o) _) ^
/* Sit on top */! H. @# H9 Y3 t- h; x1 M& N" e
padding-top: 100px;* d1 ^; H; l6 g
/* Location of the box */5 O8 p( L1 F2 G3 [ h9 X. A
left: 0;( k3 ~% G0 h2 r
top: 0;
! Y, Y0 `# H/ U' ?0 @ width: 100%;" D9 d6 G4 w! {6 t, E) K6 e7 j8 q4 g8 R
/* Full width */
. W) V+ n/ [1 }$ q% j) k height: 100%;
9 P) A5 o# M2 ^: V' C /* Full height */+ }0 f5 ] `" g+ }
overflow: auto;
# Z+ l9 Y/ M/ Q5 I& _/ Y: W7 J /* Enable scroll if needed */8 \4 y8 H9 g: @- @+ G( n& b
background-color: rgb(0, 0, 0);( }8 t3 ~: d4 F. g2 y' [: z
/* Fallback color */5 S; k4 K+ z) ?
background-color: rgba(0, 0, 0, 0.9);
8 D5 N4 [- M3 [: X. h6 W2 F /* Black w/ opacity */
8 u w( J1 t r8 i' H8 k: _0 `% I }3 q+ R7 s' L2 O9 a! u: [" h
) x8 {9 t z" n: r7 X' E r, G; K
/* 图片 */' M8 _3 O$ i, t% F. h4 {
.modelContent {3 |! m' j0 }& F8 B& M
margin: auto;( M4 Y. N' u5 ^" z2 ~
display: block;
* k1 b, ]! H* Y7 A width: 80%;5 _6 V K9 U6 ^$ Z' o
max-width: 700px;
, u* b. _ [. Y7 n; i" R) \& B }
% t! f N/ p$ M" j
4 E! Z: H# m6 f! f- p5 ? /* 文本内容 */
6 k6 z# e' [7 ~; ~& p1 d2 U #caption {
: }4 L* y& Q* q0 j4 e; e margin: auto;3 p. F# l2 a, x" a" g; ?8 a
display: block;
5 b4 a' l! H, e) _# | width: 80%;5 L) e: d& _. f% o
max-width: 700px;6 ?1 y7 o$ r. X! D, `
text-align: center;
/ y" C, G$ \% ?( t+ K color: #ccc;& A' J4 ]5 v3 \) J
padding: 10px 0;
' t! @: c+ C, h! f! [6 j height: 150px;; ^, c) F2 G8 |# }, W/ T6 X O
}4 G; f$ s# a% {& O
/* 添加动画 */
' b( I' D+ S5 v* o* u: c* f. f.modelContent, #caption { , L- z& M1 @ {2 t$ f; \% }8 W
animation-name: zoom;+ l1 L9 Y, J9 M, O
animation-duration: 0.6s;+ g @2 {& t# @! z2 {8 [) S
-webkit-animation-name: zoom;' @& M2 L& C) H' g! h
-webkit-animation-duration: 0.6s;& O+ B5 d. n% I+ `" e4 r
}5 |# X( {/ q+ T! l
- \! u4 k# O7 D4 F" N! W5 n* a@keyframes zoom {# v( f" {; J* a( b+ J
from {-webkit-transform:scale(0)}
+ ?/ H2 ` j. Y) b8 s7 {# d" k to {-webkit-transform:scale(1)}
& C! X$ B; ~/ X3 d: V& y}& N/ g! G/ Q6 L
8 F. v* v/ L3 O1 H9 K& P: d( }9 B
#myImg {6 i' H% V7 r. [. u# ?8 I
border-radius: 5px;( @6 w! U* L: g! d Y2 b
cursor: pointer;
: d2 ^! N, S2 X# y; I* L/ Y transition: 0.3s;% P! e2 z" D# _$ p. h, u$ z' `
}$ }1 O- L, N. L# G9 s
4 y( p- x+ {$ ]6 w
#myImg:hover {( v `( }$ K4 R& E, I
opacity: 0.7;* K8 s- f/ A( `- d4 n7 z: r7 F
}
3 K! G q+ {6 d
0 _1 v3 Q* @$ v6 `# u1 K7 P /* 关闭按钮 */$ f# b, O! G( b% g2 ~
.close {
% o' p6 m: S) l6 e$ }& w; ] position: absolute;
+ h [6 L# w, o3 ]* L top: 15px;
* Y( h, J+ f: p! o# d' E" |! t! \" e right: 35px;
4 f0 [# g) E) L( G# O9 _( X color: #f1f1f1;' P8 \4 M7 A6 f$ t3 Q
font-size: 40px;
! K8 M0 f) ~- {! K6 F( t& G font-weight: bold;
; p2 l7 Z2 D0 `7 N& d# o/ |9 ? transition: 0.3s;" n' J9 v& y8 u. ~
}( v2 O+ S. U2 W% x; M4 d
8 M; Z6 f, n# L" F9 F
.close:hover,
" F) q# R: R! W# x .close:focus {6 p. l) Z2 z% s& i4 H6 ~4 q" c
color: #bbb;
( X+ a4 Y: D; e7 p cursor: pointer;
$ h% {$ Q, y. J* X text-decoration: none;7 j4 o6 ?) {1 r6 g% H6 z4 e5 G
}
8 z! g" K6 T# D </style>" X$ a# B# s) Y2 c+ K3 p P
</head>/ F( A& ]5 T) z" t% V
* A! e/ g% [" i X6 m1 C<body>
0 `9 `* `9 ]1 [) O* t% t; c D8 Z* C0 T
<img src="./img/Logo.png" alt="This is a logo" id="myImg" width="300" height="200" alt="This is a test ">0 q# k C+ {! L4 Z" G) d
5 L# c( X7 z% k4 a" ~. k( o7 o/ v9 B* N( t# j" z& L( u, b0 J# Y, P1 k
<div id="model" class="model">
+ X' P8 X1 ], u% g* N5 `) H& H7 Z) {+ B$ k+ m$ }, _. Y0 T# `8 ?+ |
" i* u) h, r( l# ?
<span class="close">× </span>
& Y3 C) t2 A1 B
2 r) f/ w4 I* e; {0 q5 M( h <img id='img01' class="modelContent">
* R: u- N' ^" \0 d- [
! B9 e" W' Y: k) }$ d3 G <div id="caption"></div>
7 ?: g2 A" S) Q* U4 t
: s4 ]3 L6 W& K
! [6 ~, w5 ~4 k: I3 e6 \5 H </div>3 x/ Y" o( I* T( s" T$ P
- w' `2 [9 l) ?9 W( T9 j* a& j
n* f% e+ ~5 q; ~4 s
7 q5 |+ V4 \- T7 y; \8 j' L <script>% h" u' [* S4 ^( `# t
, j! C' j: ?5 e1 K& d var imgx = document.getElementById('myImg');3 \* \0 U! y& j
var modelx = document.getElementById('model');3 a$ ]% n9 {7 E* n) H
var modelcontentx = document.getElementById('img01');" I0 M3 O! N3 b8 o5 v% e
var captioNX = document.getElementById('caption');* T M* b p3 A# H4 a( s
5 W! [% B3 y; O; a
imgx.onclick = function () {
1 S! T6 d. }" r' I& ~ modelx.style.display = "block";
g8 @% M+ Z4 J0 L+ ^* ]0 Z modelcontentx.src = this.src;3 W% k8 _' v7 o6 J% g) x6 E
captionx.innerHTML = this.alt;3 V9 J7 C7 [) v& m9 _7 W
/ V3 H' x& |) j& j9 F5 M- W7 O
}
, ~# M0 ~/ x' W
9 C/ Q( T) U9 X8 R3 q2 s! c' W* q0 s; S5 i
</script>* @0 T! _& n, K
% B# m$ s r& e/ N
/ I) L! X# i! i' Y
7 r0 q1 n5 {6 T6 q; D
3 p$ r* O1 R) E) f5 K! l/ k</body>$ k" @/ w/ V( P* s' b" p7 {
! r7 [, E( f9 W
</html>[/mw_shl_code]
# h- c* }4 ^. V" U4 m' f |
|