PC端网页特效

1、元素偏移量offset系列

eg:

offset和style区别:

2、client系列

 立即执行函数

作用:创建一个独立作用域,里面所有变量都是局部变量,不会有命名冲突

 eg:

 3、元素滚动scroll系列

 兼容性

三大系列比较及用法

 

mouseenter和mouseover区别

 4、动画函数封装

核心原理

动画函数的封装(函数需要传递动画对象和移动到的距离参数)

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box {
            position: absolute;
            top: 100px;
            width: 200px;
            height: 200px;
            background-color: blue;
        } 
        .span {
          position: absolute;
          top: 200px;
            width: 200px;
            height: 200px;
            background-color: red;
        }
    </style>
</head>
<body>
    <div class="box"></div>
    <div class="span"></div>
    <script>
        // 简单动画函数封装obj目标对象  target目标位置
      function animate(obj,target) {
        var time=setInterval(function() {
            if(div.offsetLeft >=target) {
                // 停止动画
                clearInterval(time);
            }
            obj.style.left=obj.offsetLeft+1+'px';
        },30)
      }
      var div=document.querySelector(".box");
      var span=document.querySelector(".span");
      animate(div,100);
      animate(span,100);

    </script>
</body>
</html>

给不同元素记录不同的定时器

eg:

css:
 .ca {
            position: absolute;
          top: 400px;
            width: 200px;
            height: 200px;
            background-color: red;
        }
html:  <div class="ca">点击我</div>
js:
//   不同元素给不同的计时器 
    //定时器会叠加,如果使用点击事件这种类型的时候会点一次触发一次,不断叠加,
    // 添加取消定时器避免叠加
function animate(obj,target) {
        clearInterval(obj.time);
        obj.time=setInterval(function() {
            if(div.offsetLeft >=target) {
                // 停止动画
                clearInterval(obj.time);
            }
            obj.style.left=obj.offsetLeft+1+'px';
        },30);
      }
      var div=document.querySelector(".box");
      var span=document.querySelector(".span");
      var ca=document.querySelector(".ca");
      animate(div,100);
      animate(span,100);
      ca.addEventListener("click",function() {
          animate(ca,200);
      })

缓动动画原理

匀速动画:盒子当前位置+固定值

缓动动画:盒子当前位置+变化值(目标值-现在的位置)/10

eg:

   //   缓动动画原理
      function animate(obj,target) {
        clearInterval(obj.time);
        obj.time=setInterval(function() {
            var stop=(target-obj.offsetLeft) /10;
            if(div.offsetLeft =target) {
                // 停止动画
                clearInterval(obj.time);
            }
            obj.style.left=obj.offsetLeft+stop+'px';
        },30);
      }
      var div=document.querySelector(".box");
      var span=document.querySelector(".span");
      var ca=document.querySelector(".ca");
      animate(div,100);
      animate(span,100);
      ca.addEventListener("click",function() {
          animate(ca,200);
      })

5、常见网页特效案例

轮播图

节流阀

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值