在html页面的幻灯片放映中动态填充图像 [英] Dynamically populate images in slide show in html page

查看:99
本文介绍了在html页面的幻灯片放映中动态填充图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HI

我想做一张幻灯片,在其中动态填充图像...我已经编写了代码,但它没有旋转图像...它只是显示第一个图像,仅此而已...

请帮助我实现这个目标.

提前谢谢!

代码是:

php文件

HI

I want make a slide show in which dynamically images are populated... I have written the code but it is not rotating the images... it is just showing the first image and that''s it...

Kindly help me to get this goal..

Thanks in advance!

the code is:

php file

<?php

 header("content-type: application/x-javascript");

    function returnimages($dirname=".") {

        $files = array();

        $curimage = 0;


        //valid image extensions

        $pattern="(\.jpg$)|(\.png$)|(\.jpeg$)|(\.gif$)";


        if($handle = opendir($dirname)) {


            while(false !== ($file = readdir($handle))) {

                if(eregi($pattern, $file)){

                    echo 'galleryarray[' . $curimage . '] = "' . $file . '";';

                    $curimage++;

                }

            }


            closedir($handle);

        }


     return $files;


    }

    //Define array in JavaScript returnimages()
    //Output the array elements containing the image file names

  returnimages();

var galleryarray = new Array();


?>




html文件:




html file:

<html>

<head>

</head>

<body>

<?php     include ('test.php'); ?>


 <script src="jquery-jquery-95559f5/jquery.min.js"></script>

        <script type="text/javascript">

            var galleryarray = returnimages();

            var curimg = 0;

            function rotateimages(){


        var imagesDirectory =galleryarray[curimg];

                document.getElementById("slideshow").setAttribute("src", imagesDirectory)

                curimg = (curimg < galleryarray.length - 1) ? curimg + 1 : 0

            }



            window.onload = function(){



             setInterval("rotateimages()", 900)



            }



        </script>

</body>

    <div style="width: 170px; height: 160px" id="container">

        <img id="slideshow" src="Slide1.jpg" />

    </div>

</html>

推荐答案

dirname = " ){
dirname=".") {


文件 = array();
files = array();


curimage = 0 ; // 有效的图像扩展名
curimage = 0; //valid image extensions


这篇关于在html页面的幻灯片放映中动态填充图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆