DDR爱好者之家 Design By 杰米
本文实例为大家分享了turn.js异步加载实现翻书效果的具体代码,供大家参考,具体内容如下
1、阅读翻书js
/** * 电子翻书 */ //var width = 1080; //var height = 1680; var width = "10rem"; var height = "15.2rem"; window.onload = function () { //预加载 //loading(18,1); initData(); } function getQueryString(name) { var result = window.location.search.match(new RegExp("[\" + name + "=([^\&]+)", "i")); if (result == null || result.length < 1) { return ""; } return result[1]; } function initData(){ var book = getQueryString("bookId"); var count = getQueryString("pageCount"); loading_img_url = new Array(); for (var i = 0; i < count; i++) { loading_img_url.push((i+1) + ".png"); } var page = getQueryString("pageNum"); if(!page){ page =1; } loading(book,count,page); } var date_start; var date_end; date_start = getNowFormatDate(); //加载图片 var loading_img_url = []; //加载页面 function loading(book,count,page) { var numbers = 0; var length = loading_img_url.length; //var resUrl = ctxStatic+"/modules/intelligentquery/img/3/"; var resUrl = website + "/lawcase/bookScreenshot" + book + "&page="; var jsUrl = ctxStatic+"/modules/front/guide/vertical/"; var bookId = book; var img = new Image(); img.src = resUrl + page; //img.src = resUrl + pageNum + ".png"; img.onerror = function () { numbers += (1 / length) * 100; } img.onload = function () { numbers += (1 / length) * 100; $('.number').html(parseInt(numbers) + "%"); console.log(numbers); if (Math.round(numbers)) { //$('.number').hide(); date_end = getNowFormatDate(); var loading_time = date_end - date_start; //预加载图片 $(function progressbar() { //拼接图片 $('.shade').hide(); var tagHtml = ""; var imgUrl = resUrl + page; //var imgUrl = resUrl + (pageNum) + ".png"; if (pageNum == 1) { tagHtml += "<div id='first'><img src='"+imgUrl+"' /></div>"; } else if (pageNum == length) { tagHtml += "<div id='first'><img src='"+imgUrl+"' /></div>"; } else { tagHtml += "<div><img src='"+imgUrl+"' /></div>"; } $(".flipbook").append(tagHtml); var w = $(".graph").width(); $(".flipbook-viewport").show(); }); //配置turn.js function loadApp() { var w = width; var h = height; $('.flipboox').width(w).height(h); $('.flipbook').turn({ width: w, height: h, elevation: 50, pages: count, display: 'single', gradients: true, autoCenter: true, when: { turning: function (e, page, view) { var total = $(".flipbook").turn("pages");//总页数 $("#currentPage").html(page); $("#pageCount").html("/"+total); if (page == 1) { $(".btnImg").css("display", "none"); $(".mark").css("display", "block"); } else { $(".btnImg").css("display", "block"); $(".mark").css("display", "none"); } if (page == length) { $(".nextPage").css("display", "none"); } else { $(".nextPage").css("display", "block"); } }, turned: function (e, page, view) { var total = $(".flipbook").turn("pages");//总页数 $("#currentPage").html(page); $("#pageCount").html("/"+total); // 判断翻页按钮点击事件以及状态样式 if(page >= total){ $("#next").addClass("btn-invalid").removeAttr('onclick'); }else{ $("#next").removeClass("btn-invalid").attr("onclick","next();"); } if(page == 1){ $("#prev").addClass("btn-invalid").removeAttr('onclick'); $("#indexPage").css("display","none"); }else{ $("#prev").removeClass("btn-invalid").attr("onclick","prev();"); $("#indexPage").css("display","flex"); } }, missing: function (e, pages) { for (var i = 0; i < pages.length; i++) { addPage(pages[i], $(this),bookId); } } } }) var cpage = getQueryString("pageNum"); $(".flipbook").turn('page', cpage); } yepnope({ test: Modernizr.csstransforms, yep: [jsUrl+'js/turn.js'], complete: loadApp }); } } } function getNowFormatDate() { var date = new Date(); var seperator1 = ""; var seperator2 = ""; var month = date.getMonth() + 1; var strDate = date.getDate(); if (month >= 1 && month <= 9) { month = "0" + month; } if (strDate >= 0 && strDate <= 9) { strDate = "0" + strDate; } var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate + "" + date.getHours() + seperator2 + date.getMinutes() + seperator2 + date.getSeconds(); return currentdate; } //异步加载 function addPage(page, book,bookId) { //var resUrl = ctxStatic+"/modules/intelligentquery/img/3/"; var resUrl = website + "/lawcase/bookScreenshot" + bookId + "&page="; var imgUrl = resUrl + (page); var tagHtml = ""; if (page == 1) { tagHtml += "<div id='first'><img src='"+imgUrl+"' /></div>"; } else if (page == length) { tagHtml += "<div id='end'><img src='"+imgUrl+"' /></div>"; } else { tagHtml += "<div><img src='"+imgUrl+"' /></div>"; } // Check if the page is not in the book if (!book.turn('hasPage', page)) { // Create an element for this page var element = $('<div />').html(''); // Add the page book.turn('addPage', element, page); element.html(tagHtml); } }
2、阅读页面
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <c:set var="front" value="${frontPath}${pageContext.request.contextPath}/f"/> <c:set var="ctxStatic" value="${pageContext.request.contextPath}/static"/> <c:set var="website" value="${pageContext.request.contextPath}"/> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no"> <meta name="format-detection" content="telephone=no"> <meta name="apple-mobile-web-app-capable" content="yes"/> <meta name="apple-mobile-web-app-status-bar-style" content="black"/> <title>阅读</title> <script src="/UploadFiles/2021-04-02/jquery-3.2.1.min.js">以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
DDR爱好者之家 Design By 杰米
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
DDR爱好者之家 Design By 杰米
暂无评论...
更新日志
2024年11月25日
2024年11月25日
- 凤飞飞《我们的主题曲》飞跃制作[正版原抓WAV+CUE]
- 刘嘉亮《亮情歌2》[WAV+CUE][1G]
- 红馆40·谭咏麟《歌者恋歌浓情30年演唱会》3CD[低速原抓WAV+CUE][1.8G]
- 刘纬武《睡眠宝宝竖琴童谣 吉卜力工作室 白噪音安抚》[320K/MP3][193.25MB]
- 【轻音乐】曼托凡尼乐团《精选辑》2CD.1998[FLAC+CUE整轨]
- 邝美云《心中有爱》1989年香港DMIJP版1MTO东芝首版[WAV+CUE]
- 群星《情叹-发烧女声DSD》天籁女声发烧碟[WAV+CUE]
- 刘纬武《睡眠宝宝竖琴童谣 吉卜力工作室 白噪音安抚》[FLAC/分轨][748.03MB]
- 理想混蛋《Origin Sessions》[320K/MP3][37.47MB]
- 公馆青少年《我其实一点都不酷》[320K/MP3][78.78MB]
- 群星《情叹-发烧男声DSD》最值得珍藏的完美男声[WAV+CUE]
- 群星《国韵飘香·贵妃醉酒HQCD黑胶王》2CD[WAV]
- 卫兰《DAUGHTER》【低速原抓WAV+CUE】
- 公馆青少年《我其实一点都不酷》[FLAC/分轨][398.22MB]
- ZWEI《迟暮的花 (Explicit)》[320K/MP3][57.16MB]