[英]MooTools Fx.Slide throwing this.element is null
The following code is throwing the error "this.element is null". 以下代码引发错误“ this.element为null”。 However, the wid_cont is definitely grabbing an element.
但是,wid_cont肯定在抓取元素。
window.addEvent('domready',function(){
var min = $(document.body).getElements('a.widget_minimize');
min.addEvent('click',
function(event){
event.stop();
//var box = ;
var wid_cont = ($(this).getParents('.widget_box').getElement('.widget_box_content_cont'));
var myVerticalSlide = new Fx.Slide(wid_cont);
myVerticalSlide.slideOut();
}
);
});
It's moo tools 1.2.4 and has the fx.slide included.... 它是moo工具1.2.4,并包含fx.slide。
it does not return a single element but an array due to getParents()
and possible other similarly marked up elements, Fx.Slide requires you pass it a single element. 它不会返回单个元素,而是会返回一个数组(由于
getParents()
以及其他可能带有类似标记的元素),Fx.Slide要求您将单个元素传递给它。
here it is at least partially working when passing first item of the array: http://www.jsfiddle.net/KFdnG/ 在传递数组的第一项时,它至少部分起作用: http : //www.jsfiddle.net/KFdnG/
however, this is imo ineffective and difficult to manage if you have a long list of items and need a particular content layer to unfold only, you want to keep the lookup to the content layer more local. 但是,如果您有很长的项目列表,并且只需要显示特定的内容层,并且希望将对内容层的查找保持在本地,则imo无效并且难以管理。
something like this: http://www.jsfiddle.net/KFdnG/4/ 像这样的东西: http : //www.jsfiddle.net/KFdnG/4/
// store an instance into each content div and set initial state to hidden.
$$("div.widget_box_content_cont").each(function(el) {
el.store("fxslide", new Fx.Slide(el).hide());
});
$$('a.widget_minimize').addEvent('click', function(event) {
event.stop();
// can't use this.getNext() due to wrapper by Fx.Slide which does not have the instance.
this.getParent().getElement("div.widget_box_content_cont").retrieve("fxslide").toggle();
});
which works on the markup of: 它适用于以下标记:
<div class="widget_box">
<div class="widget_box_content">
<a href="#" class="widget_minimize">link</a>
<div class="widget_box_content_cont">
some content
</div>
</div>
<div class="widget_box_content">
<a href="#" class="widget_minimize">link 2</a>
<div class="widget_box_content_cont">
some content 2
</div>
</div>
</div>
this is also better as you won't be making a new instance of the Fx.Slide class on every click but will reference the ones already attached to the element. 这样也更好,因为您不会在每次单击时都创建Fx.Slide类的新实例,而是将引用已附加到该元素的实例。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.