javascript - Simplest BACKGROUND SCREEN ON-CLICK PICTURE CHANGE malfunction -


hey have found , adapted best simple script onclick background image change. works dream - highly recommended, reason cannot solve background picture rotation stops.

it works fine 2 pictures, when added second 'function updateindex' add more pictures shows onclick following jpeg sequence: 100 - 101 - 102 - 100.. once goes first picture onclick doesn't work anymore.

i able ad many pictures want picture rotation line up.

any appreciated.

<!doctype html> <html>  <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <title>index</title> <style type="text/css">    html, body, #body { height: 100%; width: 100%; overflow-y: hidden; overflow-x: hidden; -webkit-background-size: cover no-repeat left top fixed; -moz-background-size: cover; -o-background-size: cover; background-size: cover; margin-top: 0px; margin-left: 0px;  }   #body.imageone { background-image: url("100.jpg"); } #body.imagetwo { background-image: url("101.jpg"); } #body.imagethree { background-image: url("102.jpg"); } #body.imagefour { background-image: url("103.jpg"); } #body.imagefive { background-image: url("104.jpg"); } #body.imagesix { background-image: url("105.jpg"); }   </style> </head>  <body>  <div id="body" class="imageone"> </div>     <script type="text/javascript">//<![cdata[   var bodyobj, classname, index; bodyobj = document.getelementbyid('body');    index = 1; classname = [ 'imageone', 'imagetwo', 'imagethree', 'imagefour', 'imagefive', 'imagesix' ];    function updateindex(){ if(index === 0){     index = 1; }else{     index = 0; } 

}

function updateindex(){ if(index === 1){     index = 2; }else{     index = 0; } }    // jpeg picture rotation: 100 - 101 - 102 - (then to) 100 (perfect) stops @ 100 , screen onclick doesnt work anymore! help.   bodyobj.onclick = function(e){ e.currenttarget.classname = classname[index]; updateindex(); }  //]]>    </script>  </body>  </html> 

change updateindex() function follows:

function updateindex() {     index = (index + 1) % classname.length; } 

Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -