javascript實(shí)現(xiàn)在線客服效果
在線客服系統(tǒng)在大量的網(wǎng)站都有應(yīng)用,特別是銷售類網(wǎng)站,可以有效的增加網(wǎng)站的可用性,便于客戶及時(shí)聯(lián)系商家,從而增加了交易成功的可能性,在線客服系統(tǒng)的實(shí)現(xiàn)方式有多種多樣,這里介紹一種網(wǎng)上常見(jiàn)并且非常美觀的客服系統(tǒng),以此達(dá)到舉一反三的目的,能夠比較輕松的實(shí)現(xiàn)其他外觀形式的客服系統(tǒng),代碼示例如下:
CSS
<style type="text/css"> body { margin:0px } .main_head { background:url(mytest/JS/img3-5_2.png) no-repeat; } *html .main_head { filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src="mytest/JS/img3-5_2.png", sizingMethod='crop'); background:none transparent scroll repeat 0% 0%; } * + html .main_head { background:url(mytest/JS/img3-5_2.png) no-repeat; } .info { padding-bottom:10px; padding-left:0px; padding-right:0px; background:url(mytest/JS/img3-5_3.png) repeat-y; padding-top:5px } * html .info { filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src="mytest/JS/img3-5_3.png", sizingMethod='crop'); background-repeat:repeat-y; } * + HTML .info { padding-bottom:10px; padding-left:0px; padding-right:0px; background:url(mytest/JS/img3-5_3.png) repeat-y; padding-top:5px; } .down_kefu { width:157px; background:url(mytest/JS/img3-5_4.png) no-repeat; height:8px } * html .down_kefu { filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src="mytest/JS/img3-5_4.png", sizingMethod='crop'); width:157px; background-repeat:repeat-y; height:8px } * + HTML .down_kefu { width:157px; background:url(mytest/JS/img3-5_4.png) no-repeat; height:8px } .Obtn { margin-top:104px; width:32px; background:url(mytest/JS/img3-5_1.png) no-repeat; float:left; height:139px; margin-left:-5px } * HTML .Obtn { filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src="mytest/JS/img3-5_1.png", sizingMethod='crop'); width:32px; background:none transparent scroll repeat 0% 0%; float:left; height:139px } * + html .Obtn { margin-top:104px; width:32px; background:url(mytest/JS/img3-5_1.png) no-repeat; float:left; height:139px; margin-left:-5px; } .qqtable span { padding-bottom:5px; line-height:20px; padding-left:0px; width:100px; padding-right:0px; color:#ff6600; font-size:13px; font-weight:bold; padding-top: 5px } .qqtable a { text-decoration:none; } .qqtable a:hover { text-decoration: none } .qun { border-bottom:#ffd2bf 1px solid; border-left:#ffd2bf 1px solid; padding-bottom:5px; line-height:20px; background-color:#ffffff; padding-left:0px; width:100px; padding-right:0px; font-size:12px; border-top:#ffd2bf 1px solid; border-right:#ffd2bf 1px solid; padding-top:5px } .qun span { color:#ff6600; font-size:13px; font-weight:bold; } </style>
html
<div id="softwhy"> <table style="float:left" border="0" cellspacing="0" cellpadding="0" width="157"> <tbody> <tr> <td class="main_head" height="39" valign="top"> </td> </tr> <tr> <td class="info" valign="top"> <table class="qqtable" border="0" cellspacing="0" cellpadding="0" width="120" align="center"> <tbody> <tr> <td align=middle><a href="#" target="_blank"><img border=0 src="mytest/JS/kefu_head.gif"></a></td> </tr> <tr> <td height=5></td> </tr> <tr> <td height=30 align=middle><span>qq:88888888</span></td> </tr> <tr> <td height=30 align=middle><span>qq:88888888</span></td> </tr> <tr> <td height=5></td> </tr> <tr> <td height=35 valign=top align=middle><a href="#" target="_blank"><img border=0 src="mytest/JS/img3-5-btn1.gif" width=90 height=25></a></td> </tr> <tr> <td height=38 valign=top align=middle><a href="#" target="_blank"><img border=0 src="mytest/JS/img3-5-btn2.gif" width=90 height=25></a></td> </tr> <tr> <td align=middle><div class=qun><font color=#9b9b9b>會(huì)員交流群</font><br><span>123456</span></div></td> </tr> <tr> <td align=middle><div class=qun><font color=#9b9b9b>商家交流群</font><br><span>654321</span></div></td> </tr> <tr> <td align=middle> </td> </tr> </tbody> </table> </td> </tr> <tr> <td class="down_kefu" valign="top"></td> </tr> </tbody> </table> <div class="Obtn"></div> </div> <div style="height:1000px;"></div>
JS
<script type="text/javascript"> kefu=function(id,_top,_left){ var me=document.getElementById(id); var d1=document.body; var d2=document.documentElement; d1.style.height=d2.style.height='100%'; me.style.top=_top+'px'; me.style.left=_left+"px"; me.style.position='absolute'; function a() { me.style.top=parseInt(me.style.top)+(Math.max(d1.scrollTop,d2.scrollTop)+_top-parseInt(me.style.top))*0.1+'px'; } setInterval(a,10+parseInt(Math.random()*20)); } window.onload=function(){ kefu('softwhy',100,-152) } </script> <script type="text/javascript"> var InterTime=1; var maxWidth=-1; var minWidth=-152; var numInter=10; var BigInter; var SmallInter; var o=document.getElementById("softwhy"); var i=parseInt(o.style.left); function Big() { if(parseInt(o.style.left)<maxWidth) { i=parseInt(o.style.left); i+= numInter; o.style.left=i+"px"; if(i==maxWidth) clearInterval(BigInter); } } function toBig() { clearInterval(SmallInter); BigInter=setInterval(Big,InterTime); } function Small() { if(parseInt(o.style.left)>minWidth) { i=parseInt(o.style.left); i=i-numInter; o.style.left=i+"px"; if(i==minWidth) clearInterval(SmallInter); } } function toSmall() { clearInterval(BigInter); SmallInter=setInterval(Small,InterTime); } </script>
以上代碼實(shí)現(xiàn)了我們想要的在網(wǎng)頁(yè)一側(cè)漂浮的客服系統(tǒng)。下面就簡(jiǎn)單介紹一下如何實(shí)現(xiàn)次效果:
一.實(shí)現(xiàn)原理:
將整個(gè)客服系統(tǒng)所在的softwhy對(duì)象設(shè)置為絕對(duì)定位,然后在默認(rèn)狀態(tài)下,將它的left屬性值設(shè)置為一個(gè)恰當(dāng)?shù)呢?fù)值,這樣它主體部分就會(huì)被隱藏,只顯示提示部分:
默認(rèn)狀態(tài)下被隱藏的主體部分。
默認(rèn)狀態(tài)下顯示的提示部分。
當(dāng)鼠標(biāo)放在放在提示部分(也就是放在softwhy對(duì)象)時(shí)候,通過(guò)調(diào)用相應(yīng)的函數(shù),使用setInterval()不斷的加大left屬性值來(lái)實(shí)現(xiàn)客服主體部分逐漸顯示的效果。當(dāng)鼠標(biāo)離開(kāi)softwhy對(duì)象的時(shí)候,再通過(guò)調(diào)用相應(yīng)的函數(shù),使用setInterval()不斷的減少left屬性值來(lái)實(shí)現(xiàn)客服主體部分的逐漸隱藏。
softwhy對(duì)象top屬性值在這里可能是個(gè)難點(diǎn),它實(shí)現(xiàn)了當(dāng)拖動(dòng)滾動(dòng)條的時(shí)候,客服系統(tǒng)具有比較任性的“彈性”的感覺(jué),并且最終能夠固定在距離窗口頂端100px的垂直位置上,此效果是結(jié)合a函數(shù)和setInterval(a,10+parseInt(Math.random()*20))實(shí)現(xiàn)的,這里簡(jiǎn)單介紹一下a函數(shù)的原理,主要是個(gè)數(shù)學(xué)問(wèn)題:
我們想要實(shí)現(xiàn)的效果就是無(wú)論怎么拖動(dòng)滾動(dòng)條,客服系統(tǒng)最終在垂直位置上距離窗口上邊緣100px,也就是說(shuō)只要將top屬性值設(shè)置為d1.scrollTop或者d2.scrollTop與100px之和就可以了。下面簡(jiǎn)單對(duì)a函數(shù)進(jìn)行一下分析:
Math.max(d1.scrollTop,d2.scrollTop)+_top-parseInt(me.style.top)中,Math.max(d1.scrollTop,d2.scrollTop)+_top就是me.style.top的最終值,在通過(guò)使用setInterval()函數(shù)循環(huán)執(zhí)行a函數(shù),也就是不斷的執(zhí)行parseInt(me.style.top)+(Math.max(d1.scrollTop,d2.scrollTop)+_top-parseInt(me.style.top))*0.1+'px',當(dāng)me.style.top=Math.max(d1.scrollTop,d2.scrollTop)+_top的時(shí)候,客服系統(tǒng)也就是固定在指定的位置了。
以上所述就是本文的全部?jī)?nèi)容了,希望大家能夠喜歡。
- JS 網(wǎng)頁(yè)安全色調(diào)色板 DW風(fēng)格
- PHP+Javascript實(shí)現(xiàn)在線拍照功能實(shí)例
- JS實(shí)現(xiàn)在線統(tǒng)計(jì)一個(gè)頁(yè)面內(nèi)鼠標(biāo)點(diǎn)擊次數(shù)的方法
- JS網(wǎng)頁(yè)在線獲取鼠標(biāo)坐標(biāo)值的方法
- 學(xué)習(xí)js在線html(富文本,所見(jiàn)即所得)編輯器
- 3款實(shí)用的在線JS代碼工具(國(guó)外)
- javascript在線編碼查詢工具
- 兩個(gè)JavaScript jsFiddle JSBin在線調(diào)試器
- javascript 在線文本編輯器實(shí)現(xiàn)代碼
- JS實(shí)現(xiàn)的在線調(diào)色板實(shí)例(附demo源碼下載)
相關(guān)文章
JavaScript數(shù)據(jù)推送Comet技術(shù)詳解
這篇文章主要為大家詳細(xì)介紹了JavaScript數(shù)據(jù)推送Comet技術(shù),感興趣的小伙伴們可以參考一下2016-04-04用Javascript做flash做的事..才完成的一個(gè)類.Auntion Action var 0.1
用Javascript做flash做的事..才完成的一個(gè)類.Auntion Action var 0.1...2007-02-02js實(shí)現(xiàn)點(diǎn)擊復(fù)制當(dāng)前文本到剪貼板功能(兼容所有瀏覽器)
這篇文章主要介紹了js實(shí)現(xiàn)點(diǎn)擊復(fù)制當(dāng)前文本到剪貼板功能,兼容所有瀏覽器,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2015-12-12JS+CSS實(shí)現(xiàn)實(shí)用的單擊輸入框彈出選擇框的方法
這篇文章主要介紹了JS+CSS實(shí)現(xiàn)實(shí)用的單擊輸入框彈出選擇框的方法,實(shí)例分析了javascript操作select及button的操作技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-02-02JavaScript拆分字符串時(shí)產(chǎn)生空字符的解決方案
使用JavaScript的split方法拆分字符串時(shí)出現(xiàn)一些空字符串"",尤其是當(dāng)使用正則表達(dá)式作為分隔符的時(shí)候。那么,產(chǎn)生這些空字符串的原因是什么?又該如何來(lái)處理呢,這就是今天我們要探討的問(wèn)題2014-09-09