|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
×
; O5 U0 }1 Q4 X G/ ?点击图片方法JS动画效果
6 q7 q# r: H' P
& u. t4 v- v% a, k p: D$ p* J[mw_shl_code=html,true]<html lang="en">
# V; E/ c9 |- ]4 G z
+ \5 o* _4 K i8 T( y' _) T<head>
' {+ M* S+ q, ^7 T8 h <meta charset="UTF-8">8 S7 U' e4 u3 f" |& a5 X2 ?9 Q
<meta name="viewport" content="width=device-width, initial-scale=1.0">
$ w4 d% w8 e% Y4 x' e& d9 u <meta http-equiv="X-UA-Compatible" content="ie=edge">% a8 y+ L) i; P
<title>Popup Model</title>1 ?# c" u y# E; |
. p$ a( W& ^3 ^$ ^' y1 D8 Y <style>2 R; y3 Y" B$ g6 Y
/* 弹窗背景 */+ A; F! K6 H& n5 G: O
.model {: G9 B4 @/ t7 x: q* l2 C
display: none; P/ f' j/ ?5 |2 B/ V
position: fixed;' r( t9 a9 E6 D4 W
/* Stay in place */
& e! W6 p4 M! E z-index: 1;
2 J. z* _# E$ H$ A8 E% e /* Sit on top */$ a+ Y, H7 A1 {# s
padding-top: 100px;
/ M* X4 H1 X$ \- J /* Location of the box */
* h/ E, L% e' K3 Z$ f5 O# i left: 0;2 o% O6 s' V, k! b
top: 0;
- H6 f. k. n8 n4 l width: 100%;
4 F( z! b7 ^! U' Y /* Full width */
9 a/ z5 ?6 C9 k+ E/ F height: 100%;# |, _: l2 o) U
/* Full height */, ^! l0 T+ r7 B: S! T
overflow: auto;
& y8 J3 z; f; [4 V" j6 d x1 E- Q /* Enable scroll if needed */# y( d7 p, {. n4 ]. B. w" J
background-color: rgb(0, 0, 0);- d( d3 \$ }" [/ ]( ?$ ^, T
/* Fallback color */+ |- G! N2 n( H. {. \' ]9 l
background-color: rgba(0, 0, 0, 0.9);4 L4 `( s/ J. |" I5 L, D. o1 ]
/* Black w/ opacity */
' x& k' V7 ]# u6 { ~ }1 g+ L+ S* T6 p) Y! |/ i
1 x8 ?5 c( L0 d6 D, E /* 图片 */
& R6 J$ N+ u: ]+ C7 j4 W% \ .modelContent {- p6 t! C6 R. u0 Y" A5 p' X
margin: auto;' E7 I5 H, n. [) p2 j
display: block;$ p& }$ @# V' ]* ^7 g. q; J; C
width: 80%;
: J. Z! i/ `2 Y; l( g" P max-width: 700px;
3 t+ i* u+ S3 u: m9 j }. |' @% `' R: k+ Y3 r+ Q! O
- \) O/ o1 U* d) \5 c/ T/ X7 @2 r
/* 文本内容 */' C5 z( E+ `: m8 Z" s1 Y
#caption {3 c* L, o2 E# H! S3 J) _ ~- ]1 }1 X
margin: auto;+ U" A' S* ~" U1 q0 n z- `
display: block;# v5 B* z, Q+ O2 f- ^& U
width: 80%;
- v1 ^! V, _0 d max-width: 700px;
( Q* Q- X- \; ? text-align: center;
3 s) p' M+ {' u! x color: #ccc;" l7 u& C) r& a# R! Z
padding: 10px 0;+ {5 `9 v2 V' P. Y# D
height: 150px;+ B' c( ~1 j- X2 F5 `
}8 o; W9 N. G" I& t) x
/* 添加动画 */% i- Y8 z; y' G8 X
.modelContent, #caption {
5 k* b P5 h* J& p# m animation-name: zoom;/ }: k% k/ w. a$ ]1 e% m+ s
animation-duration: 0.6s;
9 Y$ ` ^" p4 X0 b -webkit-animation-name: zoom;5 C- G Z6 d$ G6 H# b
-webkit-animation-duration: 0.6s;
3 @, h8 \4 o2 S, `) t}; C7 f# a" S$ T' c
6 Y x! @ H! K4 Q6 M
@keyframes zoom {6 Q" ?, N2 k# g3 E: o* [
from {-webkit-transform:scale(0)} + D3 v6 u) ~& ~
to {-webkit-transform:scale(1)}
9 ^5 r' o1 @! ?: m! z1 q' s$ c}! v: X" {* W$ B$ Q @# ^6 v/ W& {
- G' v. ~- M% J* l0 K: N* M #myImg {
, [% s/ u% c/ C6 v( N6 j border-radius: 5px;
: E, J( m2 D% u( f& b7 z T1 \1 w cursor: pointer; j$ ^+ t/ d. r' W7 Y
transition: 0.3s;
5 Q' u, [& r2 J) u2 F, j; B* h* B- N }4 A; e# r) s4 V& L
. F( g6 [& p& [ D: n$ v2 x& _# m
#myImg:hover {' O. y5 s4 r' U# o" Z
opacity: 0.7;
, }( N. s6 e5 K- b, J) n* @ }& A/ Y" t! A" [# [8 ~- T# X4 @. l
9 U6 e& ?- {9 |# J
/* 关闭按钮 */: g. Y' z2 b+ g6 @( C5 E
.close {0 h$ q8 l C* l( t/ E+ J/ X% ]& y
position: absolute;9 \2 M7 O( R+ d2 B5 W- V
top: 15px;; ?8 y" }# g' }6 B1 i, l2 | k
right: 35px;* u9 L( ?. F/ G% O8 K, @
color: #f1f1f1;
0 O1 A/ ~ B9 [5 G# e$ ^ font-size: 40px;
" M4 f. t% Y- A* K- p, C. Z% F font-weight: bold;
, o: E3 J7 |9 g transition: 0.3s;
! W. I: x) _8 }5 f/ O$ X% \ }. L( @! G$ @" [! y' B
7 V- a/ w* r8 }) @$ R
.close:hover,
" b7 s5 U" [- l; u0 d .close:focus { f- a* ]* L: u6 g" V
color: #bbb;
+ A2 C$ q1 j- o cursor: pointer;4 P4 |& C$ _* u
text-decoration: none;2 C4 d. u: t: H. i+ ^0 q- |
} S' K) u6 S$ Q' N) m) @0 @! W
</style>
+ R$ N8 }% z6 z$ y4 J$ |* v# F</head>
% P8 u) ~3 l9 ~& Y/ a e0 [
- z4 ?4 q( |: G, v. n/ X+ C' o<body>2 _ |* c$ e9 ?* J5 s8 f
+ M" u) ]0 T0 C5 g2 h# n, b, b
<img src="./img/Logo.png" alt="This is a logo" id="myImg" width="300" height="200" alt="This is a test ">) [% X0 f3 e/ }5 c! @! {
% G2 z/ c, x0 d) Z( I$ C( e$ M( V( X
<div id="model" class="model">
" m0 q, Z5 U! e* y1 c$ u, _4 h! z% u
! H$ Y" t( ^6 \8 L( W# _ <span class="close">× </span>
2 }: Y: E6 [7 T$ l3 T
- N3 y. B! P" A% w+ @ <img id='img01' class="modelContent">; |' C) o- x$ h: ~$ I) p
' S4 `8 }9 T% O3 {' t
<div id="caption"></div>
# f; Y( N- T% }6 O& v) t2 y8 s0 Y" H% U4 s `
, }1 R2 W; R, U </div>, |2 L8 X0 E: Y0 y6 @
9 n4 U% |; B% o7 y- K. E; r7 d0 {
2 A Q/ s! t% j$ K! y/ ~, q
& k; y5 W2 l; s" X8 y, r <script>+ g. X8 i4 ~) J' M. V
$ M( h o9 Z. b4 }/ o* g' e var imgx = document.getElementById('myImg');
9 F' q7 a7 S' {# V" h! p var modelx = document.getElementById('model');
4 q9 S H" D, f* t- I2 ?) N$ ^; R) k2 p# w var modelcontentx = document.getElementById('img01');
4 @7 E$ O2 l& x3 r. O8 D/ [6 J p var captioNX = document.getElementById('caption');
6 m7 ^% ~0 x# d- U6 L6 j& c2 ^2 U! R- u$ [! U3 I6 K( h+ B
imgx.onclick = function () {* _5 N+ |8 v# F" u
modelx.style.display = "block";
& @: A, v- y# i+ l2 G* G% n modelcontentx.src = this.src;2 p% @: p; K9 h1 Z9 ^. b
captionx.innerHTML = this.alt;1 ~8 b% {$ a2 v1 S
) d9 A& e3 M+ L1 u1 R
}
7 a2 ~ r" M! F) ~- ], S1 y* s, }, p- R% {9 R
' L' k& [1 r/ I! H& }: A2 O2 V1 C. c </script>
; _6 t1 s: i' w) }5 ]
" X& s9 I( Z0 P) Y& L% p0 g4 O3 \5 p/ K, G$ n+ ~4 {4 a
+ w* u' V0 R3 E8 g# k) R2 `! w( X9 `* U3 ~$ N6 S& g" S* g
</body>
/ q1 V( G' Y2 h9 e4 N* J/ h
" O ^' ]7 r1 y: |& j</html>[/mw_shl_code]* b3 x1 l8 Y( A9 b
|
|