exam_detail_img.js 4.2 KB

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