views:

66

answers:

1

I have a list of items which can be displayed both vertically and horizontally:

http://jsbin.com/olefi3/2

Currently, toggling between these two modes makes for a rather jarring user experience, since items are repositioned rather suddenly (as CSS classes are being applied/removed). It would help greatly to have each item gradually move to its new position, making it easier for users to keep their orientation.

I know jQuery's animate method doesn't work for float. While I can imagine a solution, it seems rather complex:

  • create an invisible clone of each item
  • apply the desired style (vertical/horizontal)
  • record the clones' new position
  • delete the clones
  • animate the actual items to the recorded positions
  • apply the desired style to the actual items
  • remove inline styles from animation

Before I go about reinventing the wheel, does anything like this already exist?

+1  A: 

For starters, you need to include the jqueryui library right after you include the jquery library for the .toggleClass() call to animate at all

<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/jquery-ui.min.js"&gt;&lt;/script&gt;

This gets you closer to what you are looking for.

Good Luck

wowo_999
Do you mean `switchClass`? I'll experiment with that, though I'm not very hopeful. Either way, thanks!
AnC
Yeah, the problem is a float isn't a numerical value, its either floated or not so there isn't really a value to 'keyframe' from based on setting something to float. What you could do, (smoke and mirrors approach) is set the float, get the final position values of the floated elements, then unset the float and use the values as parameters for the animation? I'm curious what you come up with :) Good Luck!
wowo_999
Yeah, that sounds similar to the approach I'd envisaged in the original post - however, I'm concerned it wouldn't be very generic... I've tried, but it's not quite working out: http://jsbin.com/olefi3/4 - also, the code is too horrible to make this worthwhile.
AnC