Can you combine replace_html with a visual_effect in Rails RJS?

∥☆過路亽.° 提交于 2019-12-03 20:18:55

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:

page.insert_html :after, 'old-content', content_tag('p', '[new content]', :id => 'new-content', :style => 'display:none')
page << <<-JS
  var oldOffset = $('old-content').cumulativeOffset();
  $('new-content').setStyle({
    position: 'absolute',
    left:     oldOffset.left + 'px',
    top:      oldOffset.top + 'px'
  });
JS
page['old-content'].fade :duration => 3
page['new-content'].appear :duration => 3

Note the big block in the middle—some things are easier in Prototype than in RJS.

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.

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.

One quick way would be to do the replace and then pulsate the div.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!