成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

Silverlight實現簡單鼠標手勢控制頁面滾動

開發 后端
看了MSDN的WebCast的《用Silverlight實現簡單鼠標手勢控制頁面滾動》視頻,筆者就他的講述寫出了一個小例子。希望對大家有所幫助。。

[[5264]]

上圖藍色部分就是鼠標手勢控制的部分,劃過這塊區域,瀏覽器的滾動條就會做出相應的反應。我寫的這個程序只能適合在IE,Firefox我測試了一下沒有反應,其他瀏覽器我并沒有進行測試。

這個程序的設計目標:用Silverlight實現一個浮動在頁面右下角的鼠標手勢控制塊,讓用戶用鼠標手勢控制頁面滾動,提供更好的用戶瀏覽體驗。

鼠標手勢設計計劃:

1.制作一個浮動DIV,承載Silverlight。

2.實現鼠標移動方向與速度識別

3.調用js控制scrollbar

4.測試

鼠標手勢詳細步驟:

1.制作一個浮動DIV,承載Silverlight。

Code
 1<div id="silverlightControlHost">
 2  <object data="data:application/x-silverlight-2,"
       type="application/x-silverlight-2" width="100%" height="100%">
 3              <param name="source" value="ClientBin/Scoll.xap"/>
 4              <param name="onerror" value="onSilverlightError" />
 5              <param name="background" value="blue" />
 6              <param name="minRuntimeVersion" value="3.0.40624.0" />
 7      <param name="autoUpgrade" value="true" />
 8     <param name="windowless" value"true" />
 9    <a href="
       style="text-decoration: none;">
10   <img src="
      alt="獲取 Microsoft Silverlight" style="border-style: none"/>
11              </a>
12          </object>
<iframe id="_sl_historyFrame" style='visibility:hidden;height:0;width:0;border:0px'>
</iframe></div>
用id為silverlightControlHost的DIV來承載Silverlight。用下面的js代碼來使div浮動:
 

Code
 1 <script  type ="text/javascript">
 2      function Pos(w, h) {
 3          var silverdiv = document.getElementById("silverlightControlHost");
 4          silverdiv.style.width = w;
 5          silverdiv.style.height = h;
 6          silverdiv.style.position = "absolute";
 7          silverdiv.style.zIndex = 100;
 8          silverdiv.style.top =
 9            document.documentElement.scrollTop + document.documentElement.clientHeight - h;
10          silverdiv.style.left =
11            document.documentElement.scrollLeft + document.documentElement.clientWidth - w;
12         
13      }
14  </script>
15  <script type ="text/javascript">
16      Pos(60, 60);
17      window.onscroll = function() {
18          Pos(60, 60);
19      }
20  </script>

2.實現鼠標移動方向與速度識別

Code
 1 public MainPage()
 2        {
 3            InitializeComponent();
 4            timer.Completed += new EventHandler(timer_Completed);
 5        }
 6
 7        void timer_Completed(object sender, EventArgs e)
 8        {
 9            //throw new NotImplementedException();
10            if (Math.Abs(v_x) <= V_Min && Math.Abs(v_y) <= V_Min)
11            {
12                v_x = 0;
13                v_y = 0;
14                const_time = 0;
15                Current_Time = 0;
16            }
17            else
18            {
19                if (Current_Time < const_time)
20                {
21                    Current_Time++;
22                }
23                else
24                {
25                    if (Math.Abs(v_x) > V_Min)
26                    {
27                        v_x = Math.Sign(v_x) * (Math.Abs(v_x) - Math.Abs(dec));
28                    }
29                    if (Math.Abs(v_y) > V_Min)
30                    {
31                        v_y = Math.Sign(v_y) * (Math.Abs(v_y) - Math.Abs(dec));
32                    }
33                }
34                ScollBy(v_x, v_y);
35                timer.Begin();
36            }
37        }
38        //慣性計算
39        double dec = 0.3;
40        const double V_Min = 0.3;
41        double Current_Time = 0;
42
43
44        Point StartPoint;//開始點
45        Point EndPoint;//結束點
46        List<Point> TempPoints = new List<Point>();//點集合
47        bool IsRecording = true;//是否錄制
48        double v_x;
49        double v_y;
50        double const_time;
51        public Storyboard timer = new Storyboard() { Duration = new Duration(new TimeSpan(0, 0, 0, 0, 10)) };
52        //timer.Interval=10;
53       
54        private void MainInput_MouseMove(object sender, MouseEventArgs e)
55        {
56            if (IsRecording)
57            {
58                TempPoints.Add(e.GetPosition(null));
59            }
60        }
61
62        private void MainInput_MouseEnter(object sender, MouseEventArgs e)
63        {
64            P.Points.Clear();
65            P.Points.Add(e.GetPosition(null));
66            IsRecording = true;
67            StartPoint = e.GetPosition(null);
68            TempPoints.Clear();
69            TempPoints.Add(StartPoint);
70        }
71
72        private void MainInput_MouseLeave(object sender, MouseEventArgs e)
73        {
74            IsRecording = false;
75            EndPoint = TempPoints[TempPoints.Count - 1];
76            v_x = (StartPoint.X - EndPoint.X) / TempPoints.Count;
77            v_y = (StartPoint.Y - EndPoint.Y) / TempPoints.Count;
78            const_time = 100 / TempPoints.Count;
79            P.Points.Add(EndPoint);
80            timer.Stop();
81            timer.Begin();
82        }

3.調用js控制scrollbar

Code
1public void ScollBy(double x, double y)
2        {
3            //window.scollBy(x,y);
4            //直接調用js
5  System.Windows.Browser.HtmlPage.Window.Eval
(string.Format("window.scrollBy({0},{1});",x,y));
6        }
4.測試。

以上就可以完成這樣的一個功能了。

【編輯推薦】

  1. Office 2010將使用Silverlight改善用戶體驗
  2. 微軟.NET平臺主管談Silverlight企業級開發
  3. Flash與Silverlight多領域實測對比
  4. 微軟宣稱Silverlight裝機量超過三億
  5. 圖解Silverlight 3的7個新功能
責任編輯:彭凡 來源: 博客園
相關推薦

2010-01-04 14:06:35

Silverlight

2020-12-09 07:54:17

Vue插件鼠標

2010-01-18 18:50:26

VB.NET鼠標手勢

2010-01-04 14:14:43

Silverlight

2009-12-30 10:44:38

Silverlight

2011-07-22 13:30:52

JavaScript

2009-09-02 18:53:28

C#鼠標坐標

2009-07-27 09:46:28

Silverlight

2009-12-30 15:58:19

Silverlight

2009-06-02 10:10:15

C#

2009-12-31 10:43:48

Silverlight

2011-03-14 13:10:43

jQueryscroll滾動

2009-04-02 08:49:20

Opera瀏覽器表情控制

2021-06-18 10:12:09

JS代碼前端

2009-12-30 18:28:56

Silverlight

2009-12-31 11:23:23

Silverlight

2009-12-30 15:42:08

Silverlight

2010-03-02 13:06:22

SilverLight

2011-12-20 14:39:57

傲游手機瀏覽器

2024-10-10 09:55:51

JavaScript參數瀏覽器
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 久久精品日 | 国产一区二区三区在线 | 国产精品久久久久久久久久久久久 | 国产做a爱片久久毛片 | 这里只有精品99re | 欧美日韩激情 | 一区二区三区中文字幕 | 国产中文字幕在线观看 | 久久网一区二区 | 欧美一区永久视频免费观看 | 天天爱综合| aaa精品| 中文字幕高清在线 | 精品乱码一区二区 | 午夜精品91 | 一级毛片观看 | 一区二区三区四区在线视频 | 久久99久久99精品免视看婷婷 | 日韩精品久久久久 | 中文在线日韩 | 黄免费在线| 国产精品亚洲视频 | 亚洲欧美日本在线 | 亚洲午夜av | 亚州精品成人 | 欧美黄色片 | 免费激情网站 | 欧美精品91爱爱 | 久久久久久久久99 | 伊人亚洲 | 亚洲精品第一 | 日韩欧美一区二区三区免费看 | 天天看天天操 | 美国黄色毛片 | 亚洲精品一区中文字幕乱码 | 一区二区三区国产精品 | 午夜视频在线免费观看 | 久久久国产精品一区 | 九九久久精品 | 99国产精品久久久 | 日韩视频区 |