捕获silverlight滚轮事件
silverlight小技巧
捕获silverlight滚轮事件
- 在页面初始化时添加代码
- HtmlPage.Window.AttachEvent("DOMMouseScroll", OnMouseWheel);
- HtmlPage.Window.AttachEvent("onmousewheel", OnMouseWheel);
- HtmlPage.Document.AttachEvent("onmousewheel", OnMouseWheel);
- Mozilla/Safari浏览器监听detail属性,IE/Opera浏览器监听wheelDelta属性
private void OnMouseWheel(object sender, HtmlEventArgs args)
{
double mouseDelta = 0;
ScriptObject e = args.EventObject;
// Mozilla and Safari
if (e.GetProperty("detail") != null)
{
mouseDelta = ((double)e.GetProperty("detail"));
} // IE and Opera
else if (e.GetProperty("wheelDelta") != null)
{
mouseDelta = ((double)e.GetProperty("wheelDelta"));
}
mouseDelta = Math.Sign(mouseDelta);
}
{
double mouseDelta = 0;
ScriptObject e = args.EventObject;
// Mozilla and Safari
if (e.GetProperty("detail") != null)
{
mouseDelta = ((double)e.GetProperty("detail"));
} // IE and Opera
else if (e.GetProperty("wheelDelta") != null)
{
mouseDelta = ((double)e.GetProperty("wheelDelta"));
}
mouseDelta = Math.Sign(mouseDelta);
}