如何随机旋转图像javascript?
如何在不使用 setTimeout 刷新页面的情况下随机旋转图像?
js:
var bannerImages = new Array( );
bannerImages[0] = "Banner1.jpg";
bannerImages[1] = "Banner2.jpg";
bannerImages[2] = "Banner3.jpg";
bannerImages[3] = "Banner4.jpg";
var randomImageIndex = Math.round( Math.random( ) * 3 );
document.write( "<img alt=\"\" src=\"imgs/" + bannerImages[randomImageIndex] + "\">" );
`
how do i randomly rotate the images without refreshing the page with setTimeout??
js:
var bannerImages = new Array( );
bannerImages[0] = "Banner1.jpg";
bannerImages[1] = "Banner2.jpg";
bannerImages[2] = "Banner3.jpg";
bannerImages[3] = "Banner4.jpg";
var randomImageIndex = Math.round( Math.random( ) * 3 );
document.write( "<img alt=\"\" src=\"imgs/" + bannerImages[randomImageIndex] + "\">" );
`
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只需更改图像的 src 属性:
尝试一下: http://jsfiddle.net/A3v8w/
Just change the src attribute of the image:
Try it: http://jsfiddle.net/A3v8w/
使用JqueryRotate插件,我们可以轻松做到这一点更顺利,只有 1 个图像
例如 -
http://jsfiddle.net/ 73pXD/
参考:jquery-plug-in & 此处的代码 。
Using JqueryRotate plugin, we can do it easily & more smoothly, with only 1 image
For e.g-
http://jsfiddle.net/73pXD/
Ref: jquery-plug-in & codes here .