为什么 MooTools 在创建 Fx.Slide 实例时删除边距?

发布于 2024-07-30 19:41:54 字数 609 浏览 7 评论 0原文

我有一个带有 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 技术交流群。

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

发布评论

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

评论(1

帅冕 2024-08-06 19:41:54

来自 Fx.Slide.js

Fx.Slide = new Class({

    /* .. */

    initialize: function(element, options){
        this.addEvent('complete', function(){
            this.open = (this.wrapper['offset' + this.layout.capitalize()] != 0);
            if (this.open && Browser.Engine.webkit419) this.element.dispose().inject(this.wrapper);
        }, true);
        this.element = this.subject = document.id(element);
        this.parent(options);
        var wrapper = this.element.retrieve('wrapper');
        this.wrapper = wrapper || new Element('div', {
            styles: $extend(this.element.getStyles('margin', 'position'), {overflow: 'hidden'})
        }).wraps(this.element);
        this.element.store('wrapper', this.wrapper).setStyle('margin', 0);
        this.now = [];
        this.open = true;
    },

    /* .. */

如您所见,Fx.Slide 接受您应用于它的元素 (this.element),包装它位于包装 div (this.wrapper) 中,并带有 overflow: hide 以及元素的 marginposition然后删除元素的margin

因此,删除边距是设计使然。 我不明白的是为什么边距没有转移到包装纸上。 您可能有一些 CSS 修改了使用 !important 的父元素中的纯 DIV,并阻止 Fx.Slide 正确传输属性。

您是否将 MooTools 1.2.3 与最新版本的 MooTools More (1.2.3.1) 一起使用?

此外,为了使 Fx.Slide 正常工作,您的页面需要处于标准模式。 您是否将 XHTML 或 HTML(严格或过渡)文档类型作为标记中的第一件事? (没有 XML 序言)。 最坏的情况,如果仍然不起作用,请使用以下内容:

$('mydiv').getParent().setStyle('margin', '0 auto');

MooTools 是一个很棒的 JavaScript 框架我个人认为 它比 jQuery 更强大(不包括 jQuery 拥有庞大社区的事实)。 不幸的是,More 包(相当于 jQuery 的插件)在某些方面缺乏一致性。

From Fx.Slide.js:

Fx.Slide = new Class({

    /* .. */

    initialize: function(element, options){
        this.addEvent('complete', function(){
            this.open = (this.wrapper['offset' + this.layout.capitalize()] != 0);
            if (this.open && Browser.Engine.webkit419) this.element.dispose().inject(this.wrapper);
        }, true);
        this.element = this.subject = document.id(element);
        this.parent(options);
        var wrapper = this.element.retrieve('wrapper');
        this.wrapper = wrapper || new Element('div', {
            styles: $extend(this.element.getStyles('margin', 'position'), {overflow: 'hidden'})
        }).wraps(this.element);
        this.element.store('wrapper', this.wrapper).setStyle('margin', 0);
        this.now = [];
        this.open = true;
    },

    /* .. */

As you can see, Fx.Slide takes the element (this.element) you apply to it, wraps it in a wrapper div (this.wrapper) with overflow: hidden and the margin and position of the element and then removes the margin 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 preventing Fx.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:

$('mydiv').getParent().setStyle('margin', '0 auto');

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.

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