百叶窗大家都见过吧!如图:

原理:

  1. 如图所示,空心格子就好比是每个li,给它设定相对定位属性,设置overflow:hidden;
  2. 黑块为li子元素,高度为li的2倍,设置absolute属性,我们正是要改变它的top值从而获得变化!
  • (右上角多余块与本图无关)

布局分析:

  • 注意top值得变化!默认top=0时候,显示的“一楼上铺”,当top=-40px时候,li的子元素 上移40px,这时候显示的内容就为“一楼下铺”
  • 注意p元素的包裹层div

JS分析:

    1. 要开多个定时器来达到效果
    2. 执行相反方向
    3. 执行多组运动
    4. 累加产生错落感
    5. 产生时间间隔的动画

JS代码如下:

     <script>
window.onload = function(){
var oUl = document.getElementById('ul1');
var oUl2 = document.getElementById('ul2'); toShow(oUl);
//每四秒执行一次
setTimeout(function(){
toShow(oUl2);
},4000);
function toShow(obj){
var aDiv = obj.getElementsByTagName('div');
var iNow = 0;
var timer = null;
var bBtn = true; setInterval(function(){
toChange();
},2000);
function toChange(){
timer = setInterval(function(){
if(iNow==aDiv.length){
clearInterval(timer);
iNow = 0;
bBtn = !bBtn;
}
else if(bBtn){
startMove(aDiv[iNow],{top:0},function(){
var p = document.getElementsByClassName('p-2');
for(var i=0; i<p.length;i++){
p[i].style.background = 'red';
}
});
iNow++;
}
else{
startMove(aDiv[iNow],{top:-30});
iNow++;
}
},100);
}
}
};
       //运动框架
function startMove(obj,json,endFn){
clearInterval(obj.timer);
obj.timer = setInterval(function(){
var bBtn = true;
for(var attr in json){
var iCur = 0;
iCur = parseInt(getStyle(obj,attr)) || 0;
var iSpeed = (json[attr] - iCur)/8;
iSpeed = iSpeed >0 ? Math.ceil(iSpeed) : Math.floor(iSpeed); if(iCur!=json[attr]){
bBtn = false;
}
obj.style[attr] = iCur + iSpeed + 'px';
}
if(bBtn){
clearInterval(obj.timer);
if(endFn){
endFn.call(obj);
}
}
},30);
}
        //获取非行间样式
function getStyle(obj,attr){
if(obj.currentStyle){
return obj.currentStyle[attr];
}
else{
return getComputedStyle(obj,false)[attr];
}
}
</script>

下载地址:(百度云)

  • http://pan.baidu.com/s/1gexD6KF

博客主页:http://www.cnblogs.com/bc8web/

欢迎拍砖交流!

最新文章

  1. Android.os.NetworkOnMainThreadException
  2. sql server 跨数据库插入数据
  3. hdu.5212.Code(莫比乌斯反演 &amp;&amp; 埃氏筛)
  4. ipython
  5. Mantis 缺陷管理系统配置与安装
  6. Ubuntu 安装JDK并配置成为默认的JDK
  7. 教程Xcode 4下编译发布与提交App到AppStore
  8. 利用ArcMap对tiff或jpg格式地图图片的配准步骤
  9. angular service讲解
  10. myBatis自动生成相关代码文件配置(Maven)
  11. KVO初探
  12. 南阳师范学院ACM官方博客使用说明
  13. C++ regex库的三种正则表达式操作
  14. poj 3261
  15. 分解数据表(将一个datatable按数据量分隔成多个table)
  16. zabbix添加对自定义无规则的关键日志文件的监控
  17. FragmentPagerAdapter 与 FragmentStatePagerAdapter 的区别
  18. 从MS Word到Windows Live Writer
  19. Linux命令(十二) 分割文件 split 合并文件 join
  20. 解决secureCRT 数据库里没有找到防火墙 &#39;无&#39; 此会话降尝试不通过防火墙进行连接。

热门文章

  1. uedit富文本编辑器及图片上传控件
  2. mac下的一个类似“_kbhit()”实现
  3. modern.IE
  4. 数组/指针/const/字符串常量的使用传值问题
  5. Beetlsql自定义生成entity,mapper,md代码
  6. Navigation and Pathfinding
  7. java集合:常用集合的数据结构
  8. lammps模拟化学反应(1)
  9. PHP - MongoDB连接攻略
  10. Spring Boot 简单入门