0 Star 0 Fork 0

Pan / html5_and_javascript_animation

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README

html5_and_javascript_animation

常用的一些代码

事件创建 检测等

检测是否支持canvas

if (document.createElement('canvas').getContext) {
    console.log('support')
}

requestAnimationFrame在各个游览器版本中的实现

if (!window.requestAnimationFrame) {
    window.requestAnimationFrame = (
        window.webkitRequestAnimationFrame ||
        window.mozRequestAnimationFrame ||
        window.oRequestAnimationFrame ||
        window.msRequestAnimationFrame ||
        function(callback) {
            return window.setTimeout(
                callback,
                1000 / 60 //每秒60帧
            )
        }
    )
}

捕获keydown

textarea.focus()

textarea.addEventListener('keydown', function(event) {
    console.log(event.type)
}, false)

简单的三角函数概念

三角形

正弦 sin : 该角相对的直角边与斜边的比例

余弦 cos : 改角的邻边与斜边的比例

正切 tan : 改角的对边与邻边的比例

反正弦 asin : 正弦的逆运算

反余弦 acos : 余弦的逆运算

反正切 atan : 正切的逆运算

角度和弧度的换算

radian = angle * Math.PI / 180
angle = radian * 180 / Math.PI

通过反三角函数求对应的角度或者弧度

Math.asin(0.5) * 180 / Math.PI //30
Math.sin(30 * Math.PI / 180) //4.999

反三角函数

朝鼠标任意一点旋转

dx = mouse.x - obj.x
dy = mouse.y - obj.y
obj.rotation = Math.atan2(dy, dx) //此处是弧度值 

创建波

function drawFrame() {
    window.requestAnimationFrame(drawFrame, canvas)

    value = cneter + Math.sin(angle) * range
    angle += speed
}

创建圆形

positionX = centerX + Math.cos(angle) * radius
positionY = centerY + Math.sin(angle) * radius
angle += speed

创建椭圆形

positionX = centerX + Math.cos(angle) * radiusX
positionY = centerY + Math.sin(angle) * radiusY
angle += speed

计算两点间距离

dx = x2 - x1
dy = y2 - y1
dist = Math.sqrt(dx * dx + dy * dy)

空文件

简介

暂无描述 展开 收起
JavaScript
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
JavaScript
1
https://gitee.com/codingpan/html5_and_javascript_animation.git
git@gitee.com:codingpan/html5_and_javascript_animation.git
codingpan
html5_and_javascript_animation
html5_and_javascript_animation
master

搜索帮助