动态设置在Javascript(目前静态)图像阵列 [英] Dynamically setting (currently static) image array in Javascript

查看:219
本文介绍了动态设置在Javascript(目前静态)图像阵列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过JavaScript和js文件的图像implementa幻灯片,其中含有幻灯片影像TOP4

I want to implementa slideshow of images through javascript and js files, where the slideshow contains top4 images.

我以前所在的图像阵列具有静态图像的脚本。

I used the script where the image array has static images.

我想把它从index.aspx.cs文件中找到我名字的图像转换成动态
被存储在隐藏字段。我如何获取这些隐藏字段,并将它们添加到图像阵列?

I want to convert it dynamically by finding my images names from index.aspx.cs files which are stored in hidden fields. How do I retrieve these hidden fields and add them to the image array?

<script type="text/javascript">
var mygallery2=new fadeSlideShow({
 wrapperid: "fadeshow2", //ID of blank DIV on page to house Slideshow
 dimensions: [568, 313], //width/height of gallery in pixels. Should reflect dimensions of largest image
 imagearray: [
  ["images/1.jpg", "", "", ""],
  ["images/2.jpg", "", "", ""],
  ["images/3.jpg"],
  ["images/4.jpg", "", "", ""] //<--no trailing comma after very last image element!
 ],
 displaymode: {type:'auto', pause:2500, cycles:0, wraparound:false},
 persist: false, //remember last viewed slide and recall within same session?
 fadeduration: 500, //transition duration (milliseconds)
 descreveal: "always",
 togglerid: "fadeshow2toggler"
})
 </script>

其中上面的脚本有静态图像imagearray。我想通过寻找隐藏字段的值,使之动态地在第一个脚本。

where above script have imagearray of static images. I want to make it dynamically as in 1st script by finding hidden field values.

我怎样才能做到这一点。

How can I do this.

我在JavaScript差。请帮我

I am poor in javascript. Please help me

推荐答案

给定的脚本执行之前,您可以创建一个包含脚本的名字却一个Javascript数组是合适的,例如:

Before the given script executes, you can create a Javascript array containing the names of your scripts however is appropriate, for instance:

var myImages = [];
var hiddenElements = getMyHiddenElements();
for (int i = 0; i < hiddenElements.length; i++)
{
   myImages[myImages.length] = hiddenElements[i].value;
}

然后当你创建fadeSlideShow,您可以传递的这个的数组,而不是制作一个内联:

Then when you create the fadeSlideShow, you can pass in this array instead of creating one inline:

var mygallery2=new fadeSlideShow({
 ...
 dimensions: [568, 313], //width/height of gallery in pixels
 imagearray: myImages,
 ...

这将使用您之前为图像源的数组。 (请注意,根据您的片断,你可能需要使它与什么是可能的标题/字幕,但原理是一样的二维数组。创建的数组中预先标准的JavaScript可变的,根据你的隐藏字段,然后的的传递到幻灯片的构造函数)。

This will use the array that you created earlier for the image sources. (Note that based on your snippet, you'll likely need to make it a two-dimensional array with what's probably titles/captions, but the principle remains the same. Create the array beforehand as a standard Javascript variable, based on your hidden fields, and then pass it in to the slideshow constructor).

请注意,从隐藏字段提取信息听起来不像来实现这一功能最彻底的方法。你可能会发现,如果你是动态生成的页面,它实际上是很容易直接生成文字的Javascript数组声明的页面,而不是添加隐藏字段,然后把他们变成在通过JS运行的数组。

Note that extracting information from hidden fields doesn't sound like the cleanest way to achieve this functionality. You may find that, if you're generating the page dynamically, it's actually easier to simply generate the page with a literal Javascript array declaration rather than adding hidden fields and then turning them into an array at "runtime" via JS.

这篇关于动态设置在Javascript(目前静态)图像阵列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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