Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/84.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
幻灯片显示javascript不工作_Javascript_Html_Css - Fatal编程技术网

幻灯片显示javascript不工作

幻灯片显示javascript不工作,javascript,html,css,Javascript,Html,Css,我使用下面的java脚本代码创建带有图像的幻灯片放映 img1.jpg、img1.jpg和img3.jpg。 但它在输出中只显示img1.jpg。请告诉我这个问题 #幻灯片{宽度:310;高度:210;边框样式:实心;} #幻灯片>img{位置:绝对;左侧:15;顶部:15} var计数=2; 函数mf() { document.getElementById(“imge”).src=“img”+count+”.jpg”; document.getElementById(“imge”).heig

我使用下面的java脚本代码创建带有图像的幻灯片放映 img1.jpg、img1.jpg和img3.jpg。 但它在输出中只显示img1.jpg。请告诉我这个问题


#幻灯片{宽度:310;高度:210;边框样式:实心;}
#幻灯片>img{位置:绝对;左侧:15;顶部:15}
var计数=2;
函数mf()
{
document.getElementById(“imge”).src=“img”+count+”.jpg”;
document.getElementById(“imge”).height=“200”;
document.getElementById(“imge”).width=“300”;

如果(count之后需要使用mf()启动脚本


var计数=2;
//如果脚本位于页面底部,则可以移动
//这里有三条线
var elem=document.getElementById(“imge”);
元素高度=“200”;
元素宽度=“300”;
函数mf(){
elem.src=“img”+(count+1)+“.jpg”//添加1以获取图像1到3
count=((count+1)%3);//将从0循环到2,然后再次循环
设置超时(mf,3000);
}
mf();//开始幻灯片放映的第一次迭代

你还没有在任何地方调用
mf
函数。哦…我真是太傻了…谢谢。如果我想在这张幻灯片中添加转换样式,我该怎么办?这取决于你想做什么。你可能想查看css转换:你可以通过编程方式添加和删除css类以获得想要的效果。你知道什么您所针对的浏览器?例如,如果我希望图像从左到右缓慢加载。我可以使用CSS实现吗?目标浏览器可以是任何浏览器如果您使用当前的chrome和firefox,您可以使用elem.classList.add('classu to_add')和elem.classList.remove('classu to_remove')。请参阅
<html>
<style>
#slideshow{width:310;height:210;border-style:solid;}
#slideshow>img{position:absolute;left:15;top:15}
</style>
<body>
<div id="slideshow">
<img id="imge" src="img1.jpg" height="200" width="300">
</div>
<script>
var count=2;
function mf()
{
document.getElementById("imge").src="img"+count+".jpg";
document.getElementById("imge").height="200";
document.getElementById("imge").width="300";
if(count<3)
count++;
else
count=1;
setTimeout("mf()",3000);
}
</script>
</body>
</html>
<script>
   var count=2;
   // if your script is at the bottom of the page, you can move 
   // these three lines out here
   var elem = document.getElementById("imge");  
   elem.height="200";
   elem.width="300";

   function mf() {

      elem.src="img"+ (count + 1) +".jpg"; // add 1 to grab images 1 through 3

      count = ((count + 1) % 3); // will loop from 0 to 2 and back again
      setTimeout(mf,3000);
   }
   mf(); // kick off the first iteration of the slideshow
</script>