123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- $(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>.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);
- 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 })
- // 手机端更改
- let x1, y1, oldTime, newTime, olfLeft, newLeft;
- movedom[0].addEventListener("touchstart", function (e) {
- e.preventDefault();
- $(".prog>.title").hide();
- $(".pro>.pro-title").hide();
- var touches = e.changedTouches;
- x1 = touches[0].pageX;
- olfLeft = this.offsetLeft;
- }, false)
- movedom[0].addEventListener("touchmove", function (e) {
- e.preventDefault();
- var x2 = e.changedTouches[0].pageX;
- newLeft = x2 - x1;
- nowLeft = olfLeft + newLeft;
- if (nowLeft < 0) {
- nowLeft = 0;
- }
- if (nowLeft > maxlength) {
- nowLeft = maxlength;
- }
- showdom.css("width", nowLeft + "px");
- $(this).css("left", nowLeft + "px");
- let percent = nowLeft / maxlength * gross;
- percent = Math.round(percent);
- pro_show.css("left", nowLeft).text(percent);
- }, false)
- function handleEnd (e) {
- this.removeEventListener("touchmove", handleEnd, false);
- }
- movedom[0].addEventListener("touchend", function () {
- this.removeEventListener("touchmove", handleEnd, false);
- }, false)
- // 不能实现的事件
- 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");
- })
- })
|