Jump to content
  • 0

Смена изображения анимации


raiden
 Share

Question

Добрый день. Скрипт работает в браузерах хром и фаерфокс (скрипт меняет картинку), а в IE и Opera не работает, где же ошибка в коде? Помогите исправить код. Знаю что код не ахти

Вот сам скрипт

<span id="passpss"></span>
<div id="myimg" class="k"></div>
<div id="myimga" class="z"></div>

<!--//</div>//-->

<script type="text/javascript">
function updateData() {
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET","test.xml",false);
xmlhttp.onreadystatechange = function (){
xmlDoc=xmlhttp.responseXML;

document.getElementById("myimg").innerHTML=$(xmlDo c).find('#1-222-1-25-0').find('Status').text();
document.getElementById("myimga").innerHTML=$(xmlD oc).find('#1-222-1-26-0').find('Status').text();
document.getElementById("passpss").innerHTML=$(xml Doc).find('#1-222-1-27-0').find('Status').text();

var y = parseFloat(document.getElementById("myimg").innerH TML);
var i = document.getElementById('myimg');
img1 = new Image (20,20);

switch (y){
case 1: img1.src="green.gif";break;
case 2: img1.src="red.gif";break;
case 0: img1.src="red.gif";
}

i.appendChild(img1);

var z = parseFloat(document.getElementById("myimga").inner HTML);
var i = document.getElementById('myimga');
img2 = new Image (20,20);

switch (z){
case 1: img2.src="green.gif";break;
case 2: img2.src="red.gif";break;
case 0: img2.src="red.gif";
}

i.appendChild(img2);


}
xmlhttp.send();


}
</script>


<script type="text/javascript">
$(document).ready(function(){
updateData();
setInterval('updateData()',5000);
});
</script>

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0

Я не давно делал скрипт, который меняет картинку. Крутит баннеры каждые N секунд времени.

В общем если будет полезно:

 

HTML

<div id="bannerRoller"><img src="#" width="800" height="133"  alt="Первая картинка"/><img src="#" width="800" height="133"  alt="Вторая картинка"/><img src="#" width="800" height="133"  alt="Третья картинка"/></div>

JS

 var element;   window.onload = function() {    bannerScroll(); //banner roller   }      function bannerScroll() {    var TIME = 7000; //time in ms between banner changing     var ID = "bannerRoller"; //id of banner wrapper        var element = document.getElementById(ID);    var images = element.getElementsByTagName("img");    var start = 0;    var current = start;    var last = images.length-1;    var status=0;    //Loading first element    images[start].style.display="block";    current++;        //banner changing    if (images.length==1) { return; } else {      setInterval(function() {      if (current==start) {       images[last].style.display="none";       images[current].style.display="block";       current++;      } else      if (current<last) {       images[current-1].style.display="none";       images[current++].style.display="block";      } else {       images[current-1].style.display="none";       images[current].style.display="block";       current=start;      }     }, TIME);    }   }
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. See more about our Guidelines and Privacy Policy