Home  >  Article  >  Web Front-end  >  jQuery动态背景图片效果实现方法_jquery

jQuery动态背景图片效果实现方法_jquery

WBOY
WBOYOriginal
2016-05-16 15:51:291799browse

本文实例讲述了jQuery动态背景图片效果实现方法。分享给大家供大家参考。具体如下:

这里把背景图片按照1.jpg - 20.jpg放到目录里,jQuery会随机调用这些图片作为背景

$(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+'")'));
});

希望本文所述对大家的jquery程序设计有所帮助。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn