让咱们一块儿来作一个页面。首先,咱们须要一个布局。
javascript
请使用 CSS 控制 3 个 div,实现以下图的布局。java
这题不难,在平时项目开发过程当中也常常会碰到:函数
主要考虑几个问题:1. IE6 的 3 像素 BUG;2. 清楚浮动;布局
代码:优化
1 |
div{ background : #CCCCCC ;} |
2 |
#first{ float : left ; width : 100px ; height : 150px } |
3 |
#second{ clear : left ; float : left ; margin-top : 10px ; width : 100px ; height : 150px } |
4 |
#third{zoom: 1 ; width : 200px ; margin-left : 110px ; _margin-left : 107px ; height : 310px } |
XML/HTML代码:this
1 |
< div id = "first" ></ div > |
2 |
< div id = "second" ></ div > |
3 |
< div id = "third" ></ div > |
因为咱们的用户群喜欢放大看页面,因而咱们给上一题的布局作一次优化。spa
当鼠标略过某个区块的时候,该区块会放大25%,而且其余的区块仍然固定不动。调试
也许,咱们其余的布局也会用到这个放大的效果。能够使用任何开源代码,包括曾经你本身写的。code
关键字:javascript、封装、复用。对象
惭愧啊,用上边那个布局我怎么也没把它优化出来,硬这头皮用绝对定位改了布局;
因此样式改为了这样:
1 |
body{ margin : 0 ; padding : 0 } |
2 |
div{ background : #CCCCCC ; position : absolute } |
3 |
#first{ width : 100px ; height : 150px } |
4 |
#second{ top : 160px ; width : 100px ; height : 150px } |
5 |
#third{ width : 200px ; height : 310px ; left : 110px } |
javascript 要考虑封装、复用。
JavaScript代码:
01 |
function zoom(id,x,y) |
02 |
{ |
03 |
// 设置缩放函数参数:容器id、横向缩放倍数、纵向缩放倍数(等比例缩放时也能够设定一个参数) |
04 |
var obj=document.getElementById(id); // 获取元素对象值 |
05 |
var dW=obj.clientWidth; // 获取元素宽度 |
06 |
var dH=obj.clientHeight; // 获取元素高度 |
07 |
//var oTop=obj.offsetTop; |
08 |
//var oLeft=obj.offsetLeft; |
09 |
obj.onmouseover= function (){ // 鼠标移入 |
10 |
this .style.width=dW*x+ "px" ; // 横向缩放 |
11 |
this .style.height=dH*y+ "px" ; // 纵向缩放 |
12 |
this .style.backgroundColor=" #f00″; // 设置调试背景 |
13 |
this .style.zIndex=1; // 设 置z轴优先 |
14 |
} |
15 |
obj.onmouseout= function () { // 鼠标移出,设回默认值 |
16 |
this .style.width= "" ; |
17 |
this .style.height= "" ; |
18 |
this .style.padding= "" ; |
19 |
this .style.backgroundColor= "" ; |
20 |
this .style.zIndex= "" ; |
21 |
} |
22 |
} |
23 |
zoom( "first" ,1.25,1.25); |
24 |
zoom( "second" ,1.25,1.25); |
25 |
zoom( "third" ,1.25,1.25); |