Transient mechanics of foams and emulsions