|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
& `/ t# S4 i$ l* w; p4 a点击图片方法JS动画效果/ d. I& G$ ], h1 d! I* I4 o* q0 B
% z& B. @& h- R1 S
[mw_shl_code=html,true]<html lang="en">
( t- T3 w! q! [. i+ F4 \
# M5 D: i/ ]4 S" B* p; J$ l<head>6 g4 \8 x1 {& @1 {' e! L
<meta charset="UTF-8">
! }5 V3 Z/ l ` <meta name="viewport" content="width=device-width, initial-scale=1.0">
2 E0 p- S) U9 H <meta http-equiv="X-UA-Compatible" content="ie=edge">
( H3 L* ^+ Z/ `5 ]1 e( ? <title>Popup Model</title># { T! g* y' V, X9 u3 r
X; ^0 E/ t( a% E _ <style>
; v M' f+ {9 `1 K) {+ y /* 弹窗背景 */0 _2 O4 A* |, m4 m. H
.model {
! W6 Z: r! a% Z' g: S display: none;7 S- J- {0 _% l0 y
position: fixed;
9 ~2 R: |. e1 ]" E, k2 V' E4 [ /* Stay in place */9 Y) m1 a- m& U/ a g) i9 x5 _5 U" V
z-index: 1;) \, p1 j5 @. {' k: x* ~$ g. V
/* Sit on top */2 Y* V" J! L) s
padding-top: 100px;
, _, j5 O# }: m3 i /* Location of the box */
; d( D3 U' X8 ]) `4 S left: 0;
/ F$ v$ Y8 ?' _, ~ top: 0;" E$ X( ~3 n8 Z Q
width: 100%;
4 y# n' q* Q, b$ {; s /* Full width */
; Y( t9 g/ f- O! s$ K height: 100%;) a2 K& |3 ~4 A. v( N
/* Full height */6 u6 e: c: s1 d
overflow: auto;
% O) D; N2 C* h /* Enable scroll if needed */
3 X) @# Y# V" ^9 k background-color: rgb(0, 0, 0);. S! Q8 s9 I2 I4 g+ W9 T
/* Fallback color */
* R: }% {; i/ w background-color: rgba(0, 0, 0, 0.9);
: |- _8 {' k- A7 Y4 J /* Black w/ opacity */) f! d1 e3 i5 O
}
( _# d+ O5 \+ ^; s" Q2 N! `' D$ {+ @+ R9 A% M
/* 图片 */1 J5 ^3 g/ j9 U) B' r; C
.modelContent {; T) m- ^) g# S* m( @5 S
margin: auto;' ]1 S7 s1 Q% s: v
display: block;/ i7 K$ }; N; t) R5 D
width: 80%;) a$ Y' [3 P9 {: V- O% T. I. ^3 j# m
max-width: 700px;; [: y- d, s# p8 n
}5 J/ |9 R; ?3 h9 }* Y* V6 w
# N ]& L K' @! R3 l" T
/* 文本内容 */
. m7 c, ]" G# ~% |/ o1 G5 O' Y x #caption {
( c) Z* c+ Z$ P& }" [ margin: auto;
1 b) t" o* p2 D' o' p display: block;
. P7 g$ B+ O+ t' c width: 80%;5 s7 |, e) q9 O( s+ f4 F1 \' o& p
max-width: 700px;
' A! o% ]8 |- R* B: f text-align: center;
. ~; G& o& r$ C- v. V, h/ C" T color: #ccc;
3 \; e; O+ n/ r6 N" J padding: 10px 0;4 |8 h1 X7 ]3 }: k6 z! n
height: 150px;
5 \: H( d. O$ }9 m( }+ H1 f0 R* \ }! ?9 P' ~0 z- I7 Z; [: t. x
/* 添加动画 */2 H0 r2 Q: w; |) c8 X5 i$ L! ~ I4 g
.modelContent, #caption {
0 p; E6 S$ P8 U+ [) Y animation-name: zoom;
5 R: J7 z# P0 Y animation-duration: 0.6s;5 O7 E$ Q, C3 \9 S& m
-webkit-animation-name: zoom; t- ]9 l0 W0 N, \1 J/ a" D! r
-webkit-animation-duration: 0.6s;
7 A6 ]7 k( a) W7 B} ]7 S, H2 x8 F0 q3 I Y
8 \3 a2 g) h7 i+ |" g2 V7 C* Y$ B
@keyframes zoom {
, `3 |. @) h4 o# X# P from {-webkit-transform:scale(0)} - V4 k! {4 D- w! ~0 d
to {-webkit-transform:scale(1)}! G+ U0 b" E9 d
}# D+ _ ]8 N$ j% G8 U2 Y
0 F; b9 d5 F' N, L, o( ` #myImg {
, { m' L% \ L' T/ k border-radius: 5px;/ s. K5 r* s' P9 q# ?4 Y) \! E
cursor: pointer;6 Z4 z( _2 V7 a" V1 c
transition: 0.3s;$ g7 @! d% H: A5 o3 p& \
}
3 N# J, n8 x: G/ J9 Z7 O8 @% P3 |/ a' F3 |: A1 z+ V
#myImg:hover {8 a& @/ }8 k) K7 B& w7 l. }
opacity: 0.7;
6 z- |6 g& r6 F7 H% V) B3 o2 ]( ~ }' b5 C2 Z0 l6 {/ V9 {7 p# n
5 S" h, T& R. ~" M; t /* 关闭按钮 */
$ V, ~4 C; D* G8 Z& ^1 ` .close {4 W& M, F& r' n/ ~- b
position: absolute;( s) ^: T# }! j
top: 15px;
" Y n0 t/ ?4 {6 @+ r8 x right: 35px;
2 O, N5 V. Y- M5 H/ N- h+ ] color: #f1f1f1;( p# l1 k( F( D. U
font-size: 40px;
; z& _- l7 A2 d6 U1 J font-weight: bold;
) @) @0 f/ O/ L+ N9 V! o transition: 0.3s;
8 X4 Q9 _1 i7 j }, M9 y& c: x5 Z7 X3 b1 u
- l9 }1 j. w$ X2 L
.close:hover,
' _/ \2 e1 k! y" R .close:focus {
0 g! I9 O# D0 C8 k* g j1 @" }/ Y4 H color: #bbb;, ]& s0 k7 e: J+ `( l
cursor: pointer;: ?" [( S' F" r0 t9 \7 W' `1 A
text-decoration: none;
& Z) }* j5 ~& n) n! G/ u5 N5 g+ X0 c }
- k+ K0 F1 D5 X9 v& H# A </style>
4 g( M% @7 Q: J3 ?- Y& I- B</head>' f- c! p$ t0 t" U
1 f; j3 Q5 O$ ~- L$ Z" w ^' D4 l6 z
<body>
( N0 d/ R$ i. T, `4 X8 `! Y5 v+ j* N: [
<img src="./img/Logo.png" alt="This is a logo" id="myImg" width="300" height="200" alt="This is a test ">* a j) U9 U; x) [
+ M& X& ]: ?9 U5 w/ K% C2 T6 s) h. o6 m3 }. l1 g8 b( a- f
<div id="model" class="model">4 H# R# L3 _ n3 V5 b8 L
7 J9 b5 s1 g5 M9 x. f
/ R% g4 V$ i. G9 _/ _- r
<span class="close">× </span>( N! f: y$ q+ h8 P+ c2 c
4 q& n4 U3 _9 H+ }$ u5 V <img id='img01' class="modelContent">' C- x$ n% B& i" g, P, R+ A3 k
8 O* m7 \8 |& j0 s9 a K. a: k# Q
<div id="caption"></div>
8 V! g' Z" W( h6 ^6 b |. G6 U6 {0 R& } Y
\8 l& i2 K2 d8 p; C- y! O </div>
% N/ u/ S# X* o/ [7 H0 T/ p9 n; M) d. ^/ @0 Y8 r
# ?2 E2 ]8 E% ]- u6 X1 B' j h5 D/ T0 U9 F' S$ r- U$ g2 H, b
<script>) O- H0 f. U& y s
# G* R; y7 L3 V& T% K var imgx = document.getElementById('myImg');
" x9 z- x& u3 Z var modelx = document.getElementById('model');
1 m4 O4 r4 n7 |$ d var modelcontentx = document.getElementById('img01');( p4 C% P5 b) e3 q$ k+ A
var captioNX = document.getElementById('caption');* M* I& I6 e# h2 z
$ o% Y* P. X; x imgx.onclick = function () { p: z( X9 @# L& ^5 G
modelx.style.display = "block";
2 x V# J$ H. R2 q3 ~ modelcontentx.src = this.src;
: ?: \9 f8 r4 ?; X captionx.innerHTML = this.alt;, ]' e) G0 e& q- Z% Y' ?
9 A) ^& B5 J1 A
}
3 j/ ^ j% J+ Z
& O" \5 W# q6 q8 x u1 ^1 D
( u8 v" S+ |2 y. B1 N </script>; e( b7 k7 M s! v. `, M9 C S
/ i# ~2 F$ L! o6 w, ?
+ M+ @! `9 g1 E( Z- v$ ~* F9 m4 B4 W. Q
3 |5 I5 i/ i9 \$ R0 r. v3 `( y</body>, f/ W0 @* [' `- N, k) b! `3 `
5 l. E! m# x; m$ y9 p
</html>[/mw_shl_code]3 W, j6 h( i4 g% _' x& z0 U
|
|