简体   繁体   English

在对象文字中的元素缓存中使用find()的语法

[英]Syntax for using find() in caching elements in an object literal

Whats the correct syntax for defining $item: ? 定义$item:的正确语法是什么?

So far I have: 到目前为止,我有:

var Animations = {

    el: {
        $body:      $('html, body'),
        $landing:       $('.landing'),
        $item:      $landing.find($('.item'))
    },

    init: function() { ..etc }
}

I've tried using this and Animations.el.//element// but cannot read property. 我尝试使用thisAnimations.el.//element//但无法读取属性。

You cannot refer to a member of an object literal within an object literal (because its not fully constructed at the point you attempt to do so), here: 您不能在对象文字中引用对象文字的成员(因为在您尝试这样做时它没有完全构造),请在此处进行:

$item: $landing.find($('.item'))

$landing is undefined. $landing是未定义的。

Assign to $item in your init() method. 在您的init()方法中分配给$item

init: function() { 
    this.el.$item = this.el.$landing.find($('.item'));
}

Try use this: 试试这个:

(...)
$item: this.Animations.el.$landing.find($('.item'))
(...)

Write it outside initialization 在初始化外写

var Animations = {
    el: {}
};

Animations.el.$body = $('html, body');
Animations.el.$landing = $('.landing');
Animations.el.$item = Animations.el.$landing.find($('.item'));
Animations.init = function() { ..etc }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM