• Sharepoint 2010 实现图片新闻轮播


    项目需要实现图片轮播的效果,没找到资料,自己上网找了一个物效,然后自己整合进sharepoint 2010,不说废话,下面是源码:

    photoNewsUserControl.ascx

    <div>

    <% photo(); %>

    <script type="text/javascript">

        var pic_width = 420; //图ª?片?宽¨ª度¨¨ 420*280

        var pic_height = 260; //图ª?片?高?度¨¨

        var text_height = 30; //文?字Á?高?度¨¨

        var swfpath = '/_layouts/images/flashFocus01.swf'; //swf文?件t路¡¤径?地Ì?址¡¤

        var swf_height = pic_height + text_height;

        var pics = "", links = "", texts = "";

        for (var i = 0; i < 3; i++) {

            pics = pics + ("|" + imag[i]);

            links = links + ("|" + link[i]);

            texts = texts + ("|" + text[i]);

        }

        pics = pics.substring(1);

        links = links.substring(1);

        texts = texts.substring(1);

        document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="' + pic_width + '" height="' + swf_height + '">');

        document.write('<param name="allowScriptAccess" value="sameDomain"><param name="movie" value="' + swfpath + '"><param name="quality" value="high"><param name="bgcolor" value="#E1F2FF">');

        document.write('<param name="menu" value="false"><param name=wmode value="opaque">');

        document.write('<param name="FlashVars" value="pics=' + pics + '&links=' + links + '&texts=' + texts + '&borderwidth=' + pic_width + '&borderheight=' + pic_height + '&textheight=' + text_height + '">');

        document.write('<embed src="' + swfpath + '" wmode="opaque" FlashVars="pics=' + pics + '&links=' + links + '&texts=' + texts + '&borderwidth=' + pic_width + '&borderheight=' + pic_height + '&textheight=' + text_height + '" menu="false" bgcolor="#FFFFFF" quality="high" width="' + pic_width + '" height="' + pic_height + '" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');

        document.write('</object>');

    </script>

    </div>

    photoNewsUserControl.ascx.cs

     

    namespace SharePointProject.photoNews

    {

        public partial class photoNewsUserControl : UserControl

        {

            protected void Page_Load(object sender, EventArgs e)

            {

     

            }

            public void photo()

            {

                try

                {

                    SPSite manageSite = null;

                    SPWeb manageWeb = null;

                    SPSecurity.RunWithElevatedPrivileges(delegate

                    {

                        using (manageSite = new SPSite(SPContext.Current.Site.ID))

                        {

                            using (manageWeb = manageSite.OpenWeb(manageSite.RootWeb.ID))

                            {

                                SPList list = manageWeb.GetList("Lists/List2");

                                SPQuery myQuery = new SPQuery();

                                myQuery.Query = "<Where><Contains><FieldRef Name='_x5185__x5bb9_' /><Value Type='Note'>img</Value></Contains></Where><OrderBy><FieldRef Name='Modified' Ascending='False' /></OrderBy>";

                                myQuery.RowLimit = 3;

                                SPListItemCollection spc = list.GetItems(myQuery);

                                DataTable dt = spc.GetDataTable();

                                if (dt.Rows.Count > 0)

                                {

                                    string str = "";

                                    for (int i = 0; i < dt.Rows.Count; i++)

                                    {

                                        string[] imag = new string[3];

                                        string[] link = new string[3];

                                        string[] text = new string[3];

                                        imag[i] = getImgUrl(dt.Rows[i]["_x5185__x5bb9_"].ToString());

                                        link[i] = "http://" + Request.Url.Authority + "/pages/listdetail.aspx?picid=" + dt.Rows[i]["ID"].ToString();

                                        text[i] = dt.Rows[i]["title"].ToString().Length > 10 ? dt.Rows[i]["title"].ToString().Substring(0, 10) + "..." : dt.Rows[i]["title"].ToString();

                                        str += "imag[" + i + "]='" + imag[i] + "';";

                                        str += "link[" + i + "]='" + link[i] + "';";

                                        str += "text[" + i + "]='" + text[i] + "';";

     

                                    }

                                    string abc = "<script language='javascript'>";

                                    abc += "var imag=new Array();var link=new Array();var text=new Array();";

                                    abc += str;

                                    abc += "</script>";

                                    Response.Write(abc);

                                }

                            }

                        }

     

                    });

                    

                }

                catch { }

            }

     

            public string getImgUrl(string html)

            {

                string url = "";

                Regex reg = new Regex(@"(?i)<img[^>]*?src=(['""]?)([^'""s>]+)1[^>]*>");

                Match m = reg.Match(html);

                if (m.Success)

                {

                    if (m.Groups[2].Value.Contains("http"))

                    {

                        url = m.Groups[2].Value;

                    }

                    else

                    {

                        url = "http://" + Request.Url.Authority + m.Groups[2].Value;

                    }

                }

                return url;

            }

        }

    }

    效果如下:

     

     

    说明 :你输出的数组大小就是显示的图片数量

  • 相关阅读:
    空气墙的制作,标签的添加
    子弹朝向问题的解决,移动方法的编写
    子弹的朝向问题
    坦克的攻击方法
    移动优先级的添加,2D渲染层级问题
    碰撞器的添加,解决抖动问题
    控制图片的移动切换
    控制玩家的移动
    游戏中预制体的制作,2D动画的制作
    场景搭建,素材的处理
  • 原文地址:https://www.cnblogs.com/rimtd/p/3284453.html
Copyright © 2020-2023  润新知