when feeling sad 这是带连词when 的分词短语作时间状语的,等于When you feel sad.
再如:
Be careful when crossing the road.
过马路时要小心