如何使用Backbone进行简单的动画制作?

时间:2014-06-29 23:34:41

标签: javascript backbone.js

我的Web应用程序中有3个简单的动画,我没有点击服务器,也不需要保存页面状态。

它们是一个简单的下拉菜单,一个页面翻转器和一个窗格翻板,它基本上是页面中的一个小页面。

我可以在Backbone中对这些进行建模。相反,我应该在主干中建模吗?

以下是我的页面翻转器示例:

/***************************************************************************************************
*/
    var Page = $A.Class.create('public', {
        Name: 'Page',

        // (P)roperties
        P: {
            page_previous:  null,
            head_previous:  null
        },

        // (Css) Classes
        C: {
            visible:        'inline',
            invisible:      'none'
        },

        // (E)lements
        E: {

            // body types
            body_splash:     '#body_splash',
            body_main:       '#body_main',
            body_settings:   '#body_settings',

            // heading types
            heading_splash:  '#heading_splash',
            heading_main:    '#heading_main'
        },

        // main, splash, settings
        flip : function (input) {
            var page_current,
                head_current;

            if (!input) {
                input = 'splash';
            }
            if (input === 'main') {
                $A.Event.trigger('main_flipped');
            }

            // set page and header based on input - update this later
            page_current =  this.E['body_' + input];

            if (input === 'settings') {
                head_current =  this.E.heading_main;
            } else {
                head_current = this.E['heading_' + input];
            }

            $A(page_current).fade();
            head_current.style.display = 'inline';

            // Turn off previous page / header
            if (this.P.page_previous !== null && this.P.page_previous !== page_current) {
                this.P.page_previous.style.display = 'none';
            }
            if (this.P.head_previous !== null && this.P.head_previous !== head_current) {
                this.P.head_previous.style.display = 'none';
            }

            // Update previous page / header
            this.P.page_previous = page_current;
            this.P.head_previous = head_current;
        }
    });

1 个答案:

答案 0 :(得分:0)

你可以使用骨干来完成这些事情。marionette。在这个github repo中,您可以找到下拉菜单和页面翻页的一些示例。

相关问题