|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
0 l4 U6 @" I) e. J1 A1 \
点击图片方法JS动画效果
9 N/ C, {9 Y& D
4 B0 @6 x& c3 j[mw_shl_code=html,true]<html lang="en">
& e- N% D! w. u0 c: I, F2 m0 S8 D, ^* f0 {
<head>( B4 t% F3 I" T* @) N
<meta charset="UTF-8">
1 y* C( ^" a! S/ J1 y0 o" ? <meta name="viewport" content="width=device-width, initial-scale=1.0">
# [- g) V( b7 L3 R: W, b <meta http-equiv="X-UA-Compatible" content="ie=edge">
/ s0 ?6 ~. f9 Q4 E0 o9 ^ <title>Popup Model</title>/ q8 Y, L9 i' q0 M3 E2 G& }& c
( I g3 J3 ^3 C" I9 g <style>
2 S6 L! ^# V8 H* X8 ^# \; l6 B /* 弹窗背景 */$ |' L3 @5 v6 C& |5 ^: m
.model {
% t3 J& C: C! I4 J/ n1 L display: none;
+ E& l& ~5 \2 ? position: fixed;) h! x' I# O$ Z# K/ [0 o- e
/* Stay in place */# d: u1 O" I+ L; I0 [6 U
z-index: 1;
! v, s' H- l9 \# [' v /* Sit on top */
4 ?. }9 r2 s0 T v' Y: _ padding-top: 100px;
. K& a/ c, }4 _: a9 t- F" Q% M/ s /* Location of the box */
! W; o6 D0 G% S2 E) H7 I5 y+ E, H left: 0;
( J" B; j& h0 W. y% y: z- w top: 0;
' I; B, b, F& l2 k7 d* F2 }/ A, w+ d width: 100%;# v# z9 X) L+ h7 t; c2 P2 `: S
/* Full width */
1 p) f7 F, i+ f/ j7 G N; v" _ height: 100%;; s0 m# O! ?* |# p
/* Full height */1 `2 N( b" S9 Z" J) D9 |5 {/ z
overflow: auto;
+ I% q" B1 H _. _* b /* Enable scroll if needed */6 j+ b, Y% f3 T$ u
background-color: rgb(0, 0, 0);
- }2 \" k/ ^, B Y! Z4 k /* Fallback color */
0 L+ K! U5 N2 [7 Z4 x4 n background-color: rgba(0, 0, 0, 0.9); y: B% y& Y, I
/* Black w/ opacity */
; j6 q" q2 ~/ F' W }
7 H) E6 f4 f2 g
/ n- E. S0 L D* Q: c2 b /* 图片 */
2 _( ~8 T: W8 I4 a( m .modelContent {/ b; O1 l: i2 J6 N, @; H; n
margin: auto;
4 C( t3 h# P) @$ z4 W) d. N display: block;. A: V% R/ z! O9 v5 G
width: 80%;
, H& P/ p/ N% Y% i: ^# K9 a/ ` max-width: 700px;
/ H% s6 I8 B, I+ H1 g9 _$ t$ @ }, c% U+ Q8 E1 P1 J6 f
6 k. Q! P% I3 F) \) W) c% g" K /* 文本内容 */2 g) X% @* e8 Y9 S
#caption {
, b3 j ?$ M5 z t$ U6 J$ S: h) e margin: auto;/ |; h9 f k$ ~2 a
display: block;
* _3 Z6 D. H ^( M! x( e width: 80%;
# t9 [, B( O( e max-width: 700px;
8 H w+ S5 B2 a$ i% R9 \! b text-align: center;- W* W- n: {1 M4 J/ \
color: #ccc;
1 T# m7 }. u' C/ \. _+ d) T padding: 10px 0;- v+ Q) ?6 l% _' Y
height: 150px;
6 ]/ ` P6 J/ z) L' K# M }5 |( [0 ] X; b
/* 添加动画 */& R; ^' J4 m! j
.modelContent, #caption { 5 Z- m9 [0 O, ^' \5 p. C
animation-name: zoom;3 D5 [5 \& I" r; Y
animation-duration: 0.6s;
9 c. ] ^& N" }! Y! n! H- W% X6 B -webkit-animation-name: zoom;& i. o. N; e+ O1 R/ v' d" t
-webkit-animation-duration: 0.6s;
$ A( b4 s/ l) [}+ q) x$ G3 B$ I& E- k. R
/ ?# I5 o8 f m/ k@keyframes zoom {" U3 s2 T. `5 T8 h" l
from {-webkit-transform:scale(0)}
9 S/ p S$ a7 j/ i9 u to {-webkit-transform:scale(1)}. a9 }1 l$ Q5 G0 Y
}- C/ s D- m4 C; @9 ]6 \) `+ B7 B2 P& T
% P- e* W5 ] f0 v8 r #myImg {
/ j! t7 @+ z2 a& M4 y border-radius: 5px;
1 b( u! v/ q, \. R" F' I/ O1 \: y cursor: pointer;
! p ]% S5 {9 x! j$ J transition: 0.3s;( f$ D7 n n1 d" ^: O. \& I/ c5 M: ?
}( n _3 n, C4 g3 Z: d, F0 _
" i6 z* t v u" E9 G" Z1 Y9 D #myImg:hover {# t8 m/ F2 [5 S/ D
opacity: 0.7;1 \, d( J* Z' p, \1 M
}9 z4 H+ ]. v& R1 k4 |8 Y
# N9 m5 Z0 ~, b% Z, s3 U4 s /* 关闭按钮 */& w! n1 M' B# |; R _! W
.close {
\6 T( p. p2 { position: absolute;
: p n; a; e% Z/ I top: 15px;
) o1 c% e/ g% V0 g6 l right: 35px;
, O; Z# U6 ^4 V& P6 P' Q color: #f1f1f1;. H( f) r8 d& U8 E" J8 y
font-size: 40px;3 v5 Q: P1 R7 f
font-weight: bold;
- _; H. Q5 e9 k: q) K0 N& d. e transition: 0.3s;
( o/ Z: H0 l# }5 ]$ [$ Q1 L }. V2 Z2 @9 Q- [
2 B1 p4 c V( r0 s .close:hover,4 \ {6 ~' z- v4 h3 y3 j8 T' [% h
.close:focus {9 _! e d! D5 ^. m8 y2 O q: ^
color: #bbb;
. \( L- m7 d4 k$ I6 P; @4 m cursor: pointer;
) I. f( M8 m8 F, u& F text-decoration: none;3 E5 M. `- E$ E2 r: T1 s! j2 i
}- p% V) b6 l; M3 @/ G
</style>
# v" d% m4 Y& g4 d6 {' v% E! F</head>
) f- K! C0 }7 p" a, w
8 x. T! X; {. g6 d9 Y6 F<body> |. A) Y ~. V& H3 @$ A
% d$ n2 s# j% G. K <img src="./img/Logo.png" alt="This is a logo" id="myImg" width="300" height="200" alt="This is a test ">
% B% {( w; z3 i3 Y$ c v
$ d2 @: M) _8 u$ R+ Q* B& F4 Y5 l- B9 n
<div id="model" class="model">5 y9 v* q% p3 b8 {7 l* z. V" N
9 t+ `$ A$ P& f2 u& d
* P" o( B6 S( D+ F- T# S
<span class="close">× </span>
) r- e# ~9 Q/ {) T: ~
1 H, t) S' w- r <img id='img01' class="modelContent">
, f' f# g5 @& s
, z# v7 i+ \+ U S) m( `2 J <div id="caption"></div>, K o s3 K) l7 V- ~
5 Y) [) t( _9 P+ [% O
2 c/ k: P) q E& n9 K4 R
</div>! h' i2 M/ l% Y2 {$ P1 Q7 ^
: y" T2 s g/ p( W7 @ c1 t$ z/ f3 F+ |5 ~ z' W
+ @- a. B( {& K2 Q, T l& P* A7 A1 D
<script>2 k# W6 }) y! V& R9 u
$ {! x# C$ R' W( E
var imgx = document.getElementById('myImg');. w% m7 C9 a! t4 {+ V
var modelx = document.getElementById('model');
9 D- R- p0 ~) i) ?% \/ l$ {9 J+ [0 e var modelcontentx = document.getElementById('img01');; k5 g1 f, O/ ~4 M2 t7 s# f
var captioNX = document.getElementById('caption');7 d& z! V. L3 K" S6 ^
. }3 \) i1 Q+ |& N9 \
imgx.onclick = function () {
0 Y) z% U2 ~1 E4 y# E modelx.style.display = "block";
9 u7 u' ]! t7 [1 z5 Q" n0 M modelcontentx.src = this.src;4 W" N5 r) a; ?1 ~$ ^
captionx.innerHTML = this.alt;
2 T0 Y4 o7 X7 [4 _& T* ?
% E6 l3 n7 V. M }
: l- E4 A) R8 v. k. G% A/ T/ _- C G8 o5 D* ~
n4 y$ ]* U: g! a, t </script>
/ O \/ p e# p! U0 ~) Z8 H/ e J
2 ?" p0 J- }7 o3 @1 B
4 p$ {6 p. k, s( C) _6 V
5 Z7 J2 K8 U ?% p+ o" ~</body>6 m$ O. \4 }/ p8 f# |
! L* v l6 f5 H5 |0 @
</html>[/mw_shl_code]
! p7 x0 |5 }' U$ n- J |
|