exam_detail_img.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. $(function () {
  2. const globaldata = {
  3. active: null,
  4. maxlength: null,
  5. };
  6. // 实现跳转
  7. $(".my-nav").click(function (e) {
  8. let active = Array.prototype.slice.call($(this).find("li")).indexOf(e.target);
  9. if (active == globaldata.active) return false;
  10. globaldata.active = active;
  11. $(this).find(".active").removeClass("active");
  12. $(e.target).addClass("active");
  13. // 获取跳转锚点到顶部的距离
  14. let title = $("#title").offset().top;
  15. let edi_answer = $("#edi-answer").offset().top;
  16. let interactive = $("#interactive").offset().top;
  17. let lis = $(this).find("li");
  18. let i = Array.prototype.slice.call(lis).indexOf($(e.target)[0]);
  19. // 储存锚点
  20. let maos = [title, edi_answer, interactive];
  21. $(window).scrollTop(maos[i]);
  22. })
  23. // 查看更多
  24. $("[data-click='open']").click(function () {
  25. let bool = $(this).data("open");
  26. if (!bool) {
  27. $(this).data("open", true).children("span").text("收起阅读全部").parent().children("i").removeClass("glyphicon-chevron-down").addClass("glyphicon-chevron-up").parent().parent().parent().addClass("edi-body-height");
  28. } else {
  29. $(this).data("open", false).children("span").text("展开阅读全部").parent().children("i").removeClass("glyphicon-chevron-up").addClass("glyphicon-chevron-down").parent().parent().parent().removeClass("edi-body-height");
  30. }
  31. })
  32. // 进度条拖动
  33. window.onresize = function () {
  34. globaldata.maxlength = $(".pro").width();
  35. }
  36. // 进度条宽度
  37. let maxlength = globaldata.maxlength || $(".pro").width();
  38. // 移动dom
  39. let movedom = $(".pro>.icon");
  40. //起始坐标
  41. let startX = null;
  42. // 分数
  43. let gross = $(".pro").data("gross");
  44. // 进度条
  45. let showdom = $(".pro>.pro-content");
  46. // 显示数值
  47. let pro_show = $(".pro>.pro-show");
  48. movedom.mousedown(function (e) {
  49. e.preventDefault();
  50. $(".prog>.title").hide();
  51. $(".pro>.pro-title").hide();
  52. startX = e.pageX;
  53. $(this).css('left') ? $(this).css('left') : $(this).css('left', '0px');
  54. let startLeft = parseInt($(this).css('left'));
  55. let $that = $(this);
  56. document.onmousemove = function (e) {
  57. e.preventDefault();
  58. let moveX = (e.pageX - startX) > 0 ? true : false;
  59. let movesection = startLeft + (e.pageX - startX);
  60. if (movesection >= 0 && movesection <= maxlength) {
  61. let percent = (movesection / maxlength).toFixed(4) * gross;
  62. percent = Math.round(percent) + "分";
  63. let move = movesection + "px";
  64. showdom.css("width", move);
  65. pro_show.css("left", move).text(percent);
  66. $that.css("left", move)
  67. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  68. }
  69. }
  70. })
  71. movedom.mouseup(function () { document.onmousemove = null })
  72. movedom.mouseleave(function () { document.onmousemove = null })
  73. // 手机端更改
  74. let x1, y1, oldTime, newTime, olfLeft, newLeft;
  75. movedom[0].addEventListener("touchstart", function (e) {
  76. e.preventDefault();
  77. $(".prog>.title").hide();
  78. $(".pro>.pro-title").hide();
  79. var touches = e.changedTouches;
  80. x1 = touches[0].pageX;
  81. olfLeft = this.offsetLeft;
  82. }, false)
  83. movedom[0].addEventListener("touchmove", function (e) {
  84. e.preventDefault();
  85. var x2 = e.changedTouches[0].pageX;
  86. newLeft = x2 - x1;
  87. nowLeft = olfLeft + newLeft;
  88. if (nowLeft < 0) {
  89. nowLeft = 0;
  90. }
  91. if (nowLeft > maxlength) {
  92. nowLeft = maxlength;
  93. }
  94. showdom.css("width", nowLeft + "px");
  95. $(this).css("left", nowLeft + "px");
  96. let percent = nowLeft / maxlength * gross;
  97. percent = Math.round(percent);
  98. pro_show.css("left", nowLeft).text(percent);
  99. }, false)
  100. function handleEnd (e) {
  101. this.removeEventListener("touchmove", handleEnd, false);
  102. }
  103. movedom[0].addEventListener("touchend", function () {
  104. this.removeEventListener("touchmove", handleEnd, false);
  105. }, false)
  106. // 不能实现的事件
  107. function warm () {
  108. alert("请在大联考App内登录后操作")
  109. }
  110. // $(".edi-open>span[data-click='open']").click(warm)
  111. $(".edi-user").click(warm)
  112. $(".choose").click(warm)
  113. // 默认 时间
  114. $(".pull-right>span").click(function () {
  115. $(this).addClass('active').siblings("span").removeClass("active");
  116. })
  117. })