定时器轮播图
1.动态封装函数
// 如果样式的代码在style的标签中设置, 外面是获取不到的
//获取div当前的位置
console.log(my$(“dv”).offsetLeft);// 数字类型 没有px
//点击按钮移动到400px , 每过20毫秒移动10px
my$("btn").onclick = function () {
animate(my$("dv"), 400)
}
//点击第二个按钮移动到800px
my$("btn1").onclick = function () {
animate(my$("dv"), 800)
}
//定义动画函数 ; 目标位置需要变, 元素要变
// function animate(element , target) {
// clearInterval(element.timeId);
// element.timeId=setInterval(function(){
// var current=element.offsetLeft;
// var step=10;
// step=current<target? step:-step;
// current+=step;
// if(Math.abs(target-current)>Math.abs(step)){
// element.style.left=current+"px";
// } else{
// clearInterval(element.timeId);
// element.style.left=target+"px&#