惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

宝玉的分享
宝玉的分享
NISL@THU
NISL@THU
E
Exploit-DB.com RSS Feed
L
LINUX DO - 热门话题
L
Lohrmann on Cybersecurity
K
Kaspersky official blog
Project Zero
Project Zero
Cisco Talos Blog
Cisco Talos Blog
T
The Exploit Database - CXSecurity.com
P
Palo Alto Networks Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
T
Threatpost
S
Schneier on Security
G
GRAHAM CLULEY
The Hacker News
The Hacker News
T
Threat Research - Cisco Blogs
Scott Helme
Scott Helme
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
P
Privacy & Cybersecurity Law Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
Cyberwarzone
Cyberwarzone
C
CERT Recently Published Vulnerability Notes
T
Tor Project blog
AWS News Blog
AWS News Blog
Simon Willison's Weblog
Simon Willison's Weblog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
爱范儿
爱范儿
P
Privacy International News Feed
云风的 BLOG
云风的 BLOG
P
Proofpoint News Feed
S
Securelist
G
Google Developers Blog
The Last Watchdog
The Last Watchdog
Google Online Security Blog
Google Online Security Blog
美团技术团队
F
Fortinet All Blogs
小众软件
小众软件
Recorded Future
Recorded Future
V
Visual Studio Blog
B
Blog RSS Feed
H
Help Net Security
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Google DeepMind News
Google DeepMind News
Blog — PlanetScale
Blog — PlanetScale
博客园 - 聂微东
Stack Overflow Blog
Stack Overflow Blog
Martin Fowler
Martin Fowler
Latest news
Latest news
Spread Privacy
Spread Privacy
H
Heimdal Security Blog

博客园 - 余墨

基金投资的三种阵型 用javascript操作xml - 余墨 - 博客园 Ajax+GridView+Xml的简易留言薄 - 余墨 - 博客园 ajax技术制作得在线歌词搜索功能 - 余墨 - 博客园 javascript实现datagrid客户端checkbox列的全选,反选 [经典推荐]事半功倍系列之javascript - 余墨 - 博客园 经典推荐--.Net面试法宝(面试题收集) DataGrid自动编号之黄金版 - 余墨 - 博客园 Ajax简单客户登陆验证 一個Ajax.NET的查詢實例 asp.net常用函数 XMLHTTP---简单介绍 XMLHttp常用属性,方法,成员 下拉菜单遮挡层的解决方案 AJAX编写用户注册实例及技术小结 XMLHTTP使用 判断用户什么时候离开,以什么方式离开 将js文件编译成动态链接库(dll)文件 Ajax程序中,自己实现页面前进、后退、与标签功能(asp.net2.0)
Ajax无刷新实现图片切换特效
余墨 · 2007-03-15 · via 博客园 - 余墨

一、AjaxMethod

using System;
using System.Data;
using System.Data.SqlClient;

namespace AjaxImage
{
    
/// <summary>
    
/// AjaxMethod 的摘要说明。
    
/// </summary>

    public class AjaxMethod
    
{
        
public AjaxMethod()
        
{            
        }

        
public static string ConnectionString = System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"].ToString();

        
GetDataSet

        [AjaxPro.AjaxMethod]
        
public static DataSet GetPhotoList( int iCategoryID )
        
{
            
string sql = "Select id,photo_path FROM Photo where photo_category_id=" + iCategoryID ;
            
return GetDataSet( sql );
        }

        [AjaxPro.AjaxMethod]
        
public static DataSet GetPhotoInfo( int id )
        
{
            
string sql = string.Format("SELECT photo_title, photo_description FROM Photo WHERE id = {0}", id);
            
return GetDataSet( sql );
        }


    }
//end class
}

二、页面HTML代码:

<div id="Layer1" style="Z-INDEX:1; LEFT:104px; WIDTH:501px; POSITION:absolute; TOP:28px; HEIGHT:345px">
                
<img name="slideShow" src="images/space.gif" width="500" height="300" style="FILTER:revealTrans(duration=2,transition=23)">
            
</div>
            
<div id="Layer2" style="Z-INDEX:2; LEFT:490px; WIDTH:112px; POSITION:absolute; TOP:380px; HEIGHT:26px">
                
<img id="btnPlay" src="images/play_bw.gif" onclick="slideshow_automatic()" onmouseover="this.src='images/play.gif'"
                    onmouseout
="this.src='images/play_bw.gif'"> <img id="btnPause" src="images/pause_bw.gif" onclick="pauseSlideShow()" onmouseover="this.src='images/pause.gif'"
                    onmouseout
="this.src='images/pause_bw.gif'"> <img id="btnPrev" src="images/prev_bw.gif" onclick="previous_image()" onmouseover="this.src='images/prev.gif'"
                    onmouseout
="this.src='images/prev_bw.gif'"> <img id="btnNext" src="images/next_bw.gif" onclick="next_image()" onmouseover="this.src='images/next.gif';next_image()"
                    onmouseout
="this.src='images/next_bw.gif'">
            
</div>

三、JAVASCRIPT:

<script language="javascript" type="text/javascript">
            
// 定时器
            var timeDelay;
            
            
// 图片自动浏览时的时间间隔
            var timeInterval = 4000;
            
            
// Array对象,存储图片文件的路径
            var image;
            
            
// 当前显示的图片序号
            var num;
            
            
// 图片信息数据表
            var dt;
            
// 预加载图片信息
            function PreloadImage(iCategoryID)
            
{
                
// 采用同步调用的方式获取图片的信息                
                var ds = AjaxImage.AjaxMethod.GetPhotoList(iCategoryID).value;
                
                
// 如果返回了结果
                if (ds)
                
{
                    
// 判断数据表是否不为空
                    if (ds.Tables[0].Rows.length > 0)
                    
{
                        
// 返回的图片信息数据表
                        dt = ds.Tables[0];
                        
                        
// 用image对象存储图片的文件路径
                        image = new Array();
                        
                        
// 图片在Photos目录下
                        for (var i = 0; i < dt.Rows.length; i++)
                        
{
                            image[i] 
= "Photos/" + dt.Rows[i].photo_path;
                        }

                                    
                        
// imagePreload对象用于实现图片的预缓存
                        var imagePreload = new Array();
                        
for (var i = 0;i < image.length;i++)
                        
{
                            
// 通过新建Image对象,并将其src属性指向图片的URL
                            // 显现图片的预缓存
                            imagePreload[i] = new Image();
                            imagePreload[i].src 
= image[i];
                        }


                        
// 初始化一些变量
                        num = -1;
                        
//nStatus = 0x09;
                        
                        
// 加载第一张图片
                        next_image();                
                    }

                    
else // 分类下没有图片
                    {
                        alert(
"该目录下没有图片!");
                    }

                }
                
            }

            
// 实现图片切换时的效果
            function image_effects()
            
{
                
// Transition的值为0~23之间的随机数,代表24种切换效果
                // 具体值与效果之间的对应见MSDN
                document.slideShow.filters.revealTrans.Transition = Math.random() * 23;
                
                
// 应用并播放切换效果
                document.slideShow.filters.revealTrans.apply();
                document.slideShow.filters.revealTrans.play();
            }

            
function next_image()
            
{
                
// 当前图片的序号向后移动,如果已经是最后一张,
                // 则切换到第一张图片
                num++;
                num 
%= image.length;
                
                
// 图片的切换效果
                image_effects();
                
                
// 将<img>对象的src属性设置为当前num对应的路径
                // 切换图片的显示
                document.slideShow.src = image[num];                
            }

            
function previous_image()
            
{
                
// 当前图片的序号向后移动,如果已经是最后一张,
                // 则切换到第一张图片
                num += image.length - 1;
                num 
%= image.length;
                
                
// 图片的切换效果
                image_effects();
                
                
// 将<img>对象的src属性设置为当前num对应的路径
                // 切换图片的显示
                document.slideShow.src = image[num];                                
            
            }

            
function slideshow_automatic()
            
{
                
// 当前图片的序号向后移动,如果已经是最后一张,
                // 则切换到第一张图片
                num ++;
                num 
%= image.length;
                
                
// 图片的切换效果
                image_effects();
                
                
// 将<img>对象的src属性设置为当前num对应的路径
                // 切换图片的显示
                document.slideShow.src = image[num];
                timeDelay 
= setTimeout( "slideshow_automatic()",timeInterval );                
            }

            
// 停止自动播放
            function pauseSlideShow()
            
{
                
// 清除定时器,不再执行slideshow_automatic函数
                clearTimeout(timeDelay);
            }

        
</script>

四、在主页面的ONLOAD事件里面添加:

      onload="PreloadImage('2')"

五、WebConfig添加:
       <system.web>
       <httpHandlers>
            <add verb="*" path="*.ashx" type="AjaxPro.AjaxHandlerFactory,AjaxPro" />
     </httpHandlers>

      <configuration>
       <appSettings>
           <add key="ConnectionString" value="server=127.0.0.1;database=test;uid=sa;pwd=dfdf" /> 
       </appSettings>   
六、数据库脚本:

CREATE TABLE [Photo] (
    
[id] [int] IDENTITY (11NOT NULL ,
    
[photo_title] [varchar] (128) COLLATE Chinese_PRC_CI_AS NULL ,
    
[photo_description] [text] COLLATE Chinese_PRC_CI_AS NULL ,
    
[photo_category_id] [int] NULL ,
    
[photo_path] [varchar] (255) COLLATE Chinese_PRC_CI_AS NULL 
ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO