|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
, O& A2 B j8 v- K点击图片方法JS动画效果7 I' S% I- a: a0 {8 S
( X0 c! v! t) W+ Z/ r
[mw_shl_code=html,true]<html lang="en">; F) M l; G6 u J) L, I1 a" w
3 s8 P1 x4 F y. [! M* g2 o" `
<head>
3 T- T# c L2 B' c S9 h6 Z <meta charset="UTF-8">. [5 U* g) s- Z0 A" q
<meta name="viewport" content="width=device-width, initial-scale=1.0">* ~# t4 S. ?. S9 J5 {9 ?
<meta http-equiv="X-UA-Compatible" content="ie=edge">( `" U* O; E* ^/ q: X
<title>Popup Model</title>
1 G n1 p9 j* Q5 h' R- q7 w! u e) j, U7 n, A& t0 A
<style>
- k, `9 B/ y* M! o7 H/ ?: b /* 弹窗背景 */
. |2 b8 ^' G% U: `3 L" b .model {$ x2 K2 w2 f# g) t, A
display: none;
2 k/ b# {$ r+ k0 Z3 @ position: fixed;
0 V5 Y4 q/ H4 O( ?5 h% ]# u& o /* Stay in place */6 S" X& h; [5 A8 F
z-index: 1;
7 B1 v. g% S; y) }" { /* Sit on top */
- _- f' S4 x( B, {3 O padding-top: 100px;
( a2 e. }1 L# R /* Location of the box */+ d! O! A5 [, o# i/ P9 h
left: 0;' j4 |. m, p7 D) f
top: 0;1 g" G: l2 M( P- D! I4 N1 `$ K
width: 100%;
3 u1 c3 A+ @5 T /* Full width */
, \$ Q1 w7 y* h( d, W height: 100%;& a2 W5 K7 H- L8 [+ t" h
/* Full height */
6 \+ a N# j6 p2 s( q overflow: auto;6 q# D" M( q( v3 G! l v1 i
/* Enable scroll if needed */4 L* q4 n q" n* R7 ?4 _
background-color: rgb(0, 0, 0);+ J+ n/ Q4 ^+ |
/* Fallback color */
$ j: N# W' d$ M/ `$ @0 {( R ~ background-color: rgba(0, 0, 0, 0.9);
. M5 p: X( V& B8 \1 N /* Black w/ opacity */2 g3 Q- ^0 K% l! {$ q
}
2 v m# J% A9 z4 d. \1 G2 t: d" d& [. \$ ~" i- A
/* 图片 */
0 H( A& v$ `! U' E .modelContent {% J8 I% [" B* c
margin: auto;
/ x! L% e- N; b% e* C) { display: block;
; j3 H9 L. y1 e5 _ width: 80%;
. W$ R5 v# y4 j8 A/ W! F max-width: 700px; z* x5 _( F: b3 O! U
}: ?/ p. v& N" Q7 b# c
, F' F4 F! M8 w+ K
/* 文本内容 */, @) g& [# C0 C) c% p. r3 T
#caption {& |1 n8 f- v" F
margin: auto;
3 w& f: L4 q; O5 M0 T8 P display: block;. `4 r- l4 K4 ?+ e3 v
width: 80%;
/ B0 j/ V! ~+ D0 K; Q max-width: 700px;
4 H M* A4 a; G L8 ]% ` text-align: center;# v. F% M' ^( q6 z) O; J
color: #ccc;
$ ^) f6 v& ?' U1 Q' A. W7 n padding: 10px 0;, r4 l5 Q8 h9 D( b% y$ k4 a$ M: v
height: 150px;1 d" G: q/ _0 F1 S; e
}4 V) o, G; O. h' J" ~0 _
/* 添加动画 */0 s9 `* H* [" E1 p1 B* S
.modelContent, #caption {
" r4 F* H2 M8 S animation-name: zoom;% W0 F5 U3 j8 u% C5 ~4 @
animation-duration: 0.6s;
. Q0 o q8 g5 f -webkit-animation-name: zoom;
& R# a( q7 {4 Q7 N7 w: O; n3 o -webkit-animation-duration: 0.6s;) T5 g+ O! t9 n
}# x2 A" [' I1 ^" Q! G5 G
" `2 K" A8 {8 W5 W2 y- u' ?$ x( D@keyframes zoom {
9 Z3 f- u6 W: Y0 r1 s" ]) ^ from {-webkit-transform:scale(0)}
# L8 n# S: _5 s- q to {-webkit-transform:scale(1)}
0 e9 M0 @+ I$ _4 B: ?8 u- K}
& ?) T3 r- f- S+ Q! ]
) z$ K5 E5 P7 k5 ? Y+ W; [ #myImg {# w0 _# ?/ D z F5 l
border-radius: 5px;
# D3 X$ J# A, O8 T* `: R' } cursor: pointer;
/ R0 B; Z$ F/ M4 |/ z3 u( d0 j transition: 0.3s;7 ?) s) j; _6 p
}
" ~) x, V/ ]- n( B. d* O# M+ _; H
, r. u% T; u1 k6 E9 T #myImg:hover {# N; g' {8 M6 u7 c4 k- [
opacity: 0.7;
, l2 \5 Z( G$ D9 ?! Z }; \2 t/ A$ {7 J$ H: n
2 m( k& H+ r) T+ X5 D9 ^
/* 关闭按钮 */: |) g3 g. H3 R9 Z. [" H
.close {. o0 @" q- X K8 `; O ~
position: absolute;: s2 @. d# \3 {' p; f$ q
top: 15px;! u; z" ^7 U' f: L
right: 35px;* i; A+ C* l0 H& r+ F" b
color: #f1f1f1;
: B' j: U* m Z- I2 |7 g+ a) @$ q font-size: 40px;2 Q( `) Y* l$ O/ o; h
font-weight: bold;( ]3 f/ X: j0 F: D3 Y* T
transition: 0.3s;
0 V& a8 E. j+ M8 ^, q" E }
o' T, W7 \4 d$ v% n# R7 l) H9 g+ o
.close:hover,7 P: \- a% X$ P: ~- @0 c" z
.close:focus {3 F- t6 y8 R. h3 j! l. m
color: #bbb;* V1 R7 j) b' K6 x' R1 ?' G( T
cursor: pointer;& H# P. K0 U2 M9 i) |4 L" k
text-decoration: none;+ q! M" e2 p: u9 D' {+ L$ |
}
1 Z/ j6 a0 k, u' j3 w4 r' o3 l6 q </style>% C: ?. v' t$ O
</head>0 I, R' |& D( g/ O
+ b) y7 O2 r2 L* q* B
<body>
; J& |8 D Y( S, M4 H/ F; m
6 Z. P9 t, _- } <img src="./img/Logo.png" alt="This is a logo" id="myImg" width="300" height="200" alt="This is a test ">/ c8 Z+ c! J+ _4 i
- a% _( | v" `9 J1 k
- U0 O% Z3 c6 o, s; z8 c& ?0 `/ _
<div id="model" class="model">
! Z- [4 K0 S4 T) {. L) U1 q0 @! u/ |4 R7 i) f9 X
3 X1 d; T1 \7 [/ N4 l
<span class="close">× </span>
2 [9 ]- ?* w5 ^+ l; V- V) p
0 I: C7 f% c/ T) A7 C* O <img id='img01' class="modelContent">! F$ X* w9 K1 i8 J; g7 _' Y; y3 c
`1 @! u. p! ~# g <div id="caption"></div>) X/ l2 e4 H7 ^
; F" R; d% U5 X0 A
E" K9 f! z! S4 P& Y9 A </div>
, f6 S! h) a* a/ T- C" z9 ^2 p4 L+ ~, U/ | j6 I
C3 O2 L/ N( P T' b1 B9 A) v% T5 Y. k9 E
<script>. ~. ~6 |, W, V' C5 w
" U8 \1 \( r2 S5 w7 h5 A, y
var imgx = document.getElementById('myImg');
6 N W m3 d9 K' c, ~$ u var modelx = document.getElementById('model');8 ~: [& f4 `8 @6 Q
var modelcontentx = document.getElementById('img01');
+ A9 X: [& K8 H9 K/ q var captioNX = document.getElementById('caption');
6 n% _" |+ h0 Z9 W/ z7 Y' B% Y% ]# A
imgx.onclick = function () {0 X) H2 v/ o& }8 B4 z' c
modelx.style.display = "block";
, C0 V3 ]/ ^; m5 Y modelcontentx.src = this.src;- [; ?2 h6 G+ ^4 z- f: `6 j
captionx.innerHTML = this.alt;
1 M9 X6 u( G* X
7 V0 O4 m- g( D }
4 k [ F! v, c' d5 [8 }9 o3 ~% N' i+ D5 ]$ ~1 C* g
: F- ^) H+ T8 |5 i" M
</script>$ q5 X* T& j3 l. `/ U, C
8 a$ `: X4 c; f- B5 P! R$ ^- r: Y# b$ [7 W2 `
( |/ q0 P2 o# `7 [( T1 a5 K
N- T5 `( x9 T6 Y. L: C2 G2 L</body>4 Q7 V6 s' Y. g: W3 V; d; ^
: k% ~! @6 Z$ U5 X</html>[/mw_shl_code]# z. }# O {- f1 Y Y& \( l
|
|