exam_detail_img.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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_show");
  48. movedom.mousedown(function (e) {
  49. startX = e.pageX;
  50. $(this).css('left') ? $(this).css('left') : $(this).css('left', '0px');
  51. let startLeft = parseInt($(this).css('left'));
  52. console.log(startLeft)
  53. let $that = $(this);
  54. $(document).mousemove(function (e) {
  55. let moveX = (e.pageX - startX) > 0 ? true : false;
  56. let movesection = startLeft + (e.pageX - startX);
  57. if (movesection >= 0 && movesection <= maxlength) {
  58. let percent = (movesection / maxlength).toFixed(4) * 100 * gross;
  59. percent = Math.round(percent) + "分";
  60. let move = movesection + "px";
  61. showdom.css("width", move);
  62. console.log(percent)
  63. pro_show.css("left", move).text(percent);
  64. $that.css("left", move)
  65. }
  66. })
  67. }).mouseleave(function () { $(document).mousemove = null })
  68. })