Git Product home page Git Product logo

tween.js's Introduction

tween.js

Plain javascript easing functions, 纯js缓动函数, 利用数学函数的坐标变换自定义缓动函数    

很多人不理解为什么可以只接受一个参数t,单变量的思路是把所有的求y值的增加看作是0到1的过程,x的增加的也是0到1的过程,再用图形坐标变换得到相应的函数公式  

在线 Demo

Usage 使用方法

参考 demo.html

<script src="tween.min.js"></script>
        $(function () {
            $('.content img').click(function () {
                var This = $(this);
                var s = This.parents('.content').width(),
                    easing = This.attr('id').replace('_ball', ''),
                    timeNow = 0;
                // 运动
                var move = function () {
                    var f_t = tween[easing](timeNow) * s;
                    if (timeNow <= 1) {
                        This.css('webkitTransform', 'translate3d(' + f_t + 'px, 0, 0)');
                        timeNow += 0.02; // 时间增加
                        requestAnimationFrame(move);
                    } else {
                        This.css('webkitTransform', 'translate3d(' + s + 'px, 0, 0)');
                    }
                }
                move();
            });

        });

Easing 缓动函数图像参考

easings.net

tween.js's People

Contributors

nelsonkuang avatar

Watchers

James Cloos avatar Check Cool avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.