求如图所示幻灯片 这个在网上搜的 但不能随时更新图片 只能手动输入图片src路径 我想要可以随时从文件夹读取图片
假如我上传一张图片到文件夹中 不用手动输入src 可以随时更新幻灯片里的图片 
分不够可以加,如果那位高手有现成的例子可以发到我QQ邮箱[email protected] 谢谢!

解决方案 »

  1.   

    这个还不简单,在这个js文件前,用ajax到后台读取 文件夹里的图片,赋值给js不就行了?
      

  2.   

    setinterval在图片的文件夹下 放个 文本文件 存储 图片的名称新增图片时,在文件夹下新增文件,同时 在文本文件中 加入图片的名称js 利用 setinterval 每隔 5秒 访问 文本文件
      

  3.   

    各位高手有现成例子吗? 代码也行 ajax js都可以
      

  4.   

    看看这个,比较不错,是使用jquery框架的
    http://css-tricks.com/examples/AnythingSlider/#panel-3
      

  5.   

    show.html
    <html>
    <div id='div'>
    </div>
    </html>
    <script src='a.xx'>
    </script> 
    <script>
    function response()
    {
    if(array)
            {
        var html='';
                for(var i=0;i<array.length;i++)
                {
                    html+=array[i]+'  ';
                }
                document.getElementById('div').innerHTML=html;
            }
            importJS('a.xx');
    }
    function importJS(src) {      
        var header = document.getElementsByTagName('head').item(0);      
        var js = document.createElement("<script src='"+src+"'><\/script>");       
        header.appendChild(js);      
    }  setInterval(response,5000);
    </script> 
    a.xxarray = ["1.jpg", "2.jpg", "b.jpg"]; 
      

  6.   

    or 
    <script id='js' src='a.xx'>
    </script> 
    function importJS(src) {                     
    document.getElementById('js').src='a.xx';
    }  
    如果 可以使用动态语言的话 可以不用使用文本文件,直接访问 .aspx or .ashx  ,然后在服务器端 用C# 去访问文件夹获得 所有图片的文件名,然后 输出,就不用人工往 文本文件里写了
      

  7.   

    1个img控件 <input type="IMG" src="" id="theImage" alt="" />
     var i=0;
     var theimg=document.getElementsByID("theImage");
    function PlayImg()
    {
         if(i==0){theimg.src="../../***/i.jpg";}  //这里我随便 让固定路径下图片名为i.
         if(++i>7){i=0;}                          //该目录下就7个图片
    }
    function onLoadCompelete(){
               setInterval("PlayImg()",3500); 
               //时间可以自己设定快慢
    }
    代码我随手写的,没有验证,大概就是这个意思了。你自己改改。
      

  8.   

    在哪里修改 ?源代码如下
    <script type="text/javascript">
    function slide(src,link,text,target,attr,desc) {
      this.desc = desc
      this.src = src;
      this.link = link;
      this.text = text;
      this.target = target;
      this.attr = attr;
      if (document.images) {
        this.image = new Image();
      }
      this.loaded = false;
      this.load = function() {
        if (!document.images) { return; }    if (!this.loaded) {
          this.image.src = this.src;
          this.loaded = true;
        }
      }
      this.hotlink = function() {
        var mywindow;
        if (!this.link) return;
        if (this.target) {
          if (this.attr) {
            mywindow = window.open(this.link, this.target, this.attr);
      
          } else {
            mywindow = window.open(this.link, this.target);
          }
          if (mywindow && mywindow.focus) mywindow.focus();    } else {
          location.href = this.link;
        }
      }
    }
    function slideshow( slideshowname ) {
      this.name = slideshowname;
      this.repeat = true;
      this.prefetch = -1;
      this.image;
      this.textid;
      this.textarea;
      this.timeout = 5000;
      this.slides = new Array();
      this.current = 0;
      this.timeoutid = 0;
      this.add_slide = function(slide) {
        var i = this.slides.length;
        if (this.prefetch == -1) {
          slide.load();
        }    this.slides[i] = slide;
      }
      this.play = function(timeout) {
        this.pause();
        if (timeout) {
          this.timeout = timeout;
        }
        if (typeof this.slides[ this.current ].timeout != 'undefined') {
          timeout = this.slides[ this.current ].timeout;
        } else {
          timeout = this.timeout;
        }
        this.timeoutid = setTimeout( this.name + ".loop()", timeout);
      }
      this.pause = function() {
        if (this.timeoutid != 0) {      clearTimeout(this.timeoutid);
          this.timeoutid = 0;    }
      }
      this.update = function() {
        if (! this.valid_image()) { return; }
        if (typeof this.pre_update_hook == 'function') {
          this.pre_update_hook();
        }
        var slide = this.slides[ this.current ];
        var dofilter = false;
        if (this.image &&
            typeof this.image.filters != 'undefined' &&
            typeof this.image.filters[0] != 'undefined') {
          dofilter = true;    }
        slide.load();
        if (dofilter) {
          if (slide.filter &&
              this.image.style &&
              this.image.style.filter) {
            this.image.style.filter = slide.filter;
          }
          this.image.filters[0].Apply();
        }
        this.image.src = slide.image.src;
        if (dofilter) {
          this.image.filters[0].Play();
        }
        this.display_text();
        if (typeof this.post_update_hook == 'function') {
          this.post_update_hook();
        }
        if (this.prefetch > 0) {      var next, prev, count;
          next = this.current;
          prev = this.current;
          count = 0;
          do {
            if (++next >= this.slides.length) next = 0;
            if (--prev < 0) prev = this.slides.length - 1;
            this.slides[next].load();
            this.slides[prev].load();
          } while (++count < this.prefetch);
        }
      }
      this.goto_slide = function(n) {
        if (n == -1) {
          n = this.slides.length - 1;
        }
        if (n < this.slides.length && n >= 0) {
          this.current = n;
        }
        this.update();
      }
      this.goto_random_slide = function(include_current) {
        var i;
        if (this.slides.length > 1) {
          do {
            i = Math.floor(Math.random()*this.slides.length);
          } while (i == this.current);
          this.goto_slide(i);
        }
      }
      this.next = function() {
        if (this.current < this.slides.length - 1) {
          this.current++;
        } else if (this.repeat) {
          this.current = 0;
        }
        this.update();
      }
      this.previous = function() {
        if (this.current > 0) {
          this.current--;
        } else if (this.repeat) {
          this.current = this.slides.length - 1;
        }
        this.update();
      }
      this.shuffle = function() {
        var i, i2, slides_copy, slides_randomized;
        slides_copy = new Array();
        for (i = 0; i < this.slides.length; i++) {
          slides_copy[i] = this.slides[i];
        }
        slides_randomized = new Array();
        do {
          i = Math.floor(Math.random()*slides_copy.length);
          slides_randomized[ slides_randomized.length ] =
            slides_copy[i];
          for (i2 = i + 1; i2 < slides_copy.length; i2++) {
            slides_copy[i2 - 1] = slides_copy[i2];
          }
          slides_copy.length--;
        } while (slides_copy.length);
        this.slides = slides_randomized;
      }
      this.get_text = function() {
        return(this.slides[ this.current ].text);
      }
      this.get_all_text = function(before_slide, after_slide) {
        all_text = "";
        for (i=0; i < this.slides.length; i++) {
          slide = this.slides[i];
          if (slide.text) {
            all_text += before_slide + slide.text + after_slide;
          }
        }
        return(all_text);
      }
      this.display_text = function(text) {
        if (!text) {
          text = this.slides[ this.current ].text;
        }
        if (this.textarea && typeof this.textarea.value != 'undefined') {
          this.textarea.value = text;
        }
        if (this.textid) {
          r = this.getElementById(this.textid);
          if (!r) { return false; }
          if (typeof r.innerHTML == 'undefined') { return false; }
          r.innerHTML = text;
        }
      }
      this.hotlink = function() {
        this.slides[ this.current ].hotlink();
      }
      this.save_position = function(cookiename) {
        if (!cookiename) {
          cookiename = this.name + '_slideshow';
        }
        document.cookie = cookiename + '=' + this.current;
      }
      this.restore_position = function(cookiename) {
        if (!cookiename) {
          cookiename = this.name + '_slideshow';
        }
        var search = cookiename + "=";
        if (document.cookie.length > 0) {
          offset = document.cookie.indexOf(search);
          if (offset != -1) { 
            offset += search.length;
            end = document.cookie.indexOf(";", offset);
            if (end == -1) end = document.cookie.length;
            this.current = parseInt(unescape(document.cookie.substring(offset, end)));
            }
         }
      }
      this.noscript = function() {
        $html = "\n";
        for (i=0; i < this.slides.length; i++) {
          slide = this.slides[i];
          $html += '<P>';
          if (slide.link) {
            $html += '<a href="' + slide.link + '">';
          }
          $html += '<img src="' + slide.src + '" ALT="slideshow image">';
          if (slide.link) {
            $html += "<\/a>";
          }
          if (slide.text) {
            $html += "<BR>\n" + slide.text;
          }
          $html += "<\/P>" + "\n\n";
        }
        $html = $html.replace(/\&/g, "&" );
        $html = $html.replace(/</g, "<" );
        $html = $html.replace(/>/g, ">" );
        return('<pre>' + $html + '</pre>');
      }
      this.loop = function() {
        if (this.current < this.slides.length - 1) {
          next_slide = this.slides[this.current + 1];
          if (next_slide.image.complete == null || next_slide.image.complete) {
            this.next();
          }
        } else {
          this.next();
        }
        this.play( );
      }
      this.valid_image = function() {
        if (!this.image){
          return false;
        }
        else {
          return true;
        }
      }
      this.getElementById = function(element_id) {
        if (document.getElementById) {
          return document.getElementById(element_id);
        }
        else if (document.all) {
          return document.all[element_id];
        }
        else if (document.layers) {
          return document.layers[element_id];
        } else {
          return undefined;
        }
      }
      this.set_image = function(imageobject) {
        if (!document.images)
          return;
        this.image = imageobject;
      }
      this.set_textarea = function(textareaobject) {
        this.textarea = textareaobject;
        this.display_text();
      }
      this.set_textid = function(textidstr) {
        this.textid = textidstr;
        this.display_text();
      }
    }
    </script>
    <script type="text/javascript" language="javascript">
    //内容部分
    ss = new slideshow("ss"); ss.prefetch = 1;

    ss.sizelmt = true;

    ss.repeat = true;

    s = new slide();
    s.src = "../NewsImg/1.jpg";
    s.title = "最新新闻";
    s.link = "http://www.makewing.com/";
    s.con = "";
    ss.add_slide(s); s = new slide();
    s.src = "../NewsImg/2.jpg";
    s.title = "最新新闻";
    s.link = "http://www.makewing.com/";
    s.con = "";
    ss.add_slide(s); s = new slide();
    s.src = "../NewsImg/3.jpg";
    s.title = "最新新闻";
    s.link = "";
    s.con = "";
    ss.add_slide(s); s = new slide();
    s.src = "../NewsImg/4.jpg";
    s.title = "最新新闻";
    s.link = "";
    s.con = "";
    ss.add_slide(s); s = new slide();
    s.src = "../NewsImg/1.jpg";
    s.title = "最新新闻";
    s.link = "http://www.makewing.com/";
    s.con = "";
    ss.add_slide(s);

    s.src = "../NewsImg/1.jpg";
    s.title = "最新新闻";
    s.link = "http://www.makewing.com/";
    s.con = "";
    ss.add_slide(s); s = new slide();
    s.src = "../NewsImg/2.jpg";
    s.title = "最新新闻";
    s.link = "http://www.makewing.com/";
    s.con = "";
    ss.add_slide(s); s = new slide();
    s.src = "../NewsImg/3.jpg";
    s.title = "最新新闻";
    s.link = "http://www.makewing.com/";
    s.con = "";
    ss.add_slide(s); s = new slide();
    s.src = "../NewsImg/4.jpg";
    s.title = "最新新闻";
    s.link = "";
    s.con = "";
    ss.add_slide(s);

    for (var i=0; i < ss.slides.length; i++) {

    s = ss.slides[i];

    s.target = "_blank";

    }
      

  9.   

     s.src = "../NewsImg/1.jpg";
        s.title = "最新新闻";
        s.link = "http://www.makewing.com/";
        s.con = "";
        ss.add_slide(s);    s = new slide();
        s.src = "../NewsImg/2.jpg";
        s.title = "最新新闻";
        s.link = "http://www.makewing.com/";
        s.con = "";
        ss.add_slide(s);    s = new slide();
        s.src = "../NewsImg/3.jpg";
        s.title = "最新新闻";
        s.link = "";
        s.con = "";
        ss.add_slide(s);    s = new slide();
        s.src = "../NewsImg/4.jpg";
        s.title = "最新新闻";
        s.link = "";
        s.con = "";
        ss.add_slide(s);    s = new slide();
        s.src = "../NewsImg/1.jpg";
        s.title = "最新新闻";
        s.link = "http://www.makewing.com/";
        s.con = "";
        ss.add_slide(s);
        
        s.src = "../NewsImg/1.jpg";
        s.title = "最新新闻";
        s.link = "http://www.makewing.com/";
        s.con = "";
        ss.add_slide(s);    s = new slide();
        s.src = "../NewsImg/2.jpg";
        s.title = "最新新闻";
        s.link = "http://www.makewing.com/";
        s.con = "";
        ss.add_slide(s);
    这都是手动输入src 高手怎么改?
      

  10.   

    http://hi.csdn.net/attachment/200911/11/1157712_125792926802Ze.jpg
      

  11.   


    我学习jquery的时候,做个类似的东西,不知道是否符合你
      

  12.   

    大体写了下
    jquery的js自己下,非常小<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    //引入JSTL的C核心标签库
      <head>
        <title>Photomatic Test</title>
        <link rel="stylesheet" type="text/css" href="../../common.css">
        <link rel="stylesheet" type="text/css" href="photomatic.css">
        <script type="text/javascript"
                src="../../scripts/jquery-1.2.1.js"></script>
        <script type="text/javascript"
                src="jquery.jqia.photomatic.js"></script>
        <script type="text/javascript">
          $(function(){
            $('#thumbnails img').photomatic({
              photoElement: '#photo',
              previousControl: '#previousButton',
              nextControl: '#nextButton',
              firstControl: '#firstButton',
              lastControl: '#lastButton'
            });
          });
        </script>
      </head>
      <body>
        <h1>Photomatic Tester</h1>
        <div id="thumbnails">
    //后台遍历图片夹,得到图片地址的list放置在范围中,遍历输出
        <c:forEatch items="${jpgList}" var="list">
          <img src="{list.jpgUrl}"/>
         </c:forEatch>
        </div>
        <div id="photoContainer">
          <img id="photo" src=""/>
        </div>
        <div id="buttonBar">
          <button type="button" id="firstButton">First</button>
          <button type="button" id="previousButton">Previous</button>
          <button type="button" id="nextButton">Next</button>
          <button type="button" id="lastButton">Last</button>
        </div>
      </body>
    </html>
      

  13.   

    JQUERY滑动门
    http://topic.csdn.net/u/20090319/01/EC60CAF1-AF16-47B5-A89B-BB91E1C5C6E2.html