kefu.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * @Author: ecitlm
  3. * @Date: 2017-08-04 23:18:26
  4. * @Last Modified by: ecitlm
  5. * @Last Modified time: 2017-08-04 23:18:26
  6. */
  7. !(function() {
  8. var serviceOnline = (function() {
  9. var sideContent = document.querySelector(".side_content");
  10. var show_btn = document.querySelector(".show_btn");
  11. var close_btn = document.querySelector(".close_btn");
  12. var timer = null;
  13. //悬浮QQ匀速移动
  14. var startMove = function(argument) {
  15. var scrollsidebar = document.getElementById("scrollsidebar");
  16. clearInterval(timer);
  17. timer = setInterval(function() {
  18. var speed = (argument - scrollsidebar.offsetTop) / 4;
  19. speed = speed > 0 ? Math.ceil(speed) : Math.floor(speed);
  20. if (argument == scrollsidebar.offsetTop) {
  21. clearInterval(timer);
  22. } else {
  23. scrollsidebar.style.top = scrollsidebar.offsetTop + speed + "px";
  24. }
  25. }, 20);
  26. };
  27. //鼠标移动
  28. var scrollMove = function() {
  29. window.onscroll = window.onload = function() {
  30. var scrollsidebar = document.getElementById("scrollsidebar");
  31. var scrolltop =
  32. document.body.scrollTop || document.documentElement.scrollTop;
  33. startMove(
  34. parseInt(
  35. (document.documentElement.clientHeight -
  36. scrollsidebar.offsetHeight) /2 +scrolltop
  37. )
  38. );
  39. };
  40. };
  41. //悬浮QQ显示
  42. var slideShow = function() {
  43. if (!show_btn) return false;
  44. show_btn.addEventListener(
  45. "click",
  46. function() {
  47. show_btn.style.width = 0;
  48. sideContent.style.width = "154px";
  49. },
  50. false
  51. );
  52. };
  53. //悬浮QQ隐藏
  54. var slideClose = function() {
  55. if (!close_btn) return false;
  56. close_btn.addEventListener(
  57. "click",
  58. function() {
  59. console.log(this);
  60. sideContent.style.width = 0;
  61. show_btn.style.width = "25px";
  62. },
  63. false
  64. );
  65. };
  66. //返回出来的方法
  67. return {
  68. init: function() {
  69. scrollMove();
  70. slideClose();
  71. slideShow();
  72. }
  73. };
  74. })();
  75. //初始化
  76. serviceOnline.init();
  77. })();