17 Visual Effects for Ruby on Rails RJS functions
Posted by Lars | Posted in Rails, Ruby, Tutorials | Posted on 01-06-2009
6
Ruby on Rails has a scriptaculous framework integration out of the box. The Rails helper functions are very powerful, but every time i need a visual_effect i have to search in API docs to get all Rails supported scriptaculous effects.
To shorten the search i’m going to list all 17 supported effects.
Effects for appearing
This effects make sence after AJAX create or show functions. They add the new content effectfully after your record is created or replace a list entry with a detail entry after show function.
- Appear - Fades in the selected DIV.
- BlindDown - Fades in the selected DIV from top to bottom.
- SlidesDown - Slides in the selected DIV from top to bottom.
- Grow - Fades and zoomes in the selected DIV.
Effects for disappearing
This effects you can use to remove a DIV after a destroy function was executed successfully.
- Fade - Fades out the selected DIV
- Puff - Fades out and zoomes out the selected DIV
- Blind up - Fades out from bottom to top side of selected DIV
- SwitchOff - Flash Up and fade out
- SlideUp - Moves the DIV from bottom to top
- DropOut - Fades and moves out to bottom.
- Squish - Minimizes the DIV to left top corner.
- Fold - Foldes the DIV first to top second to left.
- Shrink - Minimize the DIV to center direction.
- Hide - Hides the DIV (thx to Nick)
Effects for highlighting
After AJAX update functions this group of effects makes sence. It catches the attention after a record is updated.
- Shake - Shakes the DIV horizontally.
- Pulsate - Fades out and zoomes out the selected DIV
- Highlight - Highlights the DIV with yellow flashing.
How to use in views
Use the effects in following way in your views:
1 2 3 4 5 | <%= link_to_remote("Destroy", :url => item_path(item), :complete => visual_effect(:Fade,"item_box_#{item.id}"), :method => :delete) %> |
Have fun.











be better off using some unobtrusive javascript, like jQuery.
Yes you can. But using standard rails functions works for me very well. In most of my use cases there is no reason to add more javascript libraries.
Thanks Lars. good to have it all in one place.
I would have added Hide to the disappear list. I found this one particularly useful when promoting elements out of a list to a “selected” list.
Hi Nick, I added the Hide Effect to disappear list. Thx for your contribution.
Kind regards
Lars
Big ThNX!
Do you know how to make pause btw effects? E.g. I want to hide block and only after full hide make shrink or some other actions.