Improve shake animation case

shake if and only if the direction is changed or back from expanded
status.