在线QQ悬浮插件

8 篇文章 0 订阅
6 篇文章 0 订阅

http://vipshow.iteye.com/blog/1861281


http://jingyan.baidu.com/article/6181c3e0482621152ef153da.html


最近做网站需要在线QQ悬浮功能,且QQ是通过从数据库获取的集合。

下面例子为静态的QQ list集合。在此感谢 zhaizhai1988 的分享,对原文我做了相应的调整,代码看起来更整齐,而且我上传整个例子,供有需要的朋友下载,下载后直接就可以预览效果。

①js工具类 qqOnline.js

Js代码    收藏代码
  1. /** 
  2. * 
  3. *  qqOnline - Sonline 
  4. *  author:selina 
  5. * 
  6. **/  
  7. (function($) {  
  8.     $.fn.Sonline = function(options) {  
  9.         var opts = $.extend({}, $.fn.Sonline.defualts, options);  
  10.         $.fn.setList(opts); // 调用列表设置  
  11.         if (opts.DefaultsOpen == false) {  
  12.             $.fn.Sonline.close(opts.Position, 0);  
  13.         }  
  14.         // 展开  
  15.         $("#SonlineBox > .openTrigger").live("click"function() {  
  16.             $.fn.Sonline.open(opts.Position);  
  17.         });  
  18.         // 关闭  
  19.         $("#SonlineBox > .contentBox > .closeTrigger").live("click",  
  20.                 function() {  
  21.                     $.fn.Sonline.close(opts.Position, "fast");  
  22.                 });  
  23.         // Ie6兼容或滚动方式显示  
  24.         if ($.browser.msie && ($.browser.version == "6.0") && !$.support.style  
  25.                 || opts.Effect == true) {  
  26.             $.fn.Sonline.scrollType();  
  27.         } else if (opts.Effect == false) {  
  28.             $("#SonlineBox").css({  
  29.                 position : "fixed"  
  30.             });  
  31.         }  
  32.     }  
  33.     // plugin defaults  
  34.     $.fn.Sonline.defualts = {  
  35.         Position : "left",// left或right  
  36.         Top : 200,// 顶部距离,默认200px  
  37.         Effect : true// 滚动或者固定两种方式,布尔值:true或  
  38.         DefaultsOpen : true// 默认展开:true,默认收缩:false  
  39.         Qqlist : "" // 多个QQ用','隔开,QQ和客服名用'|'隔开  
  40.     }  
  41.     // 展开  
  42.     $.fn.Sonline.open = function(positionType) {  
  43.         var widthValue = $("#SonlineBox > .contentBox").width();  
  44.         if (positionType == "left") {  
  45.             $("#SonlineBox > .contentBox").animate({  
  46.                 left : 0  
  47.             }, "fast");  
  48.         } else if (positionType == "right") {  
  49.             $("#SonlineBox > .contentBox").animate({  
  50.                 right : 0  
  51.             }, "fast");  
  52.         }  
  53.         $("#SonlineBox").css({  
  54.             width : widthValue + 4  
  55.         });  
  56.         $("#SonlineBox > .openTrigger").hide();  
  57.     }  
  58.     // 关闭  
  59.     $.fn.Sonline.close = function(positionType, speed) {  
  60.         $("#SonlineBox > .openTrigger").show();  
  61.         var widthValue = $("#SonlineBox > .openTrigger").width();  
  62.         var allWidth = (-($("#SonlineBox > .contentBox").width()) - 6);  
  63.         if (positionType == "left") {  
  64.             $("#SonlineBox > .contentBox").animate({  
  65.                 left : allWidth  
  66.             }, speed);  
  67.         } else if (positionType == "right") {  
  68.             $("#SonlineBox > .contentBox").animate({  
  69.                 right : allWidth  
  70.             }, speed);  
  71.         }  
  72.         $("#SonlineBox").animate({  
  73.             width : widthValue  
  74.         }, speed);  
  75.     }  
  76.     // 子插件:设置列表参数  
  77.     $.fn.setList = function(opts) {  
  78.         $("body")  
  79.                 .append(  
  80.                         "<div class='SonlineBox' id='SonlineBox' style='top:-600px;'><div class='openTrigger' style='display:none' title='展开'></div><div class='contentBox'><div class='closeTrigger'><img src='icon-open.png' title='关闭' /></div><div class='titleBox'><span>客服中心</span></div><div class='listBox'></div></div></div>");  
  81.         if (opts.Qqlist == "") {  
  82.             $("#SonlineBox > .contentBox > .listBox").append(  
  83.                     "<p style='padding:15px'>暂无在线客服。</p>")  
  84.         } else {  
  85.             var qqListHtml = $.fn.Sonline.splitStr(opts);  
  86.             $("#SonlineBox > .contentBox > .listBox").append(qqListHtml);  
  87.         }  
  88.         if (opts.Position == "left") {  
  89.             $("#SonlineBox").css({  
  90.                 left : 0  
  91.             });  
  92.         } else if (opts.Position == "right") {  
  93.             $("#SonlineBox").css({  
  94.                 right : 0  
  95.             })  
  96.         }  
  97.         $("#SonlineBox").css({  
  98.             top : opts.Top  
  99.         });  
  100.         var allHeights = 0;  
  101.         if ($("#SonlineBox > .contentBox").height() < $(  
  102.                 "#SonlineBox > .openTrigger").height()) {  
  103.             allHeights = $("#SonlineBox > .openTrigger").height() + 4;  
  104.         } else {  
  105.             allHeights = $("#SonlineBox > .contentBox").height() + 4;  
  106.         }  
  107.         $("#SonlineBox").height(allHeights);  
  108.         if (opts.Position == "left") {  
  109.             $("#SonlineBox > .openTrigger").css({  
  110.                 left : 0  
  111.             });  
  112.         } else if (opts.Position == "right") {  
  113.             $("#SonlineBox > .openTrigger").css({  
  114.                 right : 0  
  115.             });  
  116.         }  
  117.     }  
  118.     // 滑动式效果  
  119.     $.fn.Sonline.scrollType = function() {  
  120.         $("#SonlineBox").css({  
  121.             position : "absolute"  
  122.         });  
  123.         var topNum = parseInt($("#SonlineBox").css("top") + "");  
  124.         $(window).scroll(function() {  
  125.             var scrollTopNum = $(window).scrollTop();// 获取网页被卷去的高  
  126.             $("#SonlineBox").stop(truetrue).delay(0).animate({  
  127.                 top : scrollTopNum + topNum  
  128.             }, "slow");  
  129.         });  
  130.     }  
  131.     // 分割QQ  
  132.     $.fn.Sonline.splitStr = function(opts) {  
  133.         var strs = new Array(); // 定义一数组  
  134.         var QqlistText = opts.Qqlist;  
  135.         strs = QqlistText.split(","); // 字符分割  
  136.         var QqHtml = ""  
  137.         for ( var i = 0; i < strs.length; i++) {  
  138.             var subStrs = new Array(); // 定义一数组  
  139.             var subQqlist = strs[i];  
  140.             subStrs = subQqlist.split("|"); // 字符分割  
  141.             QqHtml = QqHtml  
  142.                     + "<div class='QQList'><span>"  
  143.                     + subStrs[1]  
  144.                     + ":</span><a target='_blank' href='http://wpa.qq.com/msgrd?v=3&uin="  
  145.                     + subStrs[0]  
  146.                     + "&site=qq&menu=yes'><img border='0' src='http://wpa.qq.com/pa?p=2:"  
  147.                     + subStrs[0]  
  148.                     + ":41 &amp;r=0.22914223582483828' alt='点击这里'></a></div>"  
  149.         }  
  150.         return QqHtml;  
  151.     }  
  152. })(jQuery);  

 

②css样式 qqOnline.css

Html代码    收藏代码
  1. .SonlineBox{ width:162px; font-size:12px;overflow:hidden; z-index:9999;}  
  2. .SonlineBox .openTrigger{ width:30px; height:110px; position:absolute; top:0px;  z-index:1; cursor:pointer;  background:#0176ba url(icon-close.png) no-repeat;}  
  3. .SonlineBox .titleBox{ width:158px; height:35px; line-height:35px; background:#038bdc url(icon-bg.png) repeat-x; border-bottom:2px solid #0176ba;}  
  4. .SonlineBox .titleBox span{ margin-left:10px; color:#fff; font-size:14px; font-family:'微软雅黑','黑体';}  
  5. .SonlineBox .contentBox{ width:158px; height:auto; border:2px solid #0176ba; background:#fff; position:absolute; z-index:2;}  
  6. .SonlineBox .contentBox .closeTrigger{ width:25px; height:25px; display:block; cursor:pointer;  position:absolute; top:5px;right:5px;-webkit-transition:all 0.8s ease-out;}  
  7. .SonlineBox .contentBox .closeTrigger:hover{-webkit-transform:scale(1) rotate(360deg);}  
  8. .SonlineBox .contentBox .listBox{overflow:hidden; margin-bottom:10px;}  
  9. .SonlineBox .contentBox .listBox .QQList{ display:block; width:86%; height:22px; margin:10px auto 0px auto;}  
  10. .SonlineBox .contentBox .listBox .QQList span{float:left; line-height:22px;}  
  11. .SonlineBox .contentBox .listBox .QQList a{float:left;}  

 ③ html页面

Html代码    收藏代码
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">  
  2. <html>  
  3. <head>  
  4. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">  
  5. <title>在线QQ客服悬浮插件</title>  
  6. <script type="text/javascript" src="jquery-1.6.4.js"></script>  
  7. <link href="qqOnline.css" rel="stylesheet" type="text/css"  
  8.     id="" media="all"></link>  
  9. <script type="text/javascript" src="qqOnline.js"></script>  
  10. <script>  
  11. $(function(){  
  12.     $("body").Sonline({  
  13.         Position:"right",//left或right  
  14.         Top:200,//顶部距离,默认200px  
  15.         Effect:true, //滚动或者固定两种方式,布尔值:true或false  
  16.         DefaultsOpen:true, //默认展开:true,默认收缩:false  
  17.         Qqlist:"418114362|客服a,418114362|客服b,418114362|客服c,418114362|客服d,418114362|客服e" //多个QQ用','隔开,QQ和客服名用'|'隔开  
  18.     });  
  19. })  
  20. </script>  
  21. </head>  
  22. <body>  
  23.       
  24. </body>  
  25. </html> 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值