Attach callbacks when an element is visible or invisible