使用mootools Fx修改div的缩放
我有一个案例,我想为 div (及其整个内容)的缩放样式设置动画。易读性不是问题,因为这会将元素“弹出”到视图中。现在我可以使用 Fx 获得几乎所有其他风格方面的动画,但我似乎无法在缩放时使用它。
这是在 Chrome 中(尽管显然我也想让它与浏览器无关)。
使用 Chrome 开发工具中的“元素”选项卡,我可以手动设置 html 元素的缩放样式,并且它会做出相应的行为,所以我知道一定可以在代码中进行修改。使用此问题的答案:zoom css/javascript 我可以使用代码来放大和缩小元素:
dialog.setStyle('WebkitTransform', 'scale(0.1)')
现在我可以编写一个“本机”函数来执行此操作,但这样我就会失去 Fx 中所有出色的动画选项。谁能建议一种使用 Fx 实现这一目标的优雅方法?
I have a case where I'd like to animate the zoom style of a div (and it's entire contents). Legibility is not an issue, as this will be to 'pop' the element into view. Now I can get just about every other style aspect animating with Fx, but I can't seem to get this working for the zoom.
This is in chrome (though obviously I want to get it browser agnostic as well).
Using the Elements tab in the Chrome dev tools I can manually set the zoom style on the html element and it behaves accordingly, so I knew it must be possible to modify in code. Using the answer on this question: zoom css/javascript
I can get the element to zoom in and out with code:
dialog.setStyle('WebkitTransform', 'scale(0.1)')
Now I could write a 'native' function to do this, but then I'd lose out on all the great animation options in Fx. Can anyone suggest an elegent way to achieve this with Fx?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,您需要破解 mootools 核心中的一些 CSS 解析器才能使 FX 能够使用它们。
检查这个有趣的例子,我不久前为另一个SO问题做过: http://jsfiddle.net/dimitar/ZwMUH/ - 单击任意 2 个图标来交换它们,它将通过缩放来转换它们。
或者我编写的这个灯箱基类也使用它: http://jsfiddle.net/dimitar/6creP/< /a>
从根本上讲,首先修改解析器:
同样相关,跨浏览器定义所有样式的公共和脚本版本:
检测方法将循环遍历上面定义的转换并返回元素支持的第一个作为最终属性去工作将来使用,或者如果不可用,则将不透明度作为后备:
然后
this.prop
将引用正确的浏览器属性、供应商前缀或不透明度作为补间/变形的后备,而this.scaleTransform 将是一个布尔值,指向缩放能力 - 然后您可以检查它以查看在创建变形对象时是否支持它。
对象本身是这样的:
还有其他解决方案,例如这个插件 http://mootools.net/forge /p/fx_tween_css3,我知道还有 Theiry Bela 的一个:https://github.com/tbela99/Fx.css
它也将在 mootools 2.0 中原生提供,
玩得开心。
yes, you need to hack some of the CSS parsers in the mootools core to enable FX to work with them.
check this fun example I did a while back for another SO problem: http://jsfiddle.net/dimitar/ZwMUH/ - click on any 2 icons to swap them and it will transition them via scale.
or this light box base class I wrote that also uses it: http://jsfiddle.net/dimitar/6creP/
at its basic, start by modding the parsers:
also relevant, define public and scripting vers of all styles cross browser:
detection method which will loop through the transforms defined above and return the first one that the element supports as the definitive property to work with in the future, or opacity as fallback if unavailable:
then
this.prop
will refer to the correct browser property, vendor prefixed or opacity as fallback for tweening/morphing whereasthis.scaleTransform
will be a boolean that points to the ability to scale - you can then check against that to see if its supported when you are creating the morph object.The object itself would be like this:
other solutions are available such as this plugin http://mootools.net/forge/p/fx_tween_css3, there's also one by Theiry Bela I know of: https://github.com/tbela99/Fx.css
its also going to be natively available in mootools 2.0
have fun.