我的账户
猩码学苑

专注C++开发菁英教育

亲爱的游客,欢迎!

已有账号,请

如尚未注册?

前端-段童雨-20230522

[复制链接]
Yeeeee 发表于 2023-5-24 17:42:08 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题
一.今日所学

鼠标事件:mouseenter  mouseleave
两种鼠标的区别 :mouseover 存在事件冒泡  mouseenter 不存在事件冒泡
client事件:clientWidth,clientHeight 包括: content + padding
clientLeft 边框的宽度-左边框

scroll事件:scrollWidth,scrollHeight包含content  + padding
如果内容超出了容器的高度,得到的scrollHeight就是内容的真实高度
scrollTop 头部卷去的部分


动画的实现思路:
目的:
知识点的总结应用
函数的封装的应用
动画库的封装 - 写一个函数(实现一个简单的动画)
原理 : 元素本身的偏移量的基础上加1
const div = document.querySelector('div')
        setInterval(function () {
            div.style.left = div.offsetLeft + 1 + 'px'
        }, 30)
动画的实现代码
const div = document.querySelector('div')
        let t1 = setInterval(() => {
            div.style.left = div.offsetLeft + 1 + 'px'
            if (div.offsetLeft >= 500) {
                // alert('over')
                // 停止定时器
                clearInterval(t1)
            }
        }, 15)
动画简单封装
function animate(el, target) {
            let t1 = setInterval(() => {
                el.style.left = el.offsetLeft + 1 + 'px'
                if (el.offsetLeft >= target) {
                    clearInterval(t1)
                }
            }, 15)
        }
使用animate进行封装


缓动动画
function animate(el, target, cb) {
    clearInterval(el.t1)
    el.t1 = setInterval(() => {
        let step = (target - el.offsetLeft) / 10
        console.log(step)
        if (step > 0) {
            step = Math.ceil(step)
        } else {
            step = Math.floor(step)
        }


        el.style.left = el.offsetLeft + step + 'px'
        if (el.offsetLeft == target) {
            clearInterval(el.t1)
            if (cb) {
                cb()
            }
        }
    }, 30)
}





回复

使用道具 举报

关注0

粉丝0

帖子36

发布主题
大家都在学
课堂讨论
一周热帖排行最近7x24小时热帖
关注我们
专注C++菁英教育

客服电话:18009298968

客服时间:9:00-21:00

猩码学苑 - 专注C++开发菁英教育!( 陕ICP备2025058934号-1 )

版权所有 © 陕西菁英数字科技有限公司 2023-2026