DIV CSS 佈局教程網

 DIV+CSS佈局教程網 >> 網頁腳本 >> JavaScript入門知識 >> jQuery入門知識 >> JQuery特效代碼 >> jquery漂浮在網頁右側的qq在線客服插件示例代碼學習
jquery漂浮在網頁右側的qq在線客服插件示例代碼學習
編輯:JQuery特效代碼     
很實用的一款QQ在線客服代碼,點擊QQ圖標,可直接與客服對話。具體實現代碼如下:
html頁面
. 代碼如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>jquery實現qq客服</title>
<link rel="stylesheet" type="text/css" href="css/base.css"/>
<script type="text/javascript" src="js/jquery-1.8.3.min.js"></script>
<script type="text/javascript" src="js/qqservice.js"></script>
<script type="text/javascript">
$(function(){
$("body").Sonline({
Position:"right",//left或right
Top:200,//頂部距離,默認200px
Effect:true, //滾動或者固定兩種方式,布爾值:true或false
DefaultsOpen:true, //默認展開:true,默認收縮:false
Qqlist:"<SPAN>435027|客服01,435027|客服02,435027|客服03,435027|客服04,435027|客服05</SPAN>" //多個QQ用','隔開,QQ和客服名用'|'隔開
});
})
</script>
</head>
<body>
<div style="height:2500px"></div>
<div style="text-align:center;clear:both"></div>
</body>
</html>

css樣式
. 代碼如下:
/*默認藍色*/
.SonlineBox{ width:162px; font-size:12px;overflow:hidden; z-index:9999;}
.SonlineBox .openTrigger{ width:30px; height:110px; position:absolute; top:0px; z-index:1; cursor:pointer; background:#0176ba url(../images/openTrigger.jpg) no-repeat;}
.SonlineBox .titleBox{ width:158px; height:35px; line-height:35px; background:#038bdc url(../images/SonlineTitleBg.gif) repeat-x; border-bottom:2px solid #0176ba;}
.SonlineBox .titleBox span{ margin-left:10px; color:#fff; font-size:14px; font-family:'微軟雅黑','黑體';}
.SonlineBox .contentBox{ width:158px; height:auto; border:2px solid #0176ba; background:#fff; position:absolute; z-index:2;}
.SonlineBox .contentBox .closeTrigger{ width:25px; height:25px; display:block; cursor:pointer; position:absolute; top:5px;right:5px;-webkit-transition:all 0.8s ease-out;}
.SonlineBox .contentBox .closeTrigger:hover{-webkit-transform:scale(1) rotate(360deg);}
.SonlineBox .contentBox .listBox{overflow:hidden; margin-bottom:10px;}
.SonlineBox .contentBox .listBox .QQList{ display:block; width:86%; height:22px; margin:10px auto 0px auto;}
.SonlineBox .contentBox .listBox .QQList span{float:left; line-height:22px;}
.SonlineBox .contentBox .listBox .QQList a{float:left;}

jquery腳本代碼
. 代碼如下:
/*
此插件基於Jquery
開發者 yaohucaizi
Blog:http://blog.csdn.net/yaohucaizi/
*/
(function($){
$.fn.Sonline = function(options){
var opts = $.extend({}, $.fn.Sonline.defualts, options);
$.fn.setList(opts); //調用列表設置
if(opts.DefaultsOpen == false){
$.fn.Sonline.close(opts.Position,0);
}
//展開
$("#SonlineBox > .openTrigger").live("click",function(){$.fn.Sonline.open(opts.Position);});
//關閉
$("#SonlineBox > .contentBox > .closeTrigger").live("click",function(){$.fn.Sonline.close(opts.Position,"fast");});

//Ie6兼容或滾動方式顯示
if ($.browser.msie && ($.browser.version == "6.0") && !$.support.style||opts.Effect==true) {$.fn.Sonline.scrollType();}
else if(opts.Effect==false){$("#SonlineBox").css({position:"fixed"});}
}
//plugin defaults
$.fn.Sonline.defualts ={
Position:"left",//left或right
Top:200,//頂部距離,默認200px
Effect:true, //滾動或者固定兩種方式,布爾值:true或
DefaultsOpen:true, //默認展開:true,默認收縮:false
Qqlist:"" //多個QQ用','隔開,QQ和客服名用'|'隔開
}

//展開
$.fn.Sonline.open = function(positionType){
var widthValue = $("#SonlineBox > .contentBox").width();
if(positionType=="left"){$("#SonlineBox > .contentBox").animate({left: 0},"fast");}
else if(positionType=="right"){$("#SonlineBox > .contentBox").animate({right: 0},"fast");}
$("#SonlineBox").css({width:widthValue+4});
$("#SonlineBox > .openTrigger").hide();
}
//關閉
$.fn.Sonline.close = function(positionType,speed){
$("#SonlineBox > .openTrigger").show();
var widthValue =$("#SonlineBox > .openTrigger").width();
var allWidth =(-($("#SonlineBox > .contentBox").width())-6);
if(positionType=="left"){$("#SonlineBox > .contentBox").animate({left: allWidth},speed);}
else if(positionType=="right"){$("#SonlineBox > .contentBox").animate({right: allWidth},speed);}
$("#SonlineBox").animate({width:widthValue},speed);

}
//子插件:設置列表參數
$.fn.setList = function(opts){
$("body").append("<div class='SonlineBox' id='SonlineBox' style='top:-600px;'><div class='openTrigger' style='display:none' title='展開'></div><div class='contentBox'><div class='closeTrigger'><img src='images/closeBtnImg.gif' title='關閉' /></div><div class='titleBox'><span>客服中心</span></div><div class='listBox'></div></div></div>");
if(opts.Qqlist==""){$("#SonlineBox > .contentBox > .listBox").append("<p style='padding:15px'>暫無在線客服。</p>")}
else{var qqListHtml = $.fn.Sonline.splitStr(opts);$("#SonlineBox > .contentBox > .listBox").append(qqListHtml); }
if(opts.Position=="left"){$("#SonlineBox").css({left:0});}
else if(opts.Position=="right"){$("#SonlineBox").css({right:0})}
$("#SonlineBox").css({top:opts.Top});
var allHeights=0;
if($("#SonlineBox > .contentBox").height() < $("#SonlineBox > .openTrigger").height()){
allHeights = $("#SonlineBox > .openTrigger").height()+4;
} else{allHeights = $("#SonlineBox > .contentBox").height()+4;}
$("#SonlineBox").height(allHeights);
if(opts.Position=="left"){$("#SonlineBox > .openTrigger").css({left:0});}
else if(opts.Position=="right"){$("#SonlineBox > .openTrigger").css({right:0});}
}

//滑動式效果
$.fn.Sonline.scrollType = function(){
$("#SonlineBox").css({position:"absolute"});
var topNum = parseInt($("#SonlineBox").css("top")+"");
$(window).scroll(function(){
var scrollTopNum = $(window).scrollTop();//獲取網頁被卷去的高
$("#SonlineBox").stop(true,true).delay(0).animate({top:scrollTopNum+topNum},"slow");
});
}

//分割QQ
$.fn.Sonline.splitStr = function(opts){
var strs= new Array(); //定義一數組
var QqlistText = opts.Qqlist;
strs=QqlistText.split(","); //字符分割
var QqHtml=""
for (var i=0;i<strs.length;i++){
var subStrs= new Array(); //定義一數組
var subQqlist = strs[i];
subStrs = subQqlist.split("|"); //字符分割
QqHtml = QqHtml+"<div class='QQList'><span>"+subStrs[1]+":</span><a target='_blank' href='http://wpa.qq.com/msgrd?v=3&uin="+subStrs[0]+"&site=qq&menu=yes'><img border='0' src='http://wpa.qq.com/pa?p=2:"+subStrs[0]+":41 &r=0.22914223582483828' alt='點擊這裡'></a></div>"
}
return QqHtml;
}
})(jQuery);

效果圖如下:
XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved