Prakash Mondal

Prakash Mondal

  • NA
  • 288
  • 200.3k

How to autorotate image like a slider inonly javascript,CSS?

Mar 30 2014 1:55 PM
How to autorotate image like a slider in only javascript and CSS without using JQuery???

I try this code... But doesn't work...

<html>
<head>
<title> Auto Change Background Color </title>
<style type="text/css">
div
{
height:320px;
width:100%;
}
</style>
<script type = "text/javascript">
var image = new Array ('pic-1.jpg', 'pic-2.jpg', 'pic-3.jpg', 'pic-10.jpg','pic-11.jpg');

var image_index = 0;
function ChangeBgImage ()
 {
alert(image[image_index]);
  document.getElementById("ddiv").style.backgroundImage="url(image[image_index])";
  image_index++;
  if (image.length == image_index)
  {
  image_index = 0; 
  } 
}
setInterval( "ChangeBgImage()", 1000);
</script>
</head>
<body>
<div id="ddiv">
</div>
</body>
</html>

Please help me..............