Transparent media are transparent because the incoming photon does not match any of the available energy levels to transfer its energy to the atom, or molecule, or crystal.
A classical analogy is thinking of energy levels as various size sieve holes which allow only certain size of particles to go through. Not any matter of knowing or adjusting, but inherent size of the sieve holes.
The energy levels, that the electrons abide in when attached to matter, are specific and defined by the potentials entering the problem. If the photon has the correct frequency, it will interact with the atom/molecule/lattice and the energy it carries will be absorbed by the atom/molecule/lattice and the electron will either be ejected or just go to a higher level of energy and falling back give up a new photon.
The energy is not given up continuously but with the correct quantum increments defined by the matter it hits.
There do exist free electrons and they do interact with photons. In this case a photon may lose its energy in a non quantized manner, increasing the energy of the electron and becoming a photon of lower energy. That is another story.