Happiness and sadness can actually be infectious. As Fox News reports studies from Harvard University. The study featured a sample of 1801 people. They monitored the feelings of the person at each visit by the people that they came in contact with.
When it came to being content it was less "contagious" but once "caught" the effects lasted longer than discontent. Discontent was easier to "catch" and easier to shake off.
So, when you are with someone who is unhappy or happy their feelings can literally rub off on you. Sometimes it's just a matter of events in their life but other times it's the people that surround them.
"While emotions can be contagious like disease, they also show that they can result from one’s own life events, rather than just being contagious."
