jquery-rockqipao.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /**
  2. rockqipao 提示气泡
  3. caratename:chenxihu
  4. caratetime:2014-09-02 17:00:00
  5. email:qqqq2900@126.com
  6. homepage:www.xh829.com
  7. */
  8. (function ($) {
  9. function rockqipao(element, options){
  10. var obj = element;
  11. var can = options;
  12. var rand = ''+parseInt(Math.random()*99999)+'';
  13. var me = this;
  14. this.rand = rand;
  15. //初始化
  16. this.init = function(){
  17. var s = '';
  18. var id = 'rockqipaoshowdiv_'+rand+'';
  19. var glid= obj.attr('id');
  20. s+='<div id="'+id+'" guanliid="'+glid+'" title="'+can.tip+'" style="position:absolute;z-index:8;left:5px;top:5px;width:'+can.width+'px;height:'+can.width+'px;background:'+can.bgcolor+';overflow:hidden;color:white;border-radius:'+(can.width*0.5)+'px;line-height:'+can.width+'px;cursor:pointer;font-size:12px" align="center">'+can.text+'</div>';
  21. $('body').append(s);
  22. $('#'+id+'').click(function(){
  23. can.click(this);
  24. });
  25. $('#'+id+'').mouseover(function(){
  26. me.setweizhi();
  27. });
  28. this.setweizhi();
  29. };
  30. this.setweizhi = function(){
  31. var off = obj.offset();
  32. var l = off.left+ can.left - can.width*0.5;
  33. var t = off.top + can.top-can.width;
  34. $('#rockqipaoshowdiv_'+rand+'').css({left:''+l+'px',top:''+t+'px'});
  35. }
  36. }
  37. $.fn.rockqipao = function(options){
  38. var defaultVal = {
  39. click:function(){},
  40. text:'',
  41. left:5,
  42. top:0,
  43. width:20,
  44. bgcolor:'#ff6600',
  45. tip:''
  46. };
  47. var can = $.extend({}, defaultVal, options);
  48. var clsa = new rockqipao($(this), can);
  49. clsa.init();
  50. return clsa;
  51. };
  52. })(jQuery);