---恢复内容开始---

  • 效果图说明:当鼠标移到哪一个按钮上的时候会自动跳转到某一张图片上,并且按钮会以高亮显示

Js封装的动画函数实现轮播图

 

  • 项目目录结构

Js封装的动画函数实现轮播图

 

  • 用到的js封装的animate()动画

       

 function animate(element, target) {
    clearInterval(element.timeId);
    //定时器的id值存储到对象的一个属性中
    element.timeId = setInterval(function () {
      //获取元素的当前的位置,数字类型
      var current = element.offsetLeft;
      //每次移动的距离
      var step = 10;
      step = current < target ? step : -step;
      //当前移动到位置
      current += step;
      if (Math.abs(current - target) > Math.abs(step)) {
        element.style.left = current + "px";
      } else {
        //清理定时器
        clearInterval(element.timeId);
        //直接到达目标
        element.style.left = target + "px";
      }
    }, 20);
  }
animate.js

相关文章:

  • 2021-11-02
  • 2021-08-18
  • 2021-12-15
  • 2021-12-15
  • 2022-12-23
  • 2022-12-23
  • 2021-08-08
  • 2021-04-04
猜你喜欢
  • 2021-07-05
  • 2022-12-23
  • 2022-12-23
  • 2021-08-25
  • 2021-08-20
  • 2021-12-08
相关资源
相似解决方案