gpt4 book ai didi

javascript - MooTools 垂直对齐插件功能

转载 作者:行者123 更新时间:2023-11-28 01:14:30 26 4
gpt4 key购买 nike

如何在 MooTools 中编写一个可以在一组元素上调用的插件函数(类?),以便垂直对齐它们?我有一个用于 jQuery 的类似函数,它看起来像这样:

  $.fn.vAlign = function() {
return this.each(function() {
var ah = $(this).height();
var ph = $(this).parent().height();
var mh = (ph - ah) / 2;
$(this).css('margin-top', mh);
});
};

我有点不知道如何在 MooTools 中做类似的事情。是建议的创建类的正确方法here ?这似乎并不是对 jQuery 的改进,而且这种方法似乎有些问题。有谁知道解决这个问题的正确方法吗?

最佳答案

根据 Tim Wienk 在 IRC 和 Github 上获得的信息,以下是 MooTools 版本的实际示例:

Element.implement('vAlign', function () {
var ah = this.getSize().y;
var ph = this.getParent().getSize().y;
var mh = (ph - ah) / 2;
this.setStyle('margin-top', mh);
});

$$('div').vAlign();

在线示例:http://jsfiddle.net/bTcb8/

关于javascript - MooTools 垂直对齐插件功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23999863/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com