$(function () { const globaldata = { active: null, maxlength: null, }; // 实现跳转 $(".my-nav").click(function (e) { let active = Array.prototype.slice.call($(this).find("li")).indexOf(e.target); if (active == globaldata.active) return false; globaldata.active = active; $(this).find(".active").removeClass("active"); $(e.target).addClass("active"); // 获取跳转锚点到顶部的距离 let title = $("#title").offset().top; let edi_answer = $("#edi-answer").offset().top; let interactive = $("#interactive").offset().top; let lis = $(this).find("li"); let i = Array.prototype.slice.call(lis).indexOf($(e.target)[0]); // 储存锚点 let maos = [title, edi_answer, interactive]; $(window).scrollTop(maos[i]); }) // 查看更多 $("[data-click='open']").click(function () { let bool = $(this).data("open"); if (!bool) { $(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"); } else { $(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"); } }) // 进度条拖动 window.onresize = function () { globaldata.maxlength = $(".pro").width(); } // 进度条宽度 let maxlength = globaldata.maxlength || $(".pro").width(); // 移动dom let movedom = $(".pro>.icon"); //起始坐标 let startX = null; // 分数 let gross = $(".pro").data("gross"); // 进度条 let showdom = $(".pro>.pro-content"); // 显示数值 let pro_show = $("pro_show"); movedom.mousedown(function (e) { startX = e.pageX; $(this).css('left') ? $(this).css('left') : $(this).css('left', '0px'); let startLeft = parseInt($(this).css('left')); console.log(startLeft) let $that = $(this); $(document).mousemove(function (e) { let moveX = (e.pageX - startX) > 0 ? true : false; let movesection = startLeft + (e.pageX - startX); if (movesection >= 0 && movesection <= maxlength) { let percent = (movesection / maxlength).toFixed(4) * 100 * gross; percent = Math.round(percent) + "分"; let move = movesection + "px"; showdom.css("width", move); console.log(percent) pro_show.css("left", move).text(percent); $that.css("left", move) } }) }).mouseleave(function () { $(document).mousemove = null }) })