javascript - 使用 jQuery/javascript 动态添加目录中的所有图像
问题描述
我想创建一个简单的网站,可以滚动浏览给定文件夹中的所有图片。
我有一个简单的 jQuery 脚本,它将在页面上一次显示一个图像,在图片之间淡化。它目前适用于硬编码图像。
理想情况下,我想编写一个脚本,为特定文件夹(比如/images)中的所有图像动态创建标签。我的脚本如下所示,但它不提取任何图像。
谁能看到这里有什么问题?谢谢!
<html><head>
<style>
.gallery { position:relative; height:500px; width:800px; }
.gallery img { position:absolute; height:500px; width:800px; }
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
</head>
<body>
<script>
//load images and fade them in and out - this works
$(function(){
$('.gallery img:gt(0)').hide();
setInterval(function(){
$('.gallery :first-child').fadeOut()
.next('img').fadeIn()
.end().appendTo('.gallery');},
3000);
});
//create an imageList id with a list of all images in a folder - this does not work
$('<img>')
.attr('src', '/images')
.appendTo('#imageList')
</script>
<div class="gallery" id="imageList"></div>
</body>
</html>
解决方案
推荐阅读
- javascript - 检查对象数组中是否存在所有键如果没有找到将其添加到数组中
- python - How to allow only admins to execute a command
- reactjs - React Redux - Getting state to component - Uncaught TypeError: users.map is not a function
- java - 如何通过命令行杀死特定的 Firefox 配置文件 [Java]
- c# - 无法加载实体框架不变名称“MySql.Data.MySqlClient”
- python - 使用 CSV 数据文件 Sklearn 的简单线性回归
- java - 'overridden method does not throw Exception' when use lambda with override exception thrown
- java - 使用 POI 库时出现 ClassNotFoundException org.apache.commons.collections4.ListValuedMap
- java - 如何通过 Selenium 访问框架内的嵌套 html
- php - phpmailer无法发送电子邮件