前端开发工程师面试题
转自:http://blog.sina.com.cn/s/blog_5d8975f30100jd9f.html
1. 用 CSS 实现布局
让我们一起来做一个页面
首先,我们需要一个布局。
请使用 CSS 控制 3 个 div,实现如下图的布局。
这题不难,在平时项目开发过程中也经常会碰到:
主要考虑几个问题:1. IE6 的 3 像素 BUG;2. 清楚浮动;
代码:
div{background:#CCCCCC;}
#first{float:left;width:100px;
#second{clear:left;float:left;margin-top:10px;width:100px;height:150px}
#third{zoom:1;
XML/HTML代码:
<div <div
<div
2. 用 javascript 优化布局
由于我们的用户群喜欢放大看页面
于是我们给上一题的布局做一次优化。
当鼠标略过某个区块的时候,该区块会放大25%,
并且其他的区块仍然固定不动。
提示:
也许,我们其他的布局也会用到这个放大的效果哦。
可以使用任何开源代码,包括曾经你自己写的。
关键字:javascript、封装、复用
惭愧啊,用上边那个布局我怎么也没把它优化出来,硬这头皮用绝对定位改了布局;
所以样式改成了这样
CSS代码:
body{ div{background:#CCCCCC;
#first{width:100px;
#second{top:160px;width:100px;height:150px}
#third{
javascript 要考虑封装、复用
JavaScript代码:
function var
var
var
//var
//var
obj.onmouseover=function(){
this.style.width=dW*x+"px";
this.style.height=dH*y+"px";
this.style.backgroundColor="#f00″;
this.style.zIndex=1;
}
obj.onmouseout=function() {
this.style.width="";
this.style.height="";
this.style.padding="";
this.style.backgroundColor="";
this.style.zIndex="";
}
}
zoom("first",1.25,1.25);
zoom("second",1.25,1.25);
zoom("third",1.25,1.25);