zoukankan      html  css  js  c++  java
  • H5动画

    1.参考:http://blog.csdn.net/whqet/article/details/42911059?readlog

    https://developer.mozilla.org/zh-CN/docs/Web/API/Window/requestAnimationFrame

    //兼容性处理
    (function() {
    var lastTime = 0;
    var vendors = ['webkit', 'moz', '-o'];
    for (var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
    window.requestAnimationFrame = window[vendors[x] + 'RequestAnimationFrame'];
    window.cancelAnimationFrame =
    window[vendors[x] + 'CancelAnimationFrame'] || window[vendors[x] + 'CancelRequestAnimationFrame'];
    }

    if (!window.requestAnimationFrame)
    window.requestAnimationFrame = function(callback) {
    var currTime = new Date().getTime();
    var timeToCall = Math.max(0, 16 - (currTime - lastTime));
    var id = window.setTimeout(function() {
    callback();
    },
    timeToCall);
    lastTime = currTime + timeToCall;
    return id;
    };

    if (!window.cancelAnimationFrame)
    window.cancelAnimationFrame = function(id) {
    clearTimeout(id);
    };
    })();


    //业务代码
    (function() {
    var degrees = 0;
    var div1 = document.getElementById("div1");

    function update() {
    div1.style.transform = "rotate(" + (degrees++) + "deg)";
    requestAnimationFrame(update);
    }
    requestAnimationFrame(update);

    var deg = 0;
    var id;
    var div2 = document.getElementById("div2");
    div2.addEventListener('click', function() {
    var self = this;
    requestAnimationFrame(function change() {
    console.log(deg);
    self.style.transform = 'rotate(' + (deg++) + 'deg)';
    id = requestAnimationFrame(change);
    });
    });
    document.getElementById('stop').onclick = function() {
    cancelAnimationFrame(id);
    };

    })();

  • 相关阅读:
    centos 搭建 sftp 服务器
    apt-get 安装时,提示lock被占用
    Kafka
    设计模式-分类
    SparkSQL – 从0到1认识Catalyst
    Spark分布式计算引擎
    Spark存储管理
    Spart RDD
    硬件工程师的你也不想一辈子画图、调板子吧!!!
    如何理解IPD+CMMI+Scrum一体化研发管理解决方案之Scrum篇
  • 原文地址:https://www.cnblogs.com/itdev/p/7791845.html
Copyright © 2011-2022 走看看