创建工具提示

在浏览Netflix时,当把鼠标停在一个影片的图片上时,就会看到更多关于该影片的信息。我们来模拟一下

它的功能:

1、创建一个ASP.NET AJAX Control Toolkit Website

2、Default.aspx的完整代码:

    < html  xmlns ="http://www.w3.org/1999/xhtml"   >    
   
< head  runat ="server" >
      
< title > Untitled Page </ title >     
   
</ head >
    
< body >
        
< form  id ="form1"  runat ="server" >
        
< asp:ScriptManager  ID ="ScriptManager1"  runat ="server"   />
       
< table >
           
< tr >
               
< td >< img  id ="0-0"  src ="Image1.gif"   /></ td >
               
< td >< img  id ="0-1"  src ="Image2.gif"   /></ td >
           
</ tr >
      
</ table >
       
< div  id ="DataPanel"  style ="display:none; position:absolute; left:0px; top:0px;"   />
       
</ form >
   
</ body >
   
< script  language ="javascript" >
  Type.registerNamespace(
"Test");
   
   
var main = null;
   
   Test.Main 
= function(rows, columns) {        
       
this._columns = columns;    
       
this._dataPanel = null;
       
this._imageMouseOverHandler = null;
       
this._imageMouseOutHandler = null;
       
this._rows = rows;
   }

   Test.Main.prototype 
= {
        dispose : 
function() {        
          
for(var i = 0; i < this._rows; i++)
               
for(var j = 0; j < this._rows; j++{
                  image 
= $get(i + "-" + j);
                   $removeHandler(image, 
"mouseover"this._imageMouseOverHandler);
                   $removeHandler(image, 
"mouseout"this._imageMouseOutHandler);
               }

           
delete this._imageMouseOverHandler;
           
delete this._imageMouseOutHandler;
                       
           Test.Main.callBaseMethod(
this"dispose");
       }
,
       
       _getXCoord : 
function(element) {
           
var x = 0;
          
while(element){
               x 
+= element.offsetLeft;
              element 
= element.offsetParent;
          }

          
return x;
      }
,
  
       _getYCoord : 
function(element) {
          
var y = 0;
           
while(element){
               y 
+= element.offsetTop;
               element 
= element.offsetParent;
           }

           
return y;
       }
,
      
       _image_OnMouseOver : 
function(args) {        
          
switch(args.target.id) {
               
case "0-0":
                   
this._dataPanel.innerText = "This is the first image.";
                  
break;
              
case "0-1":
                  
this._dataPanel.innerText = "This is the second image.";
                   
break;
          }
        
           
this._dataPanel.style.left = this._getXCoord(args.target) + args.target.offsetWidth + "px";
           
this._dataPanel.style.top = this._getYCoord(args.target) + "px";
          
this._dataPanel.style.display = "block";
       }
,
       
      _image_Out : 
function(args) {
           
this._dataPanel.style.display = "none";
       }
,
       
       initialize : 
function() {
           Test.Main.callBaseMethod(
this"initialize");                
           
           
var image = null;        
           
           
this._dataPanel = $get("DataPanel");   
           
           
this._imageMouseOverHandler = Function.createDelegate(thisthis._image_OnMouseOver);
          
this._imageMouseOutHandler = Function.createDelegate(thisthis._image_Out);
           
           
for(var i = 0; i < this._rows; i++)
               
for(var j = 0; j < this._columns; j++{
                  image 
= $get(i + "-" + j);
                $addHandler(image, 
"mouseover"this._imageMouseOverHandler);
                   $addHandler(image, 
"mouseout"this._imageMouseOutHandler);
               }

       }

   }

  Test.Main.registerClass(
"Test.Main", Sys.Component);
   
   
function pageLoad() {
      main 
= new Test.Main(12);
      main.initialize();
  }

  
</ script >
  
</ html >

 

3、随便copy 图片Image1.gif 和Image2.gif 放在application根目录下。核心功能就算完成了,可以根据

需要改进!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值