【问题标题】:dynamic slideshow of files(of any type)文件的动态幻灯片(任何类型)
【发布时间】:2017-10-06 10:46:29
【问题描述】:

我的文件夹中有一些文件(图片、pdf、文本)。
假设我的文件是:

  • image1.jpg
  • image2.jpg
  • pdf1.pdf
  • text1.txt

在文件夹“文件”中。
现在我想用自定义时间显示每个文件,这意味着例如

  1. image1.jpg - 5 秒
  2. image2.jpg - 10 秒
  3. pdf1.pdf - 20 秒
  4. text1.txt - 15 秒

假设我将文件路径和文件时间作为键 => array 中的值

我该怎么做?

我曾尝试在 php 和 javascript 中这样做

<script>

function display_time(param1)
{
  var time=param1*60*1000;
  var res=setTimeout(doHide,time);
  function doHide(){
      document.getElementById("file").style.display = "none";

  }

}


<?php
**// assume i have my file path and file time in $input respectively**
    $image_ext=["jpg","png"];
  $file_path=array_keys($input); 
  $file_time=array_values($input);
  $i=0;

  for($i;$i<count($input);$i++){
  $ext= pathinfo($file_path[$i],PATHINFO_EXTENSION);
  echo '<div class="section" style="max-width:800px">';
  if(in_array($ext,$GLOBALS['image_ext'])){
  echo '<img src= '.$file_path[$i].' alt = "This image cant be loaded" style="width:800px" id="file">';
  echo '<script>display_time('.$file_time[$i].');</script>';

  }
  elseif(($ext=="txt")){
  echo '<p id="file">'.file_get_contents($file_path[$i]).'</p>';
  echo '<script>display_time('.$file_time[$i].');</script>';

  }
  elseif($ext == 'pdf'){
  echo '<embed src='.$file_path[$i].' width="800px" height="2500px" id="file"/>';
  echo '<script>display_time('.$file_time[$i].');</script>';

  }
  echo '</div>';
  }

?>

【问题讨论】:

  • 您可以创建一个json文件并读取每个文件自定义时间。

标签: javascript php html css ajax


【解决方案1】:

你应该使用materialize

使用简单的代码,例如:

<div class="carousel">
<a class="carousel-item" href="#one!"><img src="https://lorempixel.com/250/250/nature/1"></a>
<a class="carousel-item" href="#two!"><img src="https://lorempixel.com/250/250/nature/2"></a>
<a class="carousel-item" href="#three!"><img src="https://lorempixel.com/250/250/nature/3"></a>
<a class="carousel-item" href="#four!"><img src="https://lorempixel.com/250/250/nature/4"></a>
<a class="carousel-item" href="#five!"><img src="https://lorempixel.com/250/250/nature/5"></a>

并初始化它:

$(document).ready(function(){
  $('.carousel').carousel();
});

希望这就是你所需要的!

【讨论】:

  • 嗨,我想我不能使用它,因为每个文件都有不同的时间值,并且每次运行脚本时我的文件数量(图像、pdf 等)都会有所不同。如果我错了,请纠正我。
【解决方案2】:

尝试为每个文件创建一个对象 示例

let objArray = [
{
url = '/file.jpg',
time = 5
}
.....
]

然后创建一个setTimeout 并将对象时间值放在那里

settimeout(function(){
...
}, objArray[n].time*1000);

【讨论】:

  • 嗨,是的,我已经以类似的方式完成了。我创建了一个数组,其中键是文件,值是时间,然后我调用了 setTimeout(function(), time) 函数在那个时间隐藏元素,但它只适用于我不是的第一个元素明白为什么?
  • 你不认为是因为你对不同的容器使用相同的 ID 吗?
  • 感谢您的宝贵时间。我想通了。
  • 所以,检查我的答案)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2010-10-11
  • 2013-04-11
  • 2018-01-12
  • 1970-01-01
  • 2015-04-21
  • 1970-01-01
  • 2012-04-15
相关资源
最近更新 更多