为什么 MooTools 在创建 Fx.Slide 实例时删除边距?
我有一个带有 CSS 规则 margin: 0 auto;
的
,必要时我使用 MooTools 来滑动它。看来仅仅实例化一个 Fx.Slide
对象就会删除我元素上的边距。 也就是说,虽然该元素过去在其父元素内部居中,但现在是左对齐的。 仅这一行似乎就可以做到这一点:
var slide = new Fx.Slide('mydiv');
我可以通过做这样的事情来抵消这种影响:
var slide = new Fx.Slide('mydiv');
$('mydiv').setStyle('margin', '0 auto');
但这很粗糙,我当然不想每次遇到这种情况时都必须这样做。 更重要的是,我想知道,为什么MooTools 首先要删除边距? 是否有一个我不知道的选项,一些我忽略的参数? 请告诉我,因为我是 MooTools 的新手。 虽然我很快发现它的应用程序远远高于 jQuery(至少对于我的目的而言),但我发现它的文档比它的语法要简洁得多。
I have a <div>
with the CSS rule margin: 0 auto;
and I'm using MooTools to slide it when necessary.
It seems that the mere instantiation of an Fx.Slide
object removes the margin on my element. That is, whereas the element used to be centered inside its parent, it is now left-aligned. Just this line alone seems to do this:
var slide = new Fx.Slide('mydiv');
I can counteract this effect by doing something like this:
var slide = new Fx.Slide('mydiv');
$('mydiv').setStyle('margin', '0 auto');
But this is crude and I certainly don't want to have to do this every time I come across this situation. And even more so, I want to know, why does MooTools remove the margin in the first place? Is there an option I don't know about, some parameter I've neglected? Please let me know, as I'm new to MooTools. While I'm quickly finding that its applications are far and above those of jQuery (at least for my purposes), I'm finding that its documentation is much less verbose than its syntax.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
来自
Fx.Slide.js
:如您所见,
Fx.Slide
接受您应用于它的元素 (this.element
),包装它位于包装 div (this.wrapper
) 中,并带有overflow: hide
以及元素的margin
和position
然后删除元素的margin
。因此,删除
边距
是设计使然。 我不明白的是为什么边距没有转移到包装纸上。 您可能有一些 CSS 修改了使用!important
的父元素中的纯 DIV,并阻止Fx.Slide
正确传输属性。您是否将 MooTools 1.2.3 与最新版本的 MooTools More (1.2.3.1) 一起使用?
此外,为了使
Fx.Slide
正常工作,您的页面需要处于标准模式。 您是否将 XHTML 或 HTML(严格或过渡)文档类型作为标记中的第一件事? (没有 XML 序言)。 最坏的情况,如果仍然不起作用,请使用以下内容:MooTools 是一个很棒的 JavaScript 框架我个人认为 它比 jQuery 更强大(不包括 jQuery 拥有庞大社区的事实)。 不幸的是,More 包(相当于 jQuery 的插件)在某些方面缺乏一致性。
From
Fx.Slide.js
:As you can see,
Fx.Slide
takes the element (this.element
) you apply to it, wraps it in a wrapper div (this.wrapper
) withoverflow: hidden
and themargin
andposition
of the element and then removes themargin
of the element.So removing the
margin
is by design. What I do not understand is why the margin is not transferred to the wrapper. You might have some CSS modifying plain DIVs in the parent element that is using!important
and is preventingFx.Slide
from transferring the properties properly.Are you using MooTools 1.2.3 with the latest version of MooTools More (1.2.3.1)?
Also, for
Fx.Slide
to work properly, your page needs to be in standards mode. Do you have an XHTML or HTML (Strict Or Transitional) doctype as the first thing in your markup? (No XML prolog). Worst case, if it still doesn't work, use the following:MooTools is great JavaScript framework to work with and I personally feel that it is way more powerful than jQuery (excluding the fact that jQuery has a huge community). Unfortunately, the
More
package (which is the equivalent of jQuery's plugins) consistency is somewhat lacking in some aspects.