Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/github/3.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 - Fatal编程技术网

用于幻灯片放映的Javascript

用于幻灯片放映的Javascript,javascript,Javascript,有人能推荐好的javascript代码来实现slideshow吗?这样slideshow的所有元素都可以在一个数组中声明。我希望它使用纯javascript而不使用jQuery。这可能对您有用。复制和替换图像 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="h

有人能推荐好的javascript代码来实现slideshow吗?这样slideshow的所有元素都可以在一个数组中声明。我希望它使用纯javascript而不使用jQuery。这可能对您有用。复制和替换图像

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>image slide show</title>
<style type="text/css">
body {
    background:#FFC;
}
input[type="button"] {
    background:#939907;
    color:#fff;
    border:1px solid #434603;
    -moz-border-radius:5px;
    -webkit-border-radius:5px;
    -ms-border-radius:5px;
    font-weight:bold;
    cursor:pointer;
    height:25px;
}
img {
    width:525px;
    height:200px;
    border:2px solid #CF3;
    -moz-border-radius:15px;
    -webkit-border-radius:15px;
    -ms-border-radius:15px;
}
</style>
<script type="text/javascript">
var images=new Array();
var i=0, t, f=false;

images[0] ="images/heli1.jpg";
images[1] ="images/heli2.JPG";
images[2] ="images/heli3.JPG";
images[3] ="images/heli4.JPG";
images[4] ="images/heli5.JPG";
images[5] ="images/heli6.JPG";
images[6] ="images/heli7.JPG";
images[7] ="images/heli2.JPG";
images[8] ="images/heli9.JPG";
images[9] ="images/heli1.jpg";
images[10] ="images/heli2.JPG";
images[11] ="images/heli3.JPG";
images[12] ="images/heli4.JPG";
images[13] ="images/heli5.JPG";
images[14] ="images/heli6.JPG";


    function start(){
        if(i>=images.length){
            i=0;
            document.getElementById('img').src=images[i];   
            i++;        
        }
        else{
            document.getElementById('img').src=images[i];
            i++;
        }
        t=setTimeout("start()", 1000);  
    }
    function play(){
        if(f==false){
            f=true;
            start();
        }
    }

    function Stop(){
        clearTimeout(t);
        f=false;
    }

    function next(){
        if(i>=images.length){
            i=0;
            document.getElementById('img').src=images[i];   
            i++;
        }
        else{
            document.getElementById('img').src=images[i];
            i++;
        }
    }

    function previous(){
        if(i>=images.lenght){
            i=images.length;
            document.getElementById('img').src=images[i];
            i--;
        }
        else if(i<=0){
            i=images.length;
            document.getElementById('img').src=images[i-1];
            i--;
        }
        else if(i>images.length){

            document.getElementById('img').src=images[images.length-i]; 
        }
        else if(i<=images.length || i>0){
            document.getElementById('img').src=images[i-1];
            i--;
        }
    }

</script>
</head>

<body>
<table width="50%" border="0" cellspacing="0" cellpadding="0" align="center">
  <tr>
    <td><input type="button" value="Previous" onclick="previous()" /></td>
    <td align="center"><a href="#"><img src="images/heli6.JPG" alt=""  id="img" /></a></td>
    <td><input type="button" value="Next" onclick="next()" /></td>
  </tr>
  <tr>
    <td colspan="3" align="center" height="50"><input type="button" value="Play" onclick="play()" />
      <input type="button" value="Stop" onclick="Stop()" /></td>
  </tr>
</table>
</body>
</html>

图像幻灯片放映
身体{
背景:#FFC;
}
输入[type=“button”]{
背景:939907;
颜色:#fff;
边框:1px实心#434603;
-moz边界半径:5px;
-webkit边界半径:5px;
-ms边界半径:5px;
字体大小:粗体;
光标:指针;
高度:25px;
}
img{
宽度:525px;
高度:200px;
边框:2px实心#CF3;
-moz边界半径:15px;
-webkit边界半径:15px;
-ms边界半径:15px;
}
var images=新数组();
变量i=0,t,f=false;
images[0]=“images/heli1.jpg”;
images[1]=“images/heli2.JPG”;
images[2]=“images/heli3.JPG”;
images[3]=“images/heli4.JPG”;
images[4]=“images/heli5.JPG”;
images[5]=“images/heli6.JPG”;
images[6]=“images/heli7.JPG”;
images[7]=“images/heli2.JPG”;
images[8]=“images/heli9.JPG”;
images[9]=“images/heli1.jpg”;
images[10]=“images/heli2.JPG”;
images[11]=“images/heli3.JPG”;
images[12]=“images/heli4.JPG”;
images[13]=“images/heli5.JPG”;
images[14]=“images/heli6.JPG”;
函数start(){
如果(i>=images.length){
i=0;
document.getElementById('img').src=images[i];
i++;
}
否则{
document.getElementById('img').src=images[i];
i++;
}
t=设置超时(“开始()”,1000);
}
函数播放(){
如果(f==false){
f=真;
start();
}
}
函数停止(){
清除超时(t);
f=假;
}
函数next(){
如果(i>=images.length){
i=0;
document.getElementById('img').src=images[i];
i++;
}
否则{
document.getElementById('img').src=images[i];
i++;
}
}
函数previous(){
如果(i>=images.lenght){
i=图像长度;
document.getElementById('img').src=images[i];
我--;
}
else if(图像长度){
document.getElementById('img').src=images[images.length-i];
}
else if(i0){
document.getElementById('img').src=images[i-1];
我--;
}
}

这可能对您有用。复制和替换图像

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>image slide show</title>
<style type="text/css">
body {
    background:#FFC;
}
input[type="button"] {
    background:#939907;
    color:#fff;
    border:1px solid #434603;
    -moz-border-radius:5px;
    -webkit-border-radius:5px;
    -ms-border-radius:5px;
    font-weight:bold;
    cursor:pointer;
    height:25px;
}
img {
    width:525px;
    height:200px;
    border:2px solid #CF3;
    -moz-border-radius:15px;
    -webkit-border-radius:15px;
    -ms-border-radius:15px;
}
</style>
<script type="text/javascript">
var images=new Array();
var i=0, t, f=false;

images[0] ="images/heli1.jpg";
images[1] ="images/heli2.JPG";
images[2] ="images/heli3.JPG";
images[3] ="images/heli4.JPG";
images[4] ="images/heli5.JPG";
images[5] ="images/heli6.JPG";
images[6] ="images/heli7.JPG";
images[7] ="images/heli2.JPG";
images[8] ="images/heli9.JPG";
images[9] ="images/heli1.jpg";
images[10] ="images/heli2.JPG";
images[11] ="images/heli3.JPG";
images[12] ="images/heli4.JPG";
images[13] ="images/heli5.JPG";
images[14] ="images/heli6.JPG";


    function start(){
        if(i>=images.length){
            i=0;
            document.getElementById('img').src=images[i];   
            i++;        
        }
        else{
            document.getElementById('img').src=images[i];
            i++;
        }
        t=setTimeout("start()", 1000);  
    }
    function play(){
        if(f==false){
            f=true;
            start();
        }
    }

    function Stop(){
        clearTimeout(t);
        f=false;
    }

    function next(){
        if(i>=images.length){
            i=0;
            document.getElementById('img').src=images[i];   
            i++;
        }
        else{
            document.getElementById('img').src=images[i];
            i++;
        }
    }

    function previous(){
        if(i>=images.lenght){
            i=images.length;
            document.getElementById('img').src=images[i];
            i--;
        }
        else if(i<=0){
            i=images.length;
            document.getElementById('img').src=images[i-1];
            i--;
        }
        else if(i>images.length){

            document.getElementById('img').src=images[images.length-i]; 
        }
        else if(i<=images.length || i>0){
            document.getElementById('img').src=images[i-1];
            i--;
        }
    }

</script>
</head>

<body>
<table width="50%" border="0" cellspacing="0" cellpadding="0" align="center">
  <tr>
    <td><input type="button" value="Previous" onclick="previous()" /></td>
    <td align="center"><a href="#"><img src="images/heli6.JPG" alt=""  id="img" /></a></td>
    <td><input type="button" value="Next" onclick="next()" /></td>
  </tr>
  <tr>
    <td colspan="3" align="center" height="50"><input type="button" value="Play" onclick="play()" />
      <input type="button" value="Stop" onclick="Stop()" /></td>
  </tr>
</table>
</body>
</html>

图像幻灯片放映
身体{
背景:#FFC;
}
输入[type=“button”]{
背景:939907;
颜色:#fff;
边框:1px实心#434603;
-moz边界半径:5px;
-webkit边界半径:5px;
-ms边界半径:5px;
字体大小:粗体;
光标:指针;
高度:25px;
}
img{
宽度:525px;
高度:200px;
边框:2px实心#CF3;
-moz边界半径:15px;
-webkit边界半径:15px;
-ms边界半径:15px;
}
var images=新数组();
变量i=0,t,f=false;
images[0]=“images/heli1.jpg”;
images[1]=“images/heli2.JPG”;
images[2]=“images/heli3.JPG”;
images[3]=“images/heli4.JPG”;
images[4]=“images/heli5.JPG”;
images[5]=“images/heli6.JPG”;
images[6]=“images/heli7.JPG”;
images[7]=“images/heli2.JPG”;
images[8]=“images/heli9.JPG”;
images[9]=“images/heli1.jpg”;
images[10]=“images/heli2.JPG”;
images[11]=“images/heli3.JPG”;
images[12]=“images/heli4.JPG”;
images[13]=“images/heli5.JPG”;
images[14]=“images/heli6.JPG”;
函数start(){
如果(i>=images.length){
i=0;
document.getElementById('img').src=images[i];
i++;
}
否则{
document.getElementById('img').src=images[i];
i++;
}
t=设置超时(“开始()”,1000);
}
函数播放(){
如果(f==false){
f=真;
start();
}
}
函数停止(){
清除超时(t);
f=假;
}
函数next(){
如果(i>=images.length){
i=0;
document.getElementById('img').src=images[i];
i++;
}
否则{
document.getElementById('img').src=images[i];
i++;
}
}
函数previous(){
如果(i>=images.lenght){
i=图像长度;
document.getElementById('img').src=images[i];
我--;
}
else if(图像长度){
document.getElementById('img').src=images[images.length-i];
}
else if(i0){
document.getElementById('img').src=images[i-1];
我--;
}
}

无标题文件
加载的\u img=0;
没有一个img=12;
img_name=新数组();
img_name.length=img-1的编号;
对于(var count=0;count<0;count++)
{
var file_num=count+1;
var filename=(“img”+file_num+“.jpg”);
img_name[计数]=文件名;
}
var whichlink=0
函数slideit(){
如果(!document.images)
返回
document.images.myimage.src=img\u name[loaded\u img].src
whichlink=已加载\u img
如果(已加载)
//slideshowimages()=新数组()
//幻灯片图像(“img1.jpg”)
var whichlink=0
var whichimage=0
函数slideit(){
如果(!document.images)
返回
document.images.myimage.src=slideimages[whichimage].src
whichlink=whichimage
如果(whichimage

无标题文件
加载的\u img=0;
没有一个img=12;
img_name=新数组();
img_name.length=img-1的编号;
对于(var count=0;count<0;count++)
{
var file_num=count+1;
var filename=(“img”+file_num+“.jpg”);
img_name[计数]=文件名;
}
var whichlink=0
函数slideit(){
如果(!document.images)
返回
document.images.myimage.src=img\u name[loaded\u img].src
whichlink=已加载\u img
如果(已加载)
//slideshowimages()=新数组()
//幻灯片图像(“img1.jpg”)
var whichlink=0
var whichimage=0
函数slideit(){
如果(!document.images)
返回
document.images.myimage.src=slideimages[whichimage].src
whichlink=whichimage
如果(whichimage这个问题是老问题,那么
<!-- index.html -->

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>slideshow</title>
</head>
<body>

<section>
    <div>
        <img id="image">
    </div>
    <div>
        <button type="button" id="playBtn">Play</button>
        <button type="button" id="pauseBtn">Pause</button>
    </div>
    <div>
        <button type="button" id="prevBtn">Prev</button>
        <button type="button" id="nextBtn">Next</button>
    </div>
</section>

<script src="slideshow.js"></script>
</body>
</html>
// slideshow.js

document.addEventListener(
  // IE 9 and up. See http://caniuse.com/#feat=domcontentloaded
  'DOMContentLoaded'

, (function STRICT() {
    'use strict';

    // Avoid 'new' and stick to array literals where possible.
    var images =
          [ 'img/30.gif'
          , 'img/31.gif'
          , 'img/32.gif'
          , 'img/33.gif'
          , 'img/34.gif'
          ]

      , img = document.getElementById('image')
      , playBtn = document.getElementById('playBtn')
      , pauseBtn = document.getElementById('pauseBtn')
      , prevBtn = document.getElementById('prevBtn')
      , nextBtn = document.getElementById('nextBtn')

      , index = 0
      , indexOfLastImage = images.length - 1

      , play
      , playInterval
      , pause
      , goToPrevious
      , goToNext
      , beginSlideShow


    play = function() {
      playInterval = setInterval(
        function() {
          if (index === indexOfLastImage) { index = 0 }

          img.src = images[++index]
        }
      , 3000
      )
    }

    pause = function() {
      clearInterval(playInterval)
      playInterval = null
    }


    goToPrevious = function() {
      // if the slideshow was running
      if (playInterval) { pause() }
      // if we're at the beginning of the array
      if (index === 0) {
        index = indexOfLastImage + 1
      }
      img.src = images[--index]
    }

    goToNext = function() {
      // if the slideshow was running
      if (playInterval) { pause() }
      // if we're at the beginning of the array
      if (index === indexOfLastImage) {
        index = -1
      }
      img.src = images[++index]
    }


    beginSlideShow = function() {
      // add listeners
      playBtn.addEventListener('click', play)
      pauseBtn.addEventListener('click', pause)
      prevBtn.addEventListener('click', goToPrevious)
      nextBtn.addEventListener('click', goToNext)
      // set initial image for display prior to first interval
      img.src = images[index]
      // kick off auto play
      play()
    }

    // This is what's attached to and will fire on the DOMContentLoaded event
    return beginSlideShow

  }())
)