你能在Rails RJS中将replace_html与视觉效果结合起来吗?
我正在使用 Ruby on Rails 开发一个网站,并且有一个包含一些内容的 div。 单击链接后,我希望该内容被其他内容替换。 这对于replace_html 和rjs 来说效果很好。
但是,我希望新旧内容之间有轻微的淡入淡出/出现(交叉淡入淡出?)过渡。 此外,div 的大小也会稍微调整,因此如果具有增长/收缩效果,效果会更酷。 我想 Scriptaculous 一定内置了类似的东西,但如果他们这样做的话我肯定找不到它。
顺便说一句,如果您有 Basecamp 帐户,有一个很好的例子:登录并单击“所有人”,然后单击“添加新公司”以查看实际效果。
有人知道怎么做吗? 谢谢! 布莱恩
I'm developing a website with Ruby on Rails and I have a div with some content. After clicking a link I want that content to get replaced with some other stuff. This works fine with replace_html and rjs.
However, I'd prefer there to be a slight fade/appear (crossfade?) transition between the old and new content. Also the div will be resized a bit so it'd be cooler if this did a grow/shrink effect. I was thinking Scriptaculous must have something like this built in, but I sure can't find it if they do.
By the way there is a great example of this if you have a Basecamp account: login and click "All people" then "Add a new company" to see the effect in action.
Anyone know how to do this? Thanks!
Brian
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
要交叉淡入淡出,您需要绝对定位新内容,并使用与旧内容相同的 x/y 坐标。 这是一个经过测试的示例:
请注意中间的大块 — 有些事情在 Prototype 中比在 RJS 中更容易。
To crossfade, you need to position your new content absolutely, and with the same x/y coordinates as the old content. Here's a tested example:
Note the big block in the middle—some things are easier in Prototype than in RJS.
一种策略可能是将元素放入包装 div 中,淡出该包装 div,替换元素中的 HTML,然后再次淡入包装 div。
我自己不是 RJS/scriptaculous 用户,所以我不确定代码是什么,但我很确定该策略会起作用。
A strategy could be to put the element in a wrapping div, fade out that wrapping div, replace the HTML in the element, and then fade in the wrapping div again.
I'm not a RJS/scriptaculous user myself, so I'm not sure what the code is, but I'm pretty sure that strategy will work.
淡出第 1 个 div。
同时在第二格盲。
当第一个消失时,第二个似乎会扩展第一个的剩余部分。
嗯,类似的事情。
如果您想查看它们调用的内容,请加载 Firebug 并单步执行代码。
Fade out the 1st div.
Blind in the 2nd div at the same time.
As the 1st one fades, the 2nd will appear to expand what's left of the first one.
Well, something like that.
Load up Firebug and step through the code if you want to see what they're calling.
一种快速的方法是进行替换,然后对 div 进行脉动。
One quick way would be to do the replace and then pulsate the div.