$(function () { const globaldata = { active: null, maxlength: null, addHandler: function (element, type, handler) { if (element.addEventListener) { element.addEventListener(type, handler, false); } else if (element.attachEvent) { element.attachEvent("on" + type, handler); } else { element["on" + type] = handler; } } }; // 实现跳转 $(".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>.pro-show"); movedom.mousedown(function (e) { e.preventDefault(); $(".prog>.title").hide(); $(".pro>.pro-title").hide(); startX = e.pageX; $(this).css('left') ? $(this).css('left') : $(this).css('left', '0px'); let startLeft = parseInt($(this).css('left')); let $that = $(this); var move = 'ontouchstart' in document ? 'touchstart' : 'mousemove'; document.onmousemove = function (e) { e.preventDefault(); 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) * gross; percent = Math.round(percent) + "分"; let move = movesection + "px"; showdom.css("width", move); pro_show.css("left", move).text(percent); $that.css("left", move) window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty(); } } }) movedom.mouseup(function () { document.onmousemove = null }) movedom.mouseleave(function () { document.onmousemove = null }) // 不能实现的事件 function warm () { alert("请在大联考App内登录后操作") } // $(".edi-open>span[data-click='open']").click(warm) $(".edi-user").click(warm) $(".choose").click(warm) // 默认 时间 $(".pull-right>span").click(function () { $(this).addClass('active').siblings("span").removeClass("active"); }) })