jquery.htselect.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. /**可拖拽div插件,可与zTree的拖拽树配合使用**/
  2. ;(function($){
  3. $.fn.htselect=$.fn.htSelect=function(options){
  4. options=$.extend({
  5. divClass:'itemDiv',
  6. over:function(){
  7. var pad_top = $(this).position().top,//获取匹配元素相对父元素的偏移
  8. pad_left = $(this).position().left,
  9. t = $("div",$(this));
  10. t.show();
  11. t.animate({top:pad_top+15,left:pad_left},100);
  12. },
  13. out:function(){
  14. var t = $("div",$(this));
  15. t.animate({top:'0'},30,function(){t.hide();});
  16. }
  17. },options);
  18. return this.each(function(){
  19. var me = $(this),
  20. ul = me.children("ul");
  21. //alert(me.offset().left);
  22. //html = ['<div style="position:absolute;top:50px;right:165px;" class="'];
  23. html = ['<div style="position:absolute;top:50px;left:'+me.offset().left+'px;" class="'];
  24. //if(!ul)return;
  25. if(ul.length==0)return;
  26. ul.remove();
  27. html.push(options.divClass);
  28. html.push('">');
  29. html.push(ul[0].outerHTML);
  30. html.push('</div>');
  31. me.append(html.join(''));
  32. me.mouseover(function(){options.over.call(me);}).mouseleave(function(){options.out.call(me);});
  33. });
  34. };
  35. })(jQuery);