jQuery dynamic Background image effect implementation method
- 2020-07-21 06:41:53
- OfStack
This paper describes the jQuery dynamic background image effect implementation method. Share to everybody for everybody reference. The details are as follows:
Here, place the background images in the directory as 1.jpg-20.jpg, and jQuery will randomly call these images as the background
$(document).ready(function(){
bgImageTotal=20;
randomNumber = Math.round(Math.random()*(bgImageTotal-1))+1;
imgPath=('/my/image/path/'+randomNumber+'.jpg');
$('h1').css('background-image', ('url("'+imgPath+'")'));
});
Hopefully, this article has been helpful in your jquery programming.