var kfc = document.getelementbyid('kf_container'); var z_top = kfc.offsettop; /* window.onscroll = function(){ settimeout('z_zxkf_scroll()',350); } */ var z_zxkf_settimeout = function(){ settimeout('z_zxkf_scroll()',350); } function z_zxkf_scroll(){ var scrotop, cur_top, step, flag, timer = 80, multiplier = 15, little_step = 8; scrotop = document.documentelement.scrolltop || document.body.scrolltop; cur_top = kfc.offsettop; step = scrotop + z_top - cur_top;//移动距离 = 页面滚动距离 + 客服容器与页面顶部原来的距离 - 客服容器与页面顶部现在的距离 flag = step > 0 ? 1 : -1; step = math.abs(step); step = step > little_step*multiplier ? little_step : step/multiplier; if(step < 1){ kfc.style.top = scrotop + z_top + 'px'; }else{ kfc.style.top = (cur_top + flag*step) + 'px'; settimeout('z_zxkf_scroll()',timer); } } if(kfc.style.display != 'none'){ if(window._scrollfnlist == undefined){ _scrollfnlist = []; } if(_scrollfnlist.length !== undefined){ if(window.onscroll != null){ _scrollfnlist.push(window.onscroll); } _scrollfnlist.push(z_zxkf_settimeout); window.onscroll = function(){ var i, max, item; for(i = 0, max = _scrollfnlist.length; i < max; i++){ item = _scrollfnlist[i]; item(); } } } }