|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
, v$ S2 N' ~) g1 D$ p. V9 W8 Q点击图片方法JS动画效果2 t) b- S; F, S; I; l
% v/ f- c' t$ s" Q
[mw_shl_code=html,true]<html lang="en">& G3 m9 C$ a$ ], |0 q2 D
: z$ g5 I* \0 Y* c0 r<head>
D+ j, f- T% { <meta charset="UTF-8">- Y I0 P( v: r* ?1 c0 V& m& t
<meta name="viewport" content="width=device-width, initial-scale=1.0">/ }. N* @: e7 i# ?( s9 u
<meta http-equiv="X-UA-Compatible" content="ie=edge">0 O* W* J. o1 D j
<title>Popup Model</title>4 F" F W; R+ L
) ~. ?, E3 F5 ?# ^ <style>- ~( q% A' z8 T9 r
/* 弹窗背景 */
& R2 z- w* f' _# ]/ k5 h, R, h .model {
: P \: ^7 w$ [0 h7 { Y9 C. ~. n2 _5 @ display: none;
7 J1 Y+ F6 E- \# K* x/ \7 f) B position: fixed;
$ k+ l3 F+ @5 n) P& X: j /* Stay in place */
) E1 R" m0 r: S* s% h z-index: 1;) N9 w: X' h; l( k+ D! V- f0 x& x
/* Sit on top */
' v: d. b4 V( _; c9 _ padding-top: 100px;
! l) r5 j7 J/ B) G8 r* m /* Location of the box */5 f* v8 A7 u& \3 H$ _, G
left: 0;5 a* K$ c- y/ c; D ^
top: 0;* j3 f+ P6 E) ~$ a8 W' {
width: 100%;. |7 K1 A2 [# h
/* Full width */& g/ G) w0 `4 W- u4 D% l
height: 100%;# [+ {- ?, s1 D& V- Y" M& }
/* Full height *// H; p" s( f: e# Y4 I5 b0 D
overflow: auto;
, |) F' I# Y: ]) T" h J1 z /* Enable scroll if needed */
% W4 e1 q0 ^! Y* i9 o' z' t" C background-color: rgb(0, 0, 0);' ]! [6 B, u+ u& P
/* Fallback color */
: s4 |# j6 l8 r" k; Z. t background-color: rgba(0, 0, 0, 0.9);5 K' @' p- n- p8 N( x+ O
/* Black w/ opacity */4 U; W% }- t0 }/ M
}0 C5 Y; [/ M+ I$ n* r) d
! Z1 Z; g+ e; t9 u- M( Y8 _1 R
/* 图片 */
# v4 }4 b5 `, t- o2 |! S .modelContent {. i# l+ p5 w0 U- e
margin: auto;
% Z$ X. C$ b. y9 s% W8 _ display: block;
2 a4 t# G' w8 V* h* `, u width: 80%;" ]( F' _5 q$ k5 P$ y/ b- W
max-width: 700px;
: [( E/ ]& J, ^; s( m) ^ }; F Z, e( `* p* T4 t V0 W7 x
( d& g7 D6 }* V, K: o
/* 文本内容 */3 f" W% e0 |0 L( M7 X* t+ |# S8 h
#caption {
W; { t0 U. }$ o T6 a margin: auto;4 q9 d! {, k8 F5 U+ }4 ^
display: block;. @. d3 |3 Y0 N: e3 J
width: 80%;5 E' o2 w# ^+ K5 U, [ ]1 K
max-width: 700px;
( j( m# ~- s* |. k. `" [. I text-align: center;0 |& T$ f8 c5 P; W' Q" ~
color: #ccc;
- U+ C/ H3 {1 {" _4 c# S1 V padding: 10px 0;* ?; A) R, a5 r3 X; m
height: 150px;
% H& V. s. v, m6 |0 R6 H }! _! \' i6 V9 |1 t- b
/* 添加动画 */. y0 }8 I/ x" D! `; t, d
.modelContent, #caption {
" n7 l& m* R; U5 l. ]) l animation-name: zoom;6 n; a3 f& c: a
animation-duration: 0.6s; d3 h! w4 F2 Y4 }4 N% d
-webkit-animation-name: zoom;
- |, `+ F1 [+ O1 _) J -webkit-animation-duration: 0.6s;: b7 a! ^: B7 X. s5 y q
}
) k) {9 j9 b) r1 q+ ?3 Z( z4 n- [! [4 G5 Q
@keyframes zoom {
5 h i0 C8 i9 l from {-webkit-transform:scale(0)} * e" T1 g% {2 f2 q$ z/ E$ q
to {-webkit-transform:scale(1)}
l7 g0 I. t' I" P+ H' t" n5 u}: r# ^# |. a6 ?0 d
7 r5 {' p7 ]; G+ Z) s; K6 L# q D: [ #myImg {
1 I& L' C% G+ A, k3 M" L) X' [ _ border-radius: 5px;
6 _. ^+ X9 }- e d" h cursor: pointer;* c5 Q. m; s$ [: |8 V* V, n
transition: 0.3s;
9 R x# |& c4 C+ S }6 r+ _0 C# s- j p; p- |
! ^6 G/ ]2 T, M: r$ S
#myImg:hover {: D }. |. X4 A& H8 z# Y
opacity: 0.7;' e _# H* E+ B6 o8 N, ?
}
3 G4 Y- M8 L. z: d/ `4 W7 Y
% z) l3 X6 i& {, ] /* 关闭按钮 */4 {2 c4 @, ]! q4 O h, z# L
.close {6 x w8 x1 e1 Z
position: absolute;
, F4 @6 h9 Z# t% M0 a top: 15px;. V5 R* \1 L& y) c$ H Y& K
right: 35px;0 i" u4 l4 L1 S- k/ u! w( G9 }
color: #f1f1f1;* m( L1 c2 P( C4 {# h
font-size: 40px; l$ Q* x# R; ^! S- v+ D
font-weight: bold;# [, @4 l: i) z" [8 Q3 d' V
transition: 0.3s;
+ ~0 s& O; E3 `# p3 I9 `( [: m }8 M6 j/ N; a( ~* t( d
$ O! H8 f/ g" G; C1 J- Y4 e! Y .close:hover,; d3 o( Y1 f; j# R; b
.close:focus {
6 U; r* P# S. m7 ^" I color: #bbb;+ p/ Z4 {5 c8 N9 ^* I- `/ S# K
cursor: pointer;
' K1 O( q& ^" K- d7 r4 s text-decoration: none;
( y3 d3 a0 @+ u& K& z% }4 R }
) ~& Q, Y# } w$ {$ W </style>
' ], m: I/ v( K' G2 B</head>
0 A( p5 T: p3 N
2 g6 _; V9 @7 I7 B: I. a/ i<body>
& L. C' w+ X6 R' ^9 s) T; e
" y, f. b1 [7 h5 Y# o3 X <img src="./img/Logo.png" alt="This is a logo" id="myImg" width="300" height="200" alt="This is a test ">( d U, Z* N0 ^' f
* O% B' C+ R6 P' n
8 j h, D" ^2 y B( w8 q
<div id="model" class="model">- w7 M! N6 U4 F1 N
( W* o, Y( }1 P9 ]. N! [. P
: F- B/ E T% O4 ?. R ^ <span class="close">× </span>
& r, Z5 x! N6 w' L9 ~8 ]) \. l
$ s$ ^: F4 r, Y% G0 o0 `; ~( [ <img id='img01' class="modelContent">
, _6 L' n) Q' ~9 L, x( X' P1 s. M( o
<div id="caption"></div>
% ^# _8 S; Y- S( p7 b9 s( H/ H) f8 \* @7 p0 p
) }+ X1 m0 S" K6 i </div>6 L0 F0 d- P w4 P l9 ~# Y1 X
$ M. }* D8 z7 u: N. Q
' S4 r6 f: Y6 g5 h3 n! W, M
+ J" `- r' c; f% O$ p3 M( r5 a5 e1 U
<script>& b6 }0 y2 j2 r: k2 e0 M
# j* P8 z6 _) t! k# Q( N& @. U
var imgx = document.getElementById('myImg');3 S3 `6 y6 k' \1 V4 @3 W7 d1 S
var modelx = document.getElementById('model');
/ a s! w- O% `0 \ R var modelcontentx = document.getElementById('img01');
: n4 H, P) f _3 \. l& A( ]8 _# c1 w var captioNX = document.getElementById('caption');4 T6 D; ^" C' d
+ v8 u" g3 b% P0 o! S imgx.onclick = function () {( f8 r, n! v; L0 z. f( f
modelx.style.display = "block";8 ^8 Z6 a2 d$ B5 B% V6 i
modelcontentx.src = this.src;( S2 y! O/ I- [$ T6 ]7 V* w0 n
captionx.innerHTML = this.alt;
/ Q( g5 V( E7 N9 ]/ t; D
$ L7 j- F( I2 E. h+ J* k# i }7 o0 q8 a0 q# f/ r
4 o0 ^ [7 v B4 X. R7 A3 s' L" q
n, W" c1 q% o4 J </script>
e: p' ?" n' H) S
$ a" J0 Q' n2 |9 c* U; A+ u! ?. j, [, T- q
9 u1 r/ `# l; w5 H' Q9 m
% \5 `. |4 {$ e
</body>
; ~% c; B6 ?2 ~( N
. r: m8 L/ Y9 `" l</html>[/mw_shl_code]
: [* i1 `8 j3 H7 `" y |
|