Mootools 类创建

发布于 2024-11-06 02:26:12 字数 1414 浏览 0 评论 0原文

我将此内联代码硬编码到页面中,但我希望能够将其放入 mootools 类中?我已经按照 david.walsh 博客上的示例进行操作,但我仍然感到困惑。

代码的第一部分创建了一个弹出窗口:

items.each(function (d, i) {
if (i % maxPerPage === 0) {
// create new page
page = new Element('div', {'class':'page'}).inject(view);
navButtons = new Element('ul', {'class':'nav-buttons'}).inject(page);
page.set('tween', {unit:'%',duration:300,transition:Fx.Transitions.Quart.easeIn});

if (i === 0) {
view.set('currentPage', 0);

switch (d.type) {
case 'correct':
var overlayWrapper = new Element('div', {'id':'overlay-wrapper'}),
overlayContent = new Element('div', {'id':'overlay-content'}).inject(overlayWrapper, 'top'),
overlayCheck = new Element('div', {'id':'close-overlay', 'class':'pngscale tween ', 'fku_bg':'trophies/icons/check-100.png'}).inject(view, 'bottom');

overlayWrapper.inject(mc, 'before');
break; 

第二部分创建了弹出窗口内容(背景图像和弹出窗口内的文本):

var li = new Element('li', {'class':'button pngscale', 'id':'item_' + i});
var container = new Element('div', {'class':'button-container pngscale'}).inject(li);

switch (d.type) {
case 'correct':
li.set('imgCatDOG.png'].join('') );
new Element ('h1', {'class':'text'}).set('text', d.content).inject(li);
new Element ('div',{'class': 'text2', 'imgBGpopup }).inject(li);
break; 

这是从中提供内容的 json:

var popup = [
{
'type': 'correct',
'content': 'that is right!'

}

I have this inline code hard coded into the page but i want to be able to make it into a mootools class? i've followed the examples at david.walsh blog but im still confused.

This first part of the code created a popup:

items.each(function (d, i) {
if (i % maxPerPage === 0) {
// create new page
page = new Element('div', {'class':'page'}).inject(view);
navButtons = new Element('ul', {'class':'nav-buttons'}).inject(page);
page.set('tween', {unit:'%',duration:300,transition:Fx.Transitions.Quart.easeIn});

if (i === 0) {
view.set('currentPage', 0);

switch (d.type) {
case 'correct':
var overlayWrapper = new Element('div', {'id':'overlay-wrapper'}),
overlayContent = new Element('div', {'id':'overlay-content'}).inject(overlayWrapper, 'top'),
overlayCheck = new Element('div', {'id':'close-overlay', 'class':'pngscale tween ', 'fku_bg':'trophies/icons/check-100.png'}).inject(view, 'bottom');

overlayWrapper.inject(mc, 'before');
break; 

This second part created the popup content(background image, and text inside the popup):

var li = new Element('li', {'class':'button pngscale', 'id':'item_' + i});
var container = new Element('div', {'class':'button-container pngscale'}).inject(li);

switch (d.type) {
case 'correct':
li.set('imgCatDOG.png'].join('') );
new Element ('h1', {'class':'text'}).set('text', d.content).inject(li);
new Element ('div',{'class': 'text2', 'imgBGpopup }).inject(li);
break; 

This is the json from which the content is being fed:

var popup = [
{
'type': 'correct',
'content': 'that is right!'

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情绪 2024-11-13 02:26:12

在没有任何上下文和片段的情况下很难判断你在做什么。甚至不知道该类的用途是什么,弹出窗口含糊不清,可能意味着任何内容。

另外,如果您说您按照教程来制作课程,那么您编写的失败代码在哪里?

从非常基本的角度看,这里有一个可以开始使用的线框图:

var myPopup = new Class({

    // mixins to use setOptions merge and class events
    Implements: [Options, Events],

    options: {
        // default options here
        maxPerPage: 4,
        view: null,
        items: []
    },

    initialize: function(options) {
        // constructor
        this.setOptions(options);
        this.items = this.options.items;
        this.view = document.id(this.options.view);

        if (!this.view)
            return; // no element to work with

        this.addPopups();
    },

    addPopups: function() {
        this.items.each(function(el, i) {
            if (i % this.options.maxPerPage === 0) {
                this.page = new Element("div.page", {
                    tween: {
                        unit:'%',
                        duration:300,
                        transition:Fx.
                        Transitions.Quart.easeIn
                    }
                });
                new Element("ul.nav-buttons").inject(this.page);
                this.page.inject(this.view);

                // etc etc.
            }
        }, this); // keep it bound to class instance
    }

});

应该为您提供足够的基础。

也许您可以首先阅读我关于制作 mootools 类并扩展它的教程:

教程 1:构建您的第一个 mootools 类 - 工具提示。
http://fragged.org/tutorial-write -a-small-but-flexible-mootools-tips-class_1293.html

教程 2:构建内容滑块类并扩展它:
http://fragged .org/tutorial-write-a-small-content-slider-class-in-mootools-and-extend-it_1321.html

最后,如果您正在构建我所说的模式框弹出窗口:
http://fragged.org/the-simple-modal-window-via -mootools_232.html - 这不是教程,而是我发布的一个实际插件,但它可能会给您一些关于如何构建类方法、使用事件以及如何扩展它的想法。

祝你好运。

it is VERY difficult to tell what you are doing w/o any context and just fragments. don't even know what the class is meant to do, popup is ambiguous and could mean anything.

also, if you say you followed a tutorial for making a class, where is the code that you wrote that failed for you?

at a very basic look, here's a wireframe to get started:

var myPopup = new Class({

    // mixins to use setOptions merge and class events
    Implements: [Options, Events],

    options: {
        // default options here
        maxPerPage: 4,
        view: null,
        items: []
    },

    initialize: function(options) {
        // constructor
        this.setOptions(options);
        this.items = this.options.items;
        this.view = document.id(this.options.view);

        if (!this.view)
            return; // no element to work with

        this.addPopups();
    },

    addPopups: function() {
        this.items.each(function(el, i) {
            if (i % this.options.maxPerPage === 0) {
                this.page = new Element("div.page", {
                    tween: {
                        unit:'%',
                        duration:300,
                        transition:Fx.
                        Transitions.Quart.easeIn
                    }
                });
                new Element("ul.nav-buttons").inject(this.page);
                this.page.inject(this.view);

                // etc etc.
            }
        }, this); // keep it bound to class instance
    }

});

should give you enough to build upon.

perhaps you could benefit first from reading my tutorials on making a mootools class and extending it:

Tutorial 1: build your first mootools class - tooltips.
http://fragged.org/tutorial-write-a-small-but-flexible-mootools-tips-class_1293.html

Tutorial 2: build a content slider class and extend it:
http://fragged.org/tutorial-write-a-small-content-slider-class-in-mootools-and-extend-it_1321.html

and finally, in case that you are building what I call a modal box popup:
http://fragged.org/the-simple-modal-window-via-mootools_232.html - this is not a tutorial but an actual plugin i released but it may give you some ideas as to how to architect your class methods, use events and how to extend it afterwards.

good luck.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文