File tree Expand file tree Collapse file tree 6 files changed +64
-0
lines changed
Expand file tree Collapse file tree 6 files changed +64
-0
lines changed Original file line number Diff line number Diff line change 1+ <!DOCTYPE html>
2+ < html lang ="en ">
3+ < head >
4+ < title > </ title >
5+ < style type ="text/css ">
6+ body {
7+ margin : 0 ;
8+ padding : 0
9+ }
10+ /*这一层是自己添加的,源代码是直接menu为最外层,但是这样不利于布局*/
11+ # box {
12+ width : 100% ;
13+ height : 200px ;
14+ position : relative;
15+ }
16+ # menu {
17+ position : absolute;
18+ width : 100% ;
19+ min-width : 1000px ;
20+ bottom : 0 ;
21+ text-align : center;
22+ }
23+ </ style >
24+ </ head >
25+ < body >
26+ < div id ="box ">
27+ < div id ="menu ">
28+ < img src ="images/1.png " />
29+ < img src ="images/2.png " />
30+ < img src ="images/3.png " />
31+ < img src ="images/4.png " />
32+ < img src ="images/5.png " />
33+ </ div >
34+ </ div >
35+ </ body >
36+ < script type ="text/javascript ">
37+ window . onload = function ( )
38+ {
39+ var oMenu = document . getElementById ( "menu" ) ;
40+ var aImg = oMenu . getElementsByTagName ( "img" ) ;
41+ var aWidth = [ ] ;
42+ var i = 0 ;
43+ //保存原宽度, 并设置当前宽度
44+ for ( i = 0 ; i < aImg . length ; i ++ )
45+ {
46+ aWidth . push ( aImg [ i ] . offsetWidth ) ; //当前图片为128px乘128px
47+ aImg [ i ] . width = parseInt ( aImg [ i ] . offsetWidth / 2 ) ; //为每一张图片设置新宽度,为原宽度/2
48+ }
49+ //鼠标移动事件
50+ oMenu . onmousemove = function ( event )
51+ {
52+ var EVENT = event || window . event ;
53+ for ( i = 0 ; i < aImg . length ; i ++ )
54+ {
55+ var a = EVENT . clientX - aImg [ i ] . offsetLeft - aImg [ i ] . offsetWidth / 2 ;
56+ var b = EVENT . clientY - aImg [ i ] . offsetTop - oMenu . offsetTop - aImg [ i ] . offsetHeight / 2 ;
57+ var iScale = 1 - Math . sqrt ( a * a + b * b ) / 300 ;
58+ if ( iScale < 0.5 ) iScale = 0.5 ;
59+ aImg [ i ] . width = aWidth [ i ] * iScale ;
60+ }
61+ } ;
62+ } ;
63+ </ script >
64+ </ html >
You can’t perform that action at this time.
0 commit comments