Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums CSS Random hover on page load Reply To: Random hover on page load

#263095
Beverleyh
Participant

You could use the mt_rand() function in PHP to generate a random number each page load. Just name your hover images 1.jpg, 2.jpg, 3.jpg, etc. and do something like this https://codepen.io/anon/pen/ooQxwy

Note that the PHP code won’t run in CodePen but copy and paste that into your web page and you’ll see the random number loading at the top. The same logic is applied below in the img src. The sample assumes you have 5 images, named sequentially, each with the .jpg extension.