2011-07-21 69 views

回答

1

到目前爲止您嘗試過什麼?

你可以做這樣BTW:

設置裏面你parent tippable元素data-attribute存儲URL(檢索由AJAX工具提示需要),即:

<div class="tippable" data-tipurl="/some/url/"> 
    when I mouseover here, a tip appears 
</div> 

然後,通過JS,創建和緩存提示即:

$$('div.tippable').each(function(tippable){ 

    tippable.addEvents({ 

     'mouseenter' : function(){ 

      if(!this.retrieve('tip')){ //first time, build tip! 

       var tip = new Element('div.tip'); 

       tip.set('load',{/* options */}); 

       tip.load(this.get('data-tipurl')); //get through ajax 

       tip.inject(this, 'top').setStyles({ //set tip style 
        position : 'absolute' 
        /* etc... */ 
       }); 

       this.store('tip', tip); //store it inside the parent 

      }else{ // already built, just show it 

       this.retrieve('tip').setStyle('display', 'block'); 
      } 
     }, 

     'mouseleave' : function(){ 
      var tip = this.retrieve('tip'); //retrieve the tip 

      if(tip){ //if it's already built, hide it 
       tip.setStyle('display','none'); 
      } 

      //otherwise, do nothing 
     } 

    }); 
}); 
+0

感謝您的回覆。讓我試試 – abhis

+0

請注意,您可以使用MooTools的Tips類。 –

+0

@Kyathi歡迎您;)@ @奧斯卡,這只是建立'ajax工具提示系統'的起點;) – stecb