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 (navigator.appversion.indexof("msie") != -1){ // ie用attachevent window.attachevent('onscroll', z_zxkf_settimeout); }else{ // 非ie用addeventlistener document.addeventlistener("scroll", z_zxkf_settimeout, false); }