You can travel while the H1B is pending. But, remember that when you are on F1 status in USA and file H1B, it is normally filed with automatic ‘Change of status’.
Travel will abandon H1B change of status
If you travel while your H1B is still pending, the request to change status will be abandoned.
This means that, when you are back in USA on F1 and H1B approved later, you will have to travel outside USA again to get H1B stamped in your passport.
This is simply because you abandoned your H1B change of status application when you went out of USA.