Atlas学习手记(23):使用行为增强用户界面(三):Hover Behavior

Hover Behavior提供了对DHTML的事件onmouseover,onmouseout,onfocus以及onblur的处理。

主要内容

1.Hover Behavior简介

2.完整示例

一.Hover Behavior简介

Hover Behavior提供了对DHTML的事件onmouseover,onmouseout,onfocus以及onblur的处理。简单示例代码:

<hoverBehavior

    
dataContext="source for data binding operations"

    hoverElement
="ID of element the hover behavior is attached to"

    id
="identifier for looking up the component by name"

    propertyChanged
="event handler"

    unhoverDelay
="0|delay before unhover event in ms"

> 

    
<bindings>

        
<!-- bindings -->

    
</bindings>

    
<hover>

        
<!-- actions -->

    
</hover>

    
<propertyChanged>

        
<!-- actions -->

    
</propertyChanged>

    
<unhover>

        
<!-- actions -->

    
</unhover>

</hoverBehavior>

二.完整示例

看一个完整的示例,新建Atlas Web Site后,在ASPX页面中放一个Div,当鼠标移动到它上面时背景颜色变为浅绿色:

<div>

 
<h3 style="text-decoration:underline">Hover Behavior Example</h3>

        
<div id="panel2">This element is associated to the hoverBehavior.</div>

</div>

然后编写Atlas脚本,这里也用到了setProperty这个Action,来为控件添加CSS样式,还有注意一下unhoverDelay属性,设置延迟时间

<script type="text/xml-script">

    
<page xmlns:script="http://schemas.microsoft.com/xml-script/2005">

        
<components><control id="panel2" cssClass="start">

                
<behaviors>

                    
<hoverBehavior unhoverDelay="500">

                        
<hover>

                            
<setProperty target="panel2" property="cssClass" value="hover"/>

                        
</hover>

                        
<unhover>

                            
<setProperty target="panel2" property="cssClass" value="start"/>

                        
</unhover>

                    
</hoverBehavior>

                
</behaviors>

            
</control>

        
</components>

    
</page>

</script>

用到的CSS样式如下:

<style type="text/css">

    .start
{background-color:lightyellow;

        border
:dashed 2px black;}


    .hover
{font-size:20pt;

        background-color
:lightgreen;

        border
:dashed 2px black;}


</style>

编译运行后如下:

移动鼠标到上面:

移开鼠标后:

完整示例下载

posted on   秋天  阅读(177)  评论(0编辑  收藏  举报

编辑推荐:
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构

导航

< 2008年3月 >
24 25 26 27 28 29 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示