照片自动播放程序怎样跳过非照片?

105910556 2004-07-12 11:30:13
我做了一个slideshow即幻灯秀,就是网页中照片自动播放,
程序运行良好,可以循环。
但是,如果目录里有其他文件如:txt 等等非jpg文件时我的幻灯秀就不动了,
怎么样让程序跳过那些文件,或者是不是可以写一行代码判断一下?
那么怎么判断是不是jpg文件文件呢?


完整代码如下:

<body vLink="#336699" aLink="#ff0000" link="#336699" bgColor="#ffffff" leftMargin="0" topMargin="0" MS_POSITIONING="FlowLayout" marginwidth="0" marginheight="0">
<center>
<form id="ShowFile" method="post" runat="server">
<table cellSpacing="0" cellPadding="0" width="100%" border="0"></table>
<table cellSpacing="0" cellPadding="0" align="center" border="0">

<tr><td>
<div align="center">

<div align="left">
<%
//fileID = GetIntParam("fileID"); // is it safe? already assigned in base
String view = GetStrParam("view");
String sort = GetStrParam("sort");
String isInc = GetStrParam("isInc");
int curPage = GetIntParam("curPage");
String share = GetStrParam("share");
long shareID = GetLongParam("shareID");
long parentID = GetLongParam("parentID");
String isGallery= GetStrParam("isGallery");
String filePath = "";
if(file!=null)
filePath = file.filePath;
//int seq = seq // member variable, is it safe?
if(fileName==null) fileName="";

DataTable filesDT = (DataTable)Session["filesDT" + shareID+parentID];

%>

<% String pageClass = "ShowFolder"; //isGallery=="true"? "ShowGallery": "ShowFolder";
%>

<asp:HyperLink ID="PrevHyperLink" runat="server"></asp:HyperLink>
<asp:HyperLink ID="NextHyperLink" runat="server"></asp:HyperLink>
</a>
<table width="100%" border=0>

<tr>
<td align="center" valign="top">


<% int i;
for(i=0; filesDT!=null && i<filesDT.Rows.Count; ++i) {

%>

<a id="photo_urls_<%=i%>" href='DF.aspx/<%=filesDT.Rows[i]["fileName"]%>?size=pv&isGallery=<%=isGallery%>&share=<%=share%>&shareID=<%=shareID%>&fileID=<%=filesDT.Rows[i]["fileID"]%>&sesID=<%=Session.SessionID%>&type=text/html&ft=<%=filesDT.Rows[i]["modifyTime"]%>'></a>
<a id="full_photo_urls_<%=i%>" href='DF.aspx/<%=filesDT.Rows[i]["fileName"]%>?isGallery=<%=isGallery%>&share=<%=share%>&shareID=<%=shareID%>&fileID=<%=filesDT.Rows[i]["fileID"]%>&sesID=<%=Session.SessionID%>&type=text/html&ft=<%=filesDT.Rows[i]["modifyTime"]%>'></a>

<% } %>

<script language="JavaScript" SRC="client_sniff.js"></script>
<script language="JavaScript">
var timer;
var current_location = 1;
var next_location = 1;
var pics_loaded = 0;
var onoff = 0;
var fullsized = 0;
var direction = 1;
var timeout_value;
var images = new Array;
var photo_urls = new Array;
var full_photo_urls = new Array;
var photo_captions = new Array;
var transitionNames = new Array;
var transitions = new Array;
var current_transition = 15;
var loop = 0;


transitions[0] = "progid:DXImageTransform.Microsoft.Fade(duration=1)";
transitions[1] = "progid:DXImageTransform.Microsoft.Blinds(Duration=1,bands=20)";
transitions[2] = "progid:DXImageTransform.Microsoft.Checkerboard(Duration=1,squaresX=20,squaresY=20)";
transitions[3] = "progid:DXImageTransform.Microsoft.Strips(Duration=1,motion=rightdown)";
transitions[4] = "progid:DXImageTransform.Microsoft.Barn(Duration=1,orientation=vertical)";
transitions[5] = "progid:DXImageTransform.Microsoft.GradientWipe(duration=1)";
transitions[6] = "progid:DXImageTransform.Microsoft.Iris(Duration=1,motion=out)";
transitions[7] = "progid:DXImageTransform.Microsoft.Wheel(Duration=1,spokes=12)";
transitions[8] = "progid:DXImageTransform.Microsoft.Pixelate(maxSquare=10,duration=1)";
transitions[9] = "progid:DXImageTransform.Microsoft.RadialWipe(Duration=1,wipeStyle=clock)";
transitions[10] = "progid:DXImageTransform.Microsoft.RandomBars(Duration=1,orientation=vertical)";
transitions[11] = "progid:DXImageTransform.Microsoft.Slide(Duration=1,slideStyle=push)";
transitions[12] = "progid:DXImageTransform.Microsoft.RandomDissolve(Duration=1,orientation=vertical)";
transitions[13] = "progid:DXImageTransform.Microsoft.Spiral(Duration=1,gridSizeX=40,gridSizeY=40)";
transitions[14] = "progid:DXImageTransform.Microsoft.Stretch(Duration=1,stretchStyle=push)";
transitions[15] = "special case";
var transition_count = 15;
var photo_count ="<%=i%>";


if ( (is_ie && !is_ie4up) || (is_opera && !is_opera5up) || (is_nav && !is_nav6up)) {
document.location = slideShowLow;
}


var browserCanBlend = (is_ie5_5up);

function stopOrStart() {
if (onoff) {
stop();
} else {
play();
}
}

function fullOrNormal() {
images = new Array;
pics_loaded=0;
if (fullsized) {
normal();
} else {
full();
}
next_location = current_location;
preload_photo(next_location);
go_to_next_photo();
}

function toggleLoop() {
if (loop) {
loop = 0;
} else {
loop = 1;
}
}

function changeElementText(id, newText) {
element = document.getElementById(id);
element.innerHTML = newText;
}

function stop() {
changeElementText("stopOrStartText", "播放");

onoff = 0;
status = "幻灯秀已停止点击播放继续";
clearTimeout(timer);

}

function play() {
changeElementText("stopOrStartText", "停止");

onoff = 1;
status = "幻灯秀正在运行";
go_to_next_photo();
}

function full() {
changeElementText("fullOrNormalText", "小图");
fullsized = 1;
status = "The slide is showing full sized images, Click [normal size] to view resized images.";
}

function normal() {
changeElementText("fullOrNormalText", "大图");

fullsized = 0;
status = "The slide is showing normal sized images, Click [full size] to view full sized images.";
}

function changeDirection() {
if (direction == 1) {
direction = -1;
changeElementText("changeDirText", "往后");
} else {
direction = 1;
changeElementText("changeDirText", "往前");
}
preload_next_photo();

}

function change_transition() {
current_transition = document.ShowFile.transitionType.selectedIndex;
}

function preload_complete() {
}

function reset_timer() {
clearTimeout(timer);
if (onoff) {
timeout_value = document.ShowFile.time.options[document.ShowFile.time.selectedIndex].value * 1000;
timer = setTimeout('go_to_next_photo()', timeout_value);
}
}

function wait_for_current_photo() {


if (!show_current_photo()) {



status = "正在载入(" + current_location + " of" + photo_count +
"). " + "请稍候..." ;
clearTimeout(timer);
timer = setTimeout('wait_for_current_photo()', 500);
return 0;
} else {
status = "幻灯秀正在运行..." ;
preload_next_photo();
reset_timer();
}
}

...全文
138 10 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
105910556 2004-07-12
  • 打赏
  • 举报
回复
可否写出具体代码
105910556 2004-07-12
  • 打赏
  • 举报
回复
怎么过滤?
xinshaw 2004-07-12
  • 打赏
  • 举报
回复
过滤文件名的后缀呀
105910556 2004-07-12
  • 打赏
  • 举报
回复
在选取文件时,就过滤掉! 可否写出具体代码

你生成数组的时候值生成图片的啊。 可否写出具体代码
你不会判断一个文件是否是图片吗?

105910556 2004-07-12
  • 打赏
  • 举报
回复
在选取文件时,就过滤掉! 可否写出具体代码

你生成数组的时候值生成图片的啊。 可否写出具体代码
你不会判断一个文件是否是图片吗?
105910556 2004-07-12
  • 打赏
  • 举报
回复
孟哥帮我呀
孟子E章 2004-07-12
  • 打赏
  • 举报
回复
你生成数组的时候值生成图片的啊。
你不会判断一个文件是否是图片吗?
codeangel 2004-07-12
  • 打赏
  • 举报
回复
在选取文件时,就过滤掉!
105910556 2004-07-12
  • 打赏
  • 举报
回复
function go_to_next_photo() {

current_location = next_location;


if (!show_current_photo()) {
wait_for_current_photo();
return 0;
}

preload_next_photo();
reset_timer();
}

function preload_next_photo() {
var inc = parseInt(direction);

next_location = (parseInt(current_location) + inc);
if (next_location >= photo_count && inc>0) {
next_location = 0;
if (!loop) {
stop();
}
}
if (next_location < 0 && inc < 0) {
next_location = photo_count-1;
if (!loop) {
stop();
}
}


preload_photo(next_location);
}

function show_current_photo() {

if (!images[current_location] || !images[current_location].complete) {
preload_photo(current_location);
return 0;
}

if (browserCanBlend){
var do_transition;
if (current_transition == (transition_count)) {
do_transition = Math.floor(Math.random() * transition_count);
} else {
do_transition = current_transition;
}
document.images.slide.style.filter=transitions[do_transition];
document.images.slide.filters[0].Apply();
}
document.slide.src = images[current_location].src;
setCaption(photo_captions[current_location]);

if (browserCanBlend) {
document.images.slide.filters[0].Play();
}

return 1;
}

function preload_photo(index) {


if (pics_loaded < photo_count) {


if (!images[index]) {
images[index] = new Image;
images[index].onLoad = preload_complete();
if (fullsized) {
images[index].src = document.getElementById("full_photo_urls_" + index).href;
} else {
images[index].src = document.getElementById("photo_urls_" + index).href;
}
pics_loaded++;
}
}
}

function setCaption(text) {
ccc=current_location+1
changeElementText("caption", "[第" + ccc + " 幅,     一共"+ photo_count + " 幅] " );
}

</Script>
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="navtableborderbegin">
<table align="center" bgcolor="#BFCFE8" width="100%" border="0" cellspacing="0" cellpadding="0" class="modnavboxtop">
<tr>
<td align="center" >幻灯秀</td>
</tr>
</table>
</td>
</tr>

<tr>
<td class="navtableborderend">

<table width="100%" border="0" cellspacing="0" cellpadding="0" class="modnavboxmid">
<tr>

</tr>
<tr>

<td align="left" valign="middle">
<span class=admin>

 <a class="admin" href='#' onClick='stopOrStart(); return false;'>[<span id='stopOrStartText'>stop</span>]</a> <a class="admin" href='#' onClick='changeDirection(); return false;'>[<span id='changeDirText'>反方向</span>]</a> <a class="admin" href='#' onClick='fullOrNormal(); return false;'>[<span id='fullOrNormalText'>大图</span>]</a>  
 时间延迟: <select name="time" size=1 style="font-size:12px;" onchange="reset_timer()" style="font-size:10px;">
<option value=0.5 >0.5 秒</option>
<option value=0.7 >0.7 秒</option>
<option value=1 >1 秒</option>
<option value=2 >2 秒</option>
<option value=3 selected>3 秒</option>
<option value=4 >4 秒</option>
<option value=5 >5 秒</option>
<option value=6 >6 秒</option>
<option value=7 >7 秒</option>
<option value=8 >8 秒</option>
<option value=9 >9 秒</option>
<option value=10 >10 秒</option>
<option value=12 >12 秒</option>
<option value=15 >15 秒</option>
<option value=18 >18 秒</option>
<option value=20 >20 秒</option>
<option value=25 >25 秒</option>

</select>

  循环播放:<input type="checkbox" name="loopCheck" onclick='toggleLoop();'>
</span>
</td>

</tr>
<tr>

</tr>
</table>
</td>
</tr>
</table>

<br>
<table width=1% border=0 cellspacing=0 cellpadding=0>
<tr bgcolor="#808080">
<script language="JavaScript">
firstPhotoURL = document.getElementById("photo_urls_" + 0).href;
document.write("<td><img border=0 src=\"");
document.write(firstPhotoURL);
document.write("\" name=slide></td>");
</script>

</tr>
<tr>
</tr>
<tr bgcolor="#808080">

</tr>
</table>
<div align="center">


<script language="Javascript">
/* show the caption */
document.write("<div class='modcaption' id='caption'></div>");

/* Load the first picture */
setCaption(photo_captions[0]);
preload_photo(0);

/* Start the show. */
play();

</script>
</div>
</td>
</tr>
</table>
105910556 2004-07-12
  • 打赏
  • 举报
回复
up

111,097

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧