admin管理员组文章数量:1323323
Hey I am trying to figure out a way for me to add some media(images and videos) to my webpage. I have a section where I add only images and videos, and it is HTML-based So I thought I could find a way to just create one folder for each section, add all the media in that folder, and then let Javascript do the work. This is the script I have e up with so far.
Javascript
var files = {'jpg':4};
var pageName = "Wimoveh";
for (var ext in files){
for (var i = 0; i < files[ext]; i++){
var src = "Images/GalleryOne" + pageName + "-" + (i+1) + "." + ext;}
}
This script looks in the folder GalleryOne for the picture with name Wimoveh with a '-' as separator and then iterates through all the content that matches that name and extension. What I dont know is how to output the result in my HTML.
Hey I am trying to figure out a way for me to add some media(images and videos) to my webpage. I have a section where I add only images and videos, and it is HTML-based So I thought I could find a way to just create one folder for each section, add all the media in that folder, and then let Javascript do the work. This is the script I have e up with so far.
Javascript
var files = {'jpg':4};
var pageName = "Wimoveh";
for (var ext in files){
for (var i = 0; i < files[ext]; i++){
var src = "Images/GalleryOne" + pageName + "-" + (i+1) + "." + ext;}
}
This script looks in the folder GalleryOne for the picture with name Wimoveh with a '-' as separator and then iterates through all the content that matches that name and extension. What I dont know is how to output the result in my HTML.
Share asked Oct 14, 2012 at 16:39 DruckerDrucker 271 gold badge2 silver badges5 bronze badges2 Answers
Reset to default 3Inside your loop:
var img = new Image();
img.src = src;
containerElement.appendChild(img);
Where containerElement is a reference to the html element you want to add the images to. (note that you'll need to delay until the dom has loaded to do so)
As Generalhenry stated in his post:
Where containerElement is a reference to the html element you want to add the images to. (note that you'll need to delay until the dom has loaded to do so)
The containerElement is what ever HTML element you want it to be. For example:
<HTML>
<BODY>
<div class="photos">
Your images would populate here.
</div>
</BODY>
</HTML>
Every time loop through your script when the code reaches photos.appendChild(IMG) your page will add an image to that div class.
本文标签: iterating through image folder using javascript and adding the result in HTMLStack Overflow
版权声明:本文标题:iterating through image folder using javascript and adding the result in HTML - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742142305a2422635.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论