|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
# Y; S& v" e7 S. k( P
点击图片方法JS动画效果
0 @) [# B% @* S8 C8 I% v0 S n5 Q8 B v; v4 Y) B4 R$ y0 Y
[mw_shl_code=html,true]<html lang="en">7 H Z( S- D; y* D# O- S# Y8 t5 {
' D' r7 s( o1 n2 K0 W& t<head>
0 L7 [5 T& n" A1 V) F5 i t2 J <meta charset="UTF-8">" m3 z; l* x& j: ^
<meta name="viewport" content="width=device-width, initial-scale=1.0">
. p* A& s5 \/ o% Z; z2 L1 G4 u* Q0 i <meta http-equiv="X-UA-Compatible" content="ie=edge">
" b: E C& O \1 V <title>Popup Model</title>0 \* e* X1 X! D* X; i' J, ]
2 p$ i L) o2 `" O
<style>
/ ?6 W# c7 r1 u& o; ^+ p' b /* 弹窗背景 */
! K' R; Q& X8 D: o8 e .model {6 S1 p' Q) s" F) s3 \4 K
display: none;
" z' c* u4 c b position: fixed;
; M# Z( v, Y/ J& b+ E0 U /* Stay in place */
) ^, C. }3 F+ n7 \/ {% u3 k z-index: 1;4 U; s) |- E3 Y L' C
/* Sit on top */ G! q+ F! a) i# |
padding-top: 100px;
% d' V2 o1 K$ Y4 s" J) R /* Location of the box */& I9 n9 r* L: A; ?, h6 p+ Y
left: 0;$ K" u8 o. X' W
top: 0;- D' W: r! k, D7 R2 a
width: 100%;
9 q' `) E6 ]0 [$ J9 r) X% f /* Full width */5 N7 |) i" S b& D9 ]9 n, N# t
height: 100%;
: }. o# D4 k/ `; k( f /* Full height */
, |( o/ r" i5 U1 m- z$ }0 Y overflow: auto;
4 A3 N: C$ v0 p3 ~' p+ v U /* Enable scroll if needed */
+ B6 C2 W# f0 L( {5 s5 o8 M background-color: rgb(0, 0, 0);
; N: R/ V9 e. q" ?% L /* Fallback color */ e" B' |$ |- m! x
background-color: rgba(0, 0, 0, 0.9);; q9 U* n0 A0 I% K* m( M$ N* y6 m
/* Black w/ opacity */: y" D; k5 o, B8 E7 a& T
}8 j) N, w. t8 Z& |& C2 J% Q- }
. g/ T/ R- W- y/ z- A /* 图片 */$ ]8 d3 F% P+ c) _6 r2 R1 B$ B
.modelContent {8 x. D, n3 U5 y+ X( z
margin: auto;
5 C8 O) @; ?- n8 ^- T display: block;7 H. o# h8 S5 @ N1 u* H( }( x5 N
width: 80%;% i0 ~3 W5 k1 E- D
max-width: 700px;+ l2 f/ ]# J: t( u5 w! S, A& z
}
' d5 \+ W# Z( E( _& C: u# h j W8 O. }* _1 ^
/* 文本内容 */3 i2 ~7 t" N: J: H- M0 T1 {1 }
#caption {
' ~' K6 N9 b/ |5 L% b/ E margin: auto;
& [& s7 P5 ?! R" P display: block;
, P8 L8 e0 G; t1 G% z$ Q4 a width: 80%; W- [- f4 F. N" A
max-width: 700px;
8 w B5 j9 r* F$ D" I9 p1 F text-align: center;
- K( ^8 x6 P7 ?( z% _ d* [$ U" I; H7 f color: #ccc;
. z* }4 j$ F; Y* R7 ` padding: 10px 0;/ ?! F9 G# f/ }% Z- _& p4 V' b
height: 150px;% `* Q. U5 R9 E" Q( V
}
# k' l( c7 D5 t5 b; ~2 N /* 添加动画 */+ r f7 s- Q6 Z6 p+ w. q0 L( W
.modelContent, #caption { / R" M5 U6 P# T# C6 Y
animation-name: zoom;: o& O6 a: _% e& ~! D5 ~
animation-duration: 0.6s;6 M/ i& D/ P1 H2 N! r
-webkit-animation-name: zoom;
0 V/ t4 v0 C0 K: G; v6 r, t -webkit-animation-duration: 0.6s;: \2 f+ l( p& q: w7 W
}
0 W' u# K% r4 K/ [7 ]
0 p. ?! t% p* i@keyframes zoom {, G3 p' f0 m* k+ v$ A
from {-webkit-transform:scale(0)} % m* C6 i$ p& r+ W2 s# I
to {-webkit-transform:scale(1)}3 K9 B# S _ `2 q/ { v* r1 T" i
}
/ m: ]; V( h# y4 ]7 \5 C, ]' c7 o. e V
#myImg {' `8 j2 G# g/ g" G) N" }( l* M
border-radius: 5px;) j9 p" m+ E, p- Q5 z% ?; D9 Q
cursor: pointer;
* y5 I7 r2 t6 ~ transition: 0.3s;4 l+ M+ ^& c- q2 V. r$ L' X3 e
}
/ C! e9 q) z1 P* w' q
. ]0 w; d8 _# p, u #myImg:hover {
4 C% x% k" r& \' a9 m opacity: 0.7;4 U+ }* }) _+ c; c
}( K2 Y1 F( Z7 P- i
" Q" G4 \4 M8 \# l /* 关闭按钮 */
: L& C/ A- P+ P) h$ ~4 q& ^ .close {
7 L8 l; b/ B2 ^& A& l* ]# r position: absolute;. b7 M' q7 o6 |& `' k: m- y5 o& U# v$ F
top: 15px;
; |) \9 l4 o2 }8 ~' o: h- p right: 35px;% I0 \; D: Y& D+ h9 g
color: #f1f1f1;
* Q$ F3 I$ F/ @5 G- } M5 R font-size: 40px;
, l. k! J4 j. ^. ~- S font-weight: bold;
6 M6 K' h* I' a7 L transition: 0.3s;# R0 t9 B0 H% ^
}
9 ^$ ^" r" @' P% f
# ?* P o* `7 v* q2 O/ ]8 S+ f .close:hover,
1 c4 b) G U: N1 _; e .close:focus { x( ?6 S' S) ^: s" i* s z# a3 ]
color: #bbb;
|3 v8 q8 F0 c* B7 E cursor: pointer;
6 N3 }/ s3 Y2 z [! y' K( j text-decoration: none;
3 v* s( t+ ]! h+ i }
7 s( I- Z2 ?2 A% z) t5 P& ~3 P </style>
# M. p( i0 z4 B2 W</head>* B1 V0 s! B, P, N% J9 Q7 Z) C
% g; X2 F$ i) R3 D% @1 k<body>
- {2 ~% W5 P2 A& J) C: A" u @' U$ n, W5 k
<img src="./img/Logo.png" alt="This is a logo" id="myImg" width="300" height="200" alt="This is a test ">) X: _( W7 E: X6 y9 v6 }
3 F0 m8 L8 ^" {2 s1 o: B
# h x x0 V8 e7 s <div id="model" class="model">
' g+ e+ i( i; G. S1 k6 ?: R6 S, ^' \+ P" [
[# d1 d/ B; z& }8 J1 V" C
<span class="close">× </span>
7 F6 J1 Q2 ? D/ D2 z3 M8 Z( T3 V% D, V, v$ i' q* k
<img id='img01' class="modelContent">7 x) J5 g( w7 K( w1 ?; d* u
) ], E0 v/ n i$ `' q) F% F
<div id="caption"></div>
9 Q2 G$ X* t* \+ z. H: z$ j5 I) N4 Q
# M0 d. d, }* R </div>
# q( C4 Q4 Z6 E" u3 E; I' g7 S4 T! y \
( k6 D, h3 I/ c2 w2 X& ?9 a! s: `1 [& t. h1 H/ i$ k
<script>: J9 f! L1 C: l1 Y# h
" f7 X+ M" E$ `0 {. k- t7 a
var imgx = document.getElementById('myImg');
1 w7 Y- I! m& v9 c var modelx = document.getElementById('model');
0 d+ G) t$ I# o% A var modelcontentx = document.getElementById('img01');
9 S3 a) b- H0 A! h' ~8 @/ C! k var captioNX = document.getElementById('caption');9 R1 }# D" x5 \4 P
$ P% Q; v7 }. V4 b, e: D
imgx.onclick = function () {
9 X; S. U+ N0 E5 w8 x& b) z4 U% V modelx.style.display = "block";
9 ~, N* o! ]0 w; m modelcontentx.src = this.src;
8 T6 M/ C8 m. J. S) A* S7 `, I3 | captionx.innerHTML = this.alt;$ t+ I$ v, p) n* l8 }1 y: Z( ]7 C
. d$ U" E$ L: {9 u3 x) B
} S+ u$ l8 Y; O
/ N5 v7 s4 }0 x, M9 w3 Y6 ^* P
6 w5 `( x; n& Y8 R2 S( ]( t
</script>0 b& M6 @( d0 c' y0 x1 E
1 R' T- I( y% @$ U& k1 s
1 R$ X H( z! }. z2 R# ?2 M' O4 b
0 s) F( X" @9 r" F2 ^) ^/ E% C1 w$ O0 H) K
</body>0 I, |! e0 p/ [2 z5 W9 V8 B0 J8 c3 E
+ H4 g3 D0 _) o& N" p</html>[/mw_shl_code]
+ A0 z. R: r" i: ~ |
|