In the case of a Cepheid or RR Lyrae variable, it is only the envelope which expands and contracts. As the envelope expands and contracts, its surface temperature varies by as much as 1000 degrees Kelvin. The textbook has a rather involved description involving the properties of a layer of ionized helium in the star's envelope. Photons are trapped inside, heating the gas and increasing its pressure. The high-pressure gas expands, becoming transparent.
Photons escape, the gas cools, the pressure drops.
As the pressure drops, the Cepheid is compressed by gravity. The greater the luminosity of a Cepheid star, the longer its period of oscillation. It was discovered empirically in 1916, by the Harvard astronomer Henrietta Leavitt, that a Cepheid's period of pulsation is linked to its luminosity. This relation holds true in our own galaxy too, and in all other galaxies where Cepheid variables have been detected. High Luminosity, Long Period.