|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
; `9 P# V" k4 j% J; \* Z8 B
点击图片方法JS动画效果
2 ]4 R+ S& k) k" B
% t7 l: T) \: y3 N% h. I[mw_shl_code=html,true]<html lang="en">3 Q9 {5 V$ [" q! m% N4 ^
8 i$ s; }. T' C, w! u6 x4 v$ S* y<head>
. D8 g& h( n. j9 @$ ~7 O3 A <meta charset="UTF-8">. R; |0 P; C( t ~$ w
<meta name="viewport" content="width=device-width, initial-scale=1.0">
( J/ N# b: ` ~) m) N$ [ <meta http-equiv="X-UA-Compatible" content="ie=edge">" ~- u3 h. X3 o/ ]! h
<title>Popup Model</title>
# w3 G- x- b! {' e3 l9 i6 c9 ~, t& x0 _
<style>
) Z% a- |- ]/ ] /* 弹窗背景 */
4 D5 J7 w( u7 @- N .model {
! u: ~- G: d Z9 ] display: none;
2 ?/ @4 p* n- @* g position: fixed;' q7 q' V" H/ R* N7 x: [
/* Stay in place */6 q$ L# y( g) ?9 Q" O9 L6 |# q
z-index: 1;
3 c) \( }9 i/ f6 N8 j /* Sit on top */$ m2 n$ J9 Q$ c! E6 z% n
padding-top: 100px;
4 }+ z: U9 M+ K /* Location of the box */% o5 @) k0 f0 @ | f4 g
left: 0;
5 ~( K+ l8 z; d top: 0;
' C/ @9 ~+ I6 K# J' H+ Z* n width: 100%;5 ^, q. ~ }& T2 n# e+ o
/* Full width *// \: n- d0 _& f1 H! U% L1 Y/ J0 R, N& R
height: 100%;
5 O5 a* c. t; Z0 r$ U I /* Full height */
( w$ j4 L2 H! ] p7 t1 L, ?5 p overflow: auto;. c j) H8 [7 g9 P) s
/* Enable scroll if needed */
. o: z ?2 Q( u0 _9 z U; h background-color: rgb(0, 0, 0);! y0 P7 L' |3 u( Y5 {
/* Fallback color */6 c- d9 d0 ]/ \' V
background-color: rgba(0, 0, 0, 0.9);
b5 @/ b1 L9 q) {& s1 l3 }0 x /* Black w/ opacity */
d( b4 P* ^/ E) ^# W }" a. c8 j8 \1 E" @; G& i: G: }
1 Q" P5 }7 M7 }6 @1 |- }
/* 图片 */
. j' w- t( ?, @5 E! E5 _. Y0 T .modelContent {& `5 w2 F5 U, F! }' P. G
margin: auto;
6 g4 D0 a% {* |; V7 z8 B) |* l& B5 A display: block;
" a1 c8 O/ v5 P8 P& u9 h width: 80%;) o2 T3 `$ r; [7 `7 O7 u
max-width: 700px;
7 Z, O. g6 X/ O- T4 K6 [ }# A# p: p' f9 H* O+ W
( N4 E# z' g* x( [! s /* 文本内容 */
- s0 f# O) ]5 |0 [5 I+ ]4 u #caption {4 k2 c, V* L' Z, m( X, x
margin: auto;8 ^$ J1 b ^" c6 [8 F5 W5 b/ ]
display: block;
5 _; R+ Y/ Q& r) g2 b width: 80%;. o- T1 Y1 x4 S+ C
max-width: 700px;. g" Y6 ]6 K. a# V0 u
text-align: center;
9 G* D$ m$ ^' {# m color: #ccc;5 ]( c! {; z6 s4 k
padding: 10px 0;
- L) s) i4 x; {7 U5 F; ?* r height: 150px;. c; f8 J# K" T9 f3 o
}
7 ]/ h$ L6 e! `- i2 k! E1 | /* 添加动画 */# |- c/ K2 k5 P) l |! g* W+ d# g
.modelContent, #caption { ' c; s# T5 c8 l" w+ D
animation-name: zoom;" K t, L+ \9 M, f
animation-duration: 0.6s;
% J: E, i u) _1 j u% ^" G -webkit-animation-name: zoom;
0 y. v* a4 P8 Z; h! Q) U -webkit-animation-duration: 0.6s;4 P( ], m+ [) B! ]
}2 N# f2 r1 S& }+ f) l% U
" w* O6 @3 k3 Z@keyframes zoom {
. `& o5 j ~& u, p, h+ U; H: ]' q, g from {-webkit-transform:scale(0)} 9 q. C% W9 n4 m0 X
to {-webkit-transform:scale(1)}. Z; p* K+ l$ `0 y! }5 D N; g
}7 T8 j5 Y `3 D+ r
0 z$ R- Z8 `. t3 x" r) [
#myImg {' w5 J! G4 u$ w h& v/ Q
border-radius: 5px;
& \7 `4 `1 n4 D* S cursor: pointer;
3 `+ d* \, i5 Z3 B% h transition: 0.3s;
2 n; x$ c. C( S$ w9 N5 W/ y' T$ ` }
$ q0 w3 A- W8 I$ m/ a) f, t2 g' }& v$ V& K M# [ ]! q
#myImg:hover {3 C7 U6 i* X4 n4 y8 W
opacity: 0.7;
$ a0 Q1 T. l4 u+ N }
& ^: p6 D. H+ _3 g6 y/ N4 f# Y. T) U6 v+ ~; |3 J# R3 M- S; }3 k3 O. @
/* 关闭按钮 */4 E) H# f4 C3 x. r ^
.close {
, y' O6 s2 r H3 P1 J position: absolute;0 p4 q: r7 S$ d2 e2 w1 U! w& p
top: 15px; z+ T; O" f( ` u7 S" a9 r7 O" A
right: 35px;1 v0 o) b* g0 K* F, c# _8 B% q
color: #f1f1f1;/ e" E. I% Y5 a/ U' E0 p E2 h
font-size: 40px;
# i( ^/ l# Z: W% {' c! c0 R1 Q% k font-weight: bold;
: [- @) ~2 l! K% x& n transition: 0.3s;
9 o: F4 m8 u, Q! g, n" l1 O }* o* S* l9 y# |) F. T+ s4 \
2 g2 |+ x! n$ m9 l' Y( n/ Y4 R8 n; {* ]! _ .close:hover,
, K+ n9 J) ?, A+ t: D3 ` .close:focus {* |6 E' M1 s" y( Y
color: #bbb;4 l$ G; C% Z5 ~* _
cursor: pointer;
) H# f% V* R( Q( S: Z3 w text-decoration: none;
4 f" u) s( M# s( f5 q }
" [# r( o0 i/ g& I# s( Y( [ </style>
, q' U; X7 k4 D K) P</head>* K; p2 _; X/ ~) k
: {: L" }* e' ]! Y9 K' y* P' A<body>
5 l2 i6 z" ^9 a1 ]9 l* X4 `7 n( i0 q d: S# K4 r+ @5 ^
<img src="./img/Logo.png" alt="This is a logo" id="myImg" width="300" height="200" alt="This is a test ">
4 c3 i# Y& Q$ q6 [: W6 S& k& |. m9 p; K) j
4 H4 _( s& ^+ {# s/ f, ?
<div id="model" class="model">9 l3 o2 N3 ]+ X8 ^; K& _$ _
8 U- g! w% B8 K0 O; N# f; A1 b
W' ~ T% z" V- I3 _
<span class="close">× </span>
2 v6 Q/ z, S: p' ]8 m ^9 v0 _4 b( V" @# X5 k! e
<img id='img01' class="modelContent">
; _% }! |+ x- f0 ]: i% D/ p) O1 Z# @6 C$ q- o2 }! ~- D
<div id="caption"></div>
: q6 S2 @( g' I
1 I8 B, O: P# ^% {9 s4 f' _2 t9 D) R- t! v) J& ?
</div>0 O9 E" h0 e. [5 {
% s# q' ^5 M3 }- a7 M; T0 g9 h
: J F4 a! o) u$ g
a) ~1 g; I/ i" m5 j- _ <script>
- ?: ?0 M2 z Y7 d9 m2 V1 g9 a8 D& z& u; {* M% e. d
var imgx = document.getElementById('myImg');, I+ j( s% F+ `4 \( \3 i5 {. z+ l
var modelx = document.getElementById('model');- h2 ?$ G) ^4 K! K* h- z: z
var modelcontentx = document.getElementById('img01');
# E+ |' V# n) }3 b, }( s0 B var captioNX = document.getElementById('caption');7 j" `/ x" b7 @1 ~+ V
& K2 j: B! m8 w X
imgx.onclick = function () {
3 u1 f$ P7 ?' E" H4 H% K% o modelx.style.display = "block";
! v, t4 W! k0 k# X modelcontentx.src = this.src;
3 H& {& u4 ]- z" O captionx.innerHTML = this.alt;" }. a3 v! H M" @& U: r
# N n. X% S+ e8 @+ j5 |; e9 E
}- P* |1 z! z J: |% O
) f: n% K' F/ P$ P$ ?
% D6 V# s( `& Q5 t! j
</script>
4 ]2 E1 u8 @, W0 v
& N- q5 J& H8 _# J2 x' H' V9 y r" p1 P: {; W
$ G8 G1 f/ \ w/ x+ X: p
" E$ j. _- h4 Y% D& Z# [# d/ m</body>
+ |6 z: k$ {! F
$ _+ o, U- ~# L( U- |</html>[/mw_shl_code]: q; w9 T0 }5 n1 y3 O4 [ V0 E
|
|