0

这里先加载图像,然后再完成滑动图像。因为动态图像被放置在 div 中。加载 div。之后,图像被一张一张地滑动 SlidePicture() 函数我希望在页面被引用时完成滑动图像

代码:

        <html xmlns="http://www.w3.org/1999/xhtml">
        <head id="Head1" runat="server">
            <title></title>
            <script src="Scripts/jquery-1.7.1.js" type="text/javascript"></script>
            <style type="text/css">
                body
                {
                    margin: 0px;
                    padding: 0px;
                }
                #divSlideShow
                {
                    position: absolute;
                    height: 500px;
                    padding: 30px 20px 60px 20px;
                    width: 1500px;
                }


                #divSlideShow IMG
                {
                    position: absolute;
                    top: 0;
                    left: 0;
                    z-index: 8;
                }

                #divSlideShow IMG.active
                {
                    z-index: 10;
                }

                #divSlideShow IMG.last-active
                {
                    z-index: 9;
                }
                .ImageClass
                {
                    padding: 50px 100px 50px 220px;
                    width: 600px;
                    height: 400px;
                }
            </style>
            <script type="text/javascript">
                function GetData() 
                {

                    var dynamicDiv = document.createElement('div');
                    dynamicDiv.setAttribute('Id', 'divSlideShow');
                    setTimeout("showIt()", 100000);
                    var fileNamesData = document.getElementById('hdnFileNames').value.split('‡');
                    for (var i = 0; i < fileNamesData.length - 1; i++) 
                    {
                        var dynamicImg = document.createElement('img');
                        dynamicImg.setAttribute("src", "Images/" + fileNamesData[i]);
                        dynamicImg.setAttribute("class", "ImageClass");
                        // document.getElementById('divSlideShow').appendChild(dynamicImg);
                        dynamicDiv.appendChild(dynamicImg);
                    }

                    document.getElementById('form2').appendChild(dynamicDiv);
                }
                function showIt() {
                    document.getElementById("divSlideShow").style.visibility = "none";
                }
                $(function () {
                    setInterval("slidePictures()", 5000);
                });

            function slidePictures() {
                var $active = $('#divSlideShow IMG.active');
                //if ($active.length == 0) $active = $('#divSlideShow IMG:last');
                var $next = $active.next().length ? $active.next() : $('#divSlideShow IMG:first');
                $active.addClass('last-active');
                $next.css({ opacity: 0.0 })
                .addClass('active')
                .animate({ opacity: 10.0 }, 1000, function () {
                    $active.removeClass('active last-active');
                });
            }
            </script>
        </head>
        <body onload="GetData()">
            <form id="form2" runat="server">
            <label id="lblImage"></label>
            <asp:HiddenField ID="hdnFileNames" runat="server" />

            </form>
        </body>
        </html>


.cs:
----
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;

namespace JquerySlideShow
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            var data="";
            string[] fileName = Directory.GetFiles(@"D:\Experiments\Jquery\JquerySlideShow\JquerySlideShow\Images");//D:\Experiments\Jquery\JquerySlideShow\JquerySlideShow\Images
            foreach (var path in fileName)
            {
                 data += (System.IO.Path.GetFileName(path)+"‡");
            }
            hdnFileNames.Value = data;   
        }
    }
}


    Anyone help me.
4

2 回答 2

0

试试这个 jQUery 插件。-jQuery Cycle
http://jquery.malsup.com/cycle/

于 2012-11-09T12:25:33.193 回答
0

抱歉,我无意冒犯,但您的帖子很难理解。我假设您希望加载图像,然后设置动画,并且当页面刷新时您不希望幻灯片再次发生?

如果是这种情况,您可以使用第二个 ASP 隐藏字段,并在动画完成后向其写入一个值。下次页面回发时,该值将保留在视图状态中,并且不会发生动画。

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="Javascripts/jquery-1.7.2.min.js"></script>
<style type="text/css">
body {
    margin: 0px;
    padding: 0px;
}
#divSlideShow {
    position: absolute;
    height: 500px;
    padding: 30px 20px 60px 20px;
    width: 1500px;
}
#divSlideShow IMG {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 8;
}
#divSlideShow IMG.active {
    z-index: 10;
}
#divSlideShow IMG.last-active {
    z-index: 9;
}
.ImageClass {
    padding: 50px 100px 50px 220px;
    width: 600px;
    height: 400px;
}
</style>
<script type="text/javascript">
                function GetData() 
                {

                    var dynamicDiv = document.createElement('div');
                    dynamicDiv.setAttribute('Id', 'divSlideShow');
                    setTimeout("showIt()", 100000);
                    var fileNamesData = document.getElementById('hdnFileNames').value.split('‡');
                    for (var i = 0; i < fileNamesData.length - 1; i++) 
                    {
                        var dynamicImg = document.createElement('img');
                        dynamicImg.setAttribute("src", "Images/" + fileNamesData[i]);
                        dynamicImg.setAttribute("class", "ImageClass");

                        dynamicDiv.appendChild(dynamicImg);
                    }

                    document.getElementById('form2').appendChild(dynamicDiv);
                }
                function showIt() {
                    document.getElementById("divSlideShow").style.visibility = "none";
                }
                $(function () {
                    setInterval("slidePictures()", 5000);
                });

            function slidePictures() {
                var $active = $('#divSlideShow IMG.active'),
                    slideState = jQuery("#hdnSlideState");

                    if (slideState.val() == "") {           

                        var $next = $active.next().length ? $active.next() : $('#divSlideShow IMG:first');
                        $active.addClass('last-active');
                        $next.css({ opacity: 0.0 })
                        .addClass('active')
                        .animate({ opacity: 10.0 }, 1000, function () {
                            $active.removeClass('active last-active');


                            jQuery("#hdnSlideState").val("noMoreSliding");


                        });

                    }
            }
            </script>
</head>
<body onload="GetData()">
<form id="form2" runat="server">
        <label id="lblImage"></label>
        <asp:HiddenField ID="hdnFileNames" runat="server" />
        <asp:HiddenField ID="hdnSlideState" runat="server" value="" clientIDmode="static" />
</form>
</body>
</html>
于 2012-11-09T12:57:15.870 回答