Molecules are constantly in motion. Temperture is, simply, a measure of the energy in this motion. You feel warm on a summer day because the air is warm; i.e., the air molecules are running around rapidly and crashing into your skin, sharing their energy and making your skin molecules jiggle faster -- that is, move to a higher temperture.
Now, the energy is shared equally among any large collection molecules. Imagine a billiard table with bowling balls and ping pong balls as well as billiard balls. If you hit the cue ball toward the others and they scatter, the bowling balls will move very slowly, the billiard balls roll at an intermediate speed, and the ping pong balls just fly off the table at high speed. The energy in the cue ball has been shared equally, but the rate at which each ball moves depends on its mass; the heavy things move slowly and the light ones move rapidly (since E = 1/2 mv2, higher m means lower v).
The same is true in the molecules of air or water -- the more massive the molecule, the slower it moves at any given temperature. Thus, the water molecules that contain two hydrogen atoms and one 16O move more rapidly than the water that has two H's and an 18O (which is 18/16 = 12% heavier). When water molecules near the surface of the ocean are jockeying to see which will break free and evaporate into the air, the fast-moving ones have a significant advantage. Thus, the water vapor that ascends to the clouds -- and then eventually falls as snow on the glaciers -- has an overrepresentation of 16O relative to 18O.
Now, to oversimplify the story somewhat [WHY?], if the Earth's temperature rises, all the molecules in the ocean speed up. This makes it easier for some of the 18O-containing water to also break free and join the clouds...and then the ice. The greater the concentration of 18O in the glacial ice, the warmer the temperature at the time of its evaporation. Thus, the 18O concentration acts as a thermometer, providing the history of Earth's temperature over hundreds of thousands of years.