cloudPrintTask.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. $(function(){
  2. /**
  3. * 滚动的区域/总区域
  4. * ||
  5. * 滚动条滚动的区域/总区域
  6. */
  7. var $barTip = $('#barTip');
  8. var $content = $('#hgc_content');
  9. var $scrollBar = $('#scrollBar');
  10. var totalArea = $('#hgc_content li').eq(0).find('span').length*150 - $content .width();
  11. var scrollArea = 0;
  12. var barArea = $scrollBar.width() - $barTip.width();
  13. $content.scroll(function(){
  14. scrollArea = $(this).scrollLeft();
  15. var scollLeft = (scrollArea/totalArea)*barArea;
  16. $barTip.css('left',scollLeft+'px')
  17. })
  18. //模拟滚动条
  19. var startLeft = 0;
  20. var isMove = false;
  21. var diff = 0;
  22. $barTip.mousedown(function(e){
  23. startLeft = e.pageX;
  24. isMove = true;
  25. diff = e.pageX - $barTip.offset().left;
  26. $(document).mouseup(function(e){
  27. startLeft = e.pageX;
  28. isMove = false;
  29. })
  30. })
  31. $(document).mousemove(function(e){
  32. var diffDistance = e.pageX-diff;
  33. var scollLeft = (diffDistance/barArea)*totalArea;
  34. if(
  35. !isMove ||
  36. diffDistance>=barArea ||
  37. diffDistance <= 0
  38. )return;
  39. $barTip.css('left',diffDistance+'px');
  40. $content.scrollLeft(scollLeft);
  41. })
  42. //document.body.onselectstart = function(){return false;}
  43. })