setInterval图片缓冲(js)
来源:互联网 发布:淘宝怎么进行实名认证 编辑:程序博客网 时间:2024/05/16 18:07
css:
#div{ position: absolute; left:800px; top:30px; background: yellowgreen; width:100px; height:100px;}#target{ width:1px; height:300px; background: black; position: absolute; left:300px; top:0;}html:
<!--终点线--><div id="target"></div><!--终点线--><div id="div"></div><input type="button" value="点击运动" id="btn">js:
var btn=document.getElementById("btn");btn.onclick=function () { startMove(300)}var timer=null;var startMove=function (oTarget) { clearInterval(timer); var odiv=document.getElementById("div"); timer=setInterval(function () { var ispeed=(oTarget-odiv.offsetLeft)/8; ispeed>0?ispeed=Math.ceil(ispeed):ispeed=Math.floor(ispeed);//准确到达终点的位置 - 三目运算 // if(ispeed>0){ //准确到达终点的位置 // ispeed=Math.ceil(ispeed) // }else{ // ispeed=Math.floor(ispeed) // } if(odiv.offsetLeft<=oTarget){ clearInterval(timer); }else{ odiv.style.left=odiv.offsetLeft+ispeed+"px"; } },30)}
阅读全文
0 0
- setInterval图片缓冲(js)
- js实例(setInterval, clearInterval)
- Js setInterval
- JS 定时器(setInterval和setTimeout 函数)
- JS 定时器 (setInterval 和 setTimeout 函数)
- 分享到—setInterval(js)
- 通过alpha变量实现图片透明度渐变(仍然用到JS缓冲运动框架)
- 缓冲加载图片的 jQuery 插件 lazyload.js 使用方法详解
- 缓冲加载图片的 jQuery 插件 lazyload.js 使用方法详解
- 缓冲加载图片的jQuery插件lazyload.js 使用方法详解
- 缓冲加载图片的 jQuery 插件 lazyload.js 使用方法详解
- 缓冲加载图片的 jQuery 插件 lazyload.js 使用方法详解
- JS中图片缓冲loading技术的实例代码
- 缓冲加载图片的 jQuery 插件 lazyload.js 使用方法详解
- 缓冲加载图片的 jQuery 插件 lazyload.js 使用方法详解
- 缓冲加载图片的 jQuery 插件 lazyload.js 使用方法详解
- js setinterval用法
- 关于js setInterval setTimeout
- dict
- java对象的内存
- Python 编码规范
- Javascript——简介
- [codeforces] 877E. Danil and a Part-time Job(DFS序+线段树)
- setInterval图片缓冲(js)
- 数据结构--线性表C实现
- 试试写个博客
- 升级nodejs, npm到某一版本
- php实现兼容Unicode文字的字符串大小写转换strtolower()和strtoupper()
- history.go(-1)、history.back()区别
- 实验6:图的实验1
- springmvc自定义参数绑定实现日期参数绑定
- sql(join on 和where的执行顺序)