当前位置:   article > 正文

vue中引入jq使用turnjs实现翻页效果(动态background-image)_自动翻页效果 js

自动翻页效果 js

使用turnjs要使用jq,jq又需要在webpack设置一下,就直接把jq源码文件引进来了,turn的npm不下来,源码文件引入也没有效果,就直接写在了method里面,可读性差了一点

进入页面会自动先翻一页

完整代码示例:

  1. <template>
  2. <div class="boxbox" style="background-color: pink;">
  3. <div id="flipbook" >
  4. <div class="hard top" :style="`background-image:url(${url1});`"></div>
  5. <div class="hard top1" :style="`background-image:url(${url2});`"></div>
  6. <div class="hard" :style="`background:url(${url3}) no-repeat; background-position:center;
  7. background-size: 100%;`"></div>
  8. <div class="hard" :style="`background-image:url(${url4});`">
  9. <div>
  10. <img src="./../assets/a.jpg" alt="" style="height:60px;width:55px">
  11. </div>
  12. <div>
  13. <span>姓名:</span>
  14. <span>章节</span>
  15. </div>
  16. </div>
  17. <div class="hard" :style="`background-image:url(${url5});`"></div>
  18. <div class="hard" :style="`background-image:url(${url4});`"></div>
  19. <div class="hard" :style="`background-image:url(${url6});`"></div>
  20. <div class="hard" :style="`background-image:url(${url7});`"></div>
  21. </div>
  22. <div>居中</div>
  23. </div>
  24. </template>
  25. <script>
  26. import '../utils/jquery.js'
  27. import '../utils/jquery.address-1.6.min.js'
  28. import '../utils/jquery.fullscreen.js'
  29. export default {
  30. name: 'HelloWorld',
  31. props: {
  32. },
  33. data(){
  34. return{
  35. url1:require('./../assets/1.png'),
  36. url2:require('./../assets/2.png'),
  37. url3:require('./../assets/3.png'),
  38. url4:require('./../assets/4.png'),
  39. url5:require('./../assets/5.png'),
  40. url6:require('./../assets/6.png'),
  41. url7:require('./../assets/7.png'),
  42. }
  43. },
  44. mounted() {
  45. this.$nextTick(() => {
  46. this.aa()
  47. $("#flipbook").turn("next")
  48. $("#flipbook").turn({
  49. width: 400,
  50. height: 275,
  51. autoCenter: true
  52. });
  53. $("#flipbook").turn("page",2)
  54. });
  55. },
  56. methods: {
  57. aa() {
  58. (function ($) {
  59. 'use strict';
  60. var has3d,
  61. vendor = '',
  62. PI = Math.PI,
  63. A90 = PI / 2,
  64. isTouch = 'ontouchstart' in window,
  65. events = (isTouch) ? { start: 'touchstart', move: 'touchmove', end: 'touchend' }
  66. : { start: 'mousedown', move: 'mousemove', end: 'mouseup' },
  67. // Contansts used for each corner
  68. // tl * tr
  69. // * *
  70. // bl * br
  71. corners = {
  72. backward: ['bl', 'tl'],
  73. forward: ['br', 'tr'],
  74. all: ['tl', 'bl', 'tr', 'br']
  75. },
  76. displays = ['single', 'double'],
  77. // Default options
  78. turnOptions = {
  79. // First page
  80. page: 1,
  81. // Enables gradients
  82. gradients: true,
  83. // Duration of transition in milliseconds
  84. duration: 600,
  85. // Enables hardware acceleration
  86. acceleration: true,
  87. // Display
  88. display: 'double',
  89. // Events
  90. when: null
  91. },
  92. flipOptions = {
  93. // Back page
  94. folding: null,
  95. // Corners
  96. // backward: Activates both tl and bl corners
  97. // forward: Activates both tr and br corners
  98. // all: Activates all the corners
  99. corners: 'forward',
  100. // Size of the active zone of each corner
  101. cornerSize: 100,
  102. // Enables gradients
  103. gradients: true,
  104. // Duration of transition in milliseconds
  105. duration: 600,
  106. // Enables hardware acceleration
  107. acceleration: true
  108. },
  109. // Number of pages in the DOM, minimum value: 6
  110. pagesInDOM = 6,
  111. pagePosition = {
  112. 0: { top: 0, left: 0, right: 'auto', bottom: 'auto' },
  113. 1: { top: 0, right: 0, left: 'auto', bottom: 'auto' }
  114. },
  115. // Gets basic attributes for a layer
  116. divAtt = function (top, left, zIndex, overf) {
  117. return {
  118. 'css': {
  119. position: 'absolute',
  120. top: top,
  121. left: left,
  122. 'overflow': overf || 'hidden',
  123. 'z-index': zIndex || 'auto'
  124. }
  125. };
  126. },
  127. // Gets a 2D point from a bezier curve of four points
  128. bezier = function (p1, p2, p3, p4, t) {
  129. var mum1 = 1 - t,
  130. mum13 = mum1 * mum1 * mum1,
  131. mu3 = t * t * t;
  132. return point2D(Math.round(mum13 * p1.x + 3 * t * mum1 * mum1 * p2.x + 3 * t * t * mum1 * p3.x + mu3 * p4.x),
  133. Math.round(mum13 * p1.y + 3 * t * mum1 * mum1 * p2.y + 3 * t * t * mum1 * p3.y + mu3 * p4.y));
  134. },
  135. // Converts an angle from degrees to radians
  136. rad = function (degrees) {
  137. return degrees / 180 * PI;
  138. },
  139. // Converts an angle from radians to degrees
  140. deg = function (radians) {
  141. return radians / PI * 180;
  142. },
  143. // Gets a 2D point
  144. point2D = function (x, y) {
  145. return { x: x, y: y };
  146. },
  147. // Returns the traslate value
  148. translate = function (x, y, use3d) {
  149. return (has3d && use3d) ? ' translate3d(' + x + 'px,' + y + 'px, 0px) ' : ' translate(' + x + 'px, ' + y + 'px) ';
  150. },
  151. // Returns the rotation value
  152. rotate = function (degrees) {
  153. return ' rotate(' + degrees + 'deg) ';
  154. },
  155. // Checks if a property belongs to an object
  156. has = function (property, object) {
  157. return Object.prototype.hasOwnProperty.call(object, property);
  158. },
  159. // Gets the CSS3 vendor prefix
  160. getPrefix = function () {
  161. var vendorPrefixes = ['Moz', 'Webkit', 'Khtml', 'O', 'ms'],
  162. len = vendorPrefixes.length,
  163. vendor = '';
  164. while (len--)
  165. if ((vendorPrefixes[len] + 'Transform') in document.body.style)
  166. vendor = '-' + vendorPrefixes[len].toLowerCase() + '-';
  167. return vendor;
  168. },
  169. // Adds gradients
  170. gradient = function (obj, p0, p1, colors, numColors) {
  171. var j, cols = [];
  172. if (vendor == '-webkit-') {
  173. for (j = 0; j < numColors; j++)
  174. cols.push('color-stop(' + colors[j][0] + ', ' + colors[j][1] + ')');
  175. obj.css({ 'background-image': '-webkit-gradient(linear, ' + p0.x + '% ' + p0.y + '%, ' + p1.x + '% ' + p1.y + '%, ' + cols.join(',') + ' )' });
  176. } else {
  177. // This procedure makes the gradients for non-webkit browsers
  178. // It will be reduced to one unique way for gradients in next versions
  179. p0 = { x: p0.x / 100 * obj.width(), y: p0.y / 100 * obj.height() };
  180. p1 = { x: p1.x / 100 * obj.width(), y: p1.y / 100 * obj.height() };
  181. var dx = p1.x - p0.x,
  182. dy = p1.y - p0.y,
  183. angle = Math.atan2(dy, dx),
  184. angle2 = angle - Math.PI / 2,
  185. diagonal = Math.abs(obj.width() * Math.sin(angle2)) + Math.abs(obj.height() * Math.cos(angle2)),
  186. gradientDiagonal = Math.sqrt(dy * dy + dx * dx),
  187. corner = point2D((p1.x < p0.x) ? obj.width() : 0, (p1.y < p0.y) ? obj.height() : 0),
  188. slope = Math.tan(angle),
  189. inverse = -1 / slope,
  190. x = (inverse * corner.x - corner.y - slope * p0.x + p0.y) / (inverse - slope),
  191. c = { x: x, y: inverse * x - inverse * corner.x + corner.y },
  192. segA = (Math.sqrt(Math.pow(c.x - p0.x, 2) + Math.pow(c.y - p0.y, 2)));
  193. for (j = 0; j < numColors; j++)
  194. cols.push(' ' + colors[j][1] + ' ' + ((segA + gradientDiagonal * colors[j][0]) * 100 / diagonal) + '%');
  195. obj.css({ 'background-image': vendor + 'linear-gradient(' + (-angle) + 'rad,' + cols.join(',') + ')' });
  196. }
  197. },
  198. turnMethods = {
  199. // Singleton constructor
  200. // $('#selector').turn([options]);
  201. init: function (opts) {
  202. // Define constants
  203. if (has3d === undefined) {
  204. has3d = 'WebKitCSSMatrix' in window || 'MozPerspective' in document.body.style;
  205. vendor = getPrefix();
  206. }
  207. var i, data = this.data(), ch = this.children();
  208. opts = $.extend({ width: this.width(), height: this.height() }, turnOptions, opts);
  209. data.opts = opts;
  210. data.pageObjs = {};
  211. data.pages = {};
  212. data.pageWrap = {};
  213. data.pagePlace = {};
  214. data.pageMv = [];
  215. data.totalPages = opts.pages || 0;
  216. if (opts.when)
  217. for (i in opts.when)
  218. if (has(i, opts.when))
  219. this.bind(i, opts.when[i]);
  220. this.css({ position: 'relative', width: opts.width, height: opts.height });
  221. this.turn('display', opts.display);
  222. if (has3d && !isTouch && opts.acceleration)
  223. this.transform(translate(0, 0, true));
  224. for (i = 0; i < ch.length; i++)
  225. this.turn('addPage', ch[i], i + 1);
  226. this.turn('page', opts.page);
  227. // allow setting active corners as an option
  228. corners = $.extend({}, corners, opts.corners);
  229. // Event listeners
  230. $(this).bind(events.start, function (e) {
  231. for (var page in data.pages)
  232. if (has(page, data.pages) && flipMethods._eventStart.call(data.pages[page], e) === false)
  233. return false;
  234. });
  235. $(document).bind(events.move, function (e) {
  236. for (var page in data.pages)
  237. if (has(page, data.pages))
  238. flipMethods._eventMove.call(data.pages[page], e);
  239. }).
  240. bind(events.end, function (e) {
  241. for (var page in data.pages)
  242. if (has(page, data.pages))
  243. flipMethods._eventEnd.call(data.pages[page], e);
  244. });
  245. data.done = true;
  246. return this;
  247. },
  248. // Adds a page from external data
  249. addPage: function (element, page) {
  250. var incPages = false,
  251. data = this.data(),
  252. lastPage = data.totalPages + 1;
  253. if (page) {
  254. if (page == lastPage) {
  255. page = lastPage;
  256. incPages = true;
  257. } else if (page > lastPage)
  258. throw new Error('It is impossible to add the page "' + page + '", the maximum value is: "' + lastPage + '"');
  259. } else {
  260. page = lastPage;
  261. incPages = true;
  262. }
  263. if (page >= 1 && page <= lastPage) {
  264. // Stop animations
  265. if (data.done) this.turn('stop');
  266. // Move pages if it's necessary
  267. if (page in data.pageObjs)
  268. turnMethods._movePages.call(this, page, 1);
  269. // Update number of pages
  270. if (incPages)
  271. data.totalPages = lastPage;
  272. // Add element
  273. data.pageObjs[page] = $(element).addClass('turn-page p' + page);
  274. // Add page
  275. turnMethods._addPage.call(this, page);
  276. // Update view
  277. if (data.done)
  278. this.turn('update');
  279. turnMethods._removeFromDOM.call(this);
  280. }
  281. return this;
  282. },
  283. // Adds a page from internal data
  284. _addPage: function (page) {
  285. var data = this.data(),
  286. element = data.pageObjs[page];
  287. if (element)
  288. if (turnMethods._necessPage.call(this, page)) {
  289. if (!data.pageWrap[page]) {
  290. var pageWidth = (data.display == 'double') ? this.width() / 2 : this.width(),
  291. pageHeight = this.height();
  292. element.css({ width: pageWidth, height: pageHeight });
  293. // Place
  294. data.pagePlace[page] = page;
  295. // Wrapper
  296. data.pageWrap[page] = $('<div/>', {
  297. 'class': 'turn-page-wrapper',
  298. page: page,
  299. css: {
  300. position: 'absolute',
  301. overflow: 'hidden',
  302. width: pageWidth,
  303. height: pageHeight
  304. }
  305. }).
  306. css(pagePosition[(data.display == 'double') ? page % 2 : 0]);
  307. // Append to this
  308. this.append(data.pageWrap[page]);
  309. // Move data.pageObjs[page] (element) to wrapper
  310. data.pageWrap[page].prepend(data.pageObjs[page]);
  311. }
  312. // If the page is in the current view, create the flip effect
  313. if (!page || turnMethods._setPageLoc.call(this, page) == 1)
  314. turnMethods._makeFlip.call(this, page);
  315. } else {
  316. // Place
  317. data.pagePlace[page] = 0;
  318. // Remove element from the DOM
  319. if (data.pageObjs[page])
  320. data.pageObjs[page].remove();
  321. }
  322. },
  323. // Checks if a page is in memory
  324. hasPage: function (page) {
  325. return page in this.data().pageObjs;
  326. },
  327. // Prepares the flip effect for a page
  328. _makeFlip: function (page) {
  329. var data = this.data();
  330. if (!data.pages[page] && data.pagePlace[page] == page) {
  331. var single = data.display == 'single',
  332. even = page % 2;
  333. data.pages[page] = data.pageObjs[page].
  334. css({ width: (single) ? this.width() : this.width() / 2, height: this.height() }).
  335. flip({
  336. page: page,
  337. next: (single && page === data.totalPages) ? page - 1 : ((even || single) ? page + 1 : page - 1),
  338. turn: this,
  339. duration: data.opts.duration,
  340. acceleration: data.opts.acceleration,
  341. corners: (single) ? 'all' : ((even) ? 'forward' : 'backward'),
  342. backGradient: data.opts.gradients,
  343. frontGradient: data.opts.gradients
  344. }).
  345. flip('disable', data.disabled).
  346. bind('pressed', turnMethods._pressed).
  347. bind('released', turnMethods._released).
  348. bind('start', turnMethods._start).
  349. bind('end', turnMethods._end).
  350. bind('flip', turnMethods._flip);
  351. }
  352. return data.pages[page];
  353. },
  354. // Makes pages within a range
  355. _makeRange: function () {
  356. var page,
  357. data = this.data(),
  358. range = this.turn('range');
  359. for (page = range[0]; page <= range[1]; page++)
  360. turnMethods._addPage.call(this, page);
  361. },
  362. // Returns a range of `pagesInDOM` pages that should be in the DOM
  363. // Example:
  364. // - page of the current view, return true
  365. // * page is in the range, return true
  366. // 0 page is not in the range, return false
  367. //
  368. // 1 2-3 4-5 6-7 8-9 10-11 12-13
  369. // ** ** -- ** **
  370. range: function (page) {
  371. var remainingPages, left, right,
  372. data = this.data();
  373. page = page || data.tpage || data.page;
  374. var view = turnMethods._view.call(this, page);
  375. if (page < 1 || page > data.totalPages)
  376. throw new Error('"' + page + '" is not a page for range');
  377. view[1] = view[1] || view[0];
  378. if (view[0] >= 1 && view[1] <= data.totalPages) {
  379. remainingPages = Math.floor((pagesInDOM - 2) / 2);
  380. if (data.totalPages - view[1] > view[0]) {
  381. left = Math.min(view[0] - 1, remainingPages);
  382. right = 2 * remainingPages - left;
  383. } else {
  384. right = Math.min(data.totalPages - view[1], remainingPages);
  385. left = 2 * remainingPages - right;
  386. }
  387. } else {
  388. left = pagesInDOM - 1;
  389. right = pagesInDOM - 1;
  390. }
  391. return [Math.max(1, view[0] - left), Math.min(data.totalPages, view[1] + right)];
  392. },
  393. // Detects if a page is within the range of `pagesInDOM` from the current view
  394. _necessPage: function (page) {
  395. if (page === 0)
  396. return true;
  397. var range = this.turn('range');
  398. return page >= range[0] && page <= range[1];
  399. },
  400. // Releases memory by removing pages from the DOM
  401. _removeFromDOM: function () {
  402. var page, data = this.data();
  403. for (page in data.pageWrap)
  404. if (has(page, data.pageWrap) && !turnMethods._necessPage.call(this, page))
  405. turnMethods._removePageFromDOM.call(this, page);
  406. },
  407. // Removes a page from DOM and its internal references
  408. _removePageFromDOM: function (page) {
  409. var data = this.data();
  410. if (data.pages[page]) {
  411. var dd = data.pages[page].data();
  412. if (dd.f && dd.f.fwrapper)
  413. dd.f.fwrapper.remove();
  414. data.pages[page].remove();
  415. delete data.pages[page];
  416. }
  417. if (data.pageObjs[page])
  418. data.pageObjs[page].remove();
  419. if (data.pageWrap[page]) {
  420. data.pageWrap[page].remove();
  421. delete data.pageWrap[page];
  422. }
  423. delete data.pagePlace[page];
  424. },
  425. // Removes a page
  426. removePage: function (page) {
  427. var data = this.data();
  428. if (data.pageObjs[page]) {
  429. // Stop animations
  430. this.turn('stop');
  431. // Remove `page`
  432. turnMethods._removePageFromDOM.call(this, page);
  433. delete data.pageObjs[page];
  434. // Move the pages behind `page`
  435. turnMethods._movePages.call(this, page, -1);
  436. // Resize the size of this magazine
  437. data.totalPages = data.totalPages - 1;
  438. turnMethods._makeRange.call(this);
  439. // Check the current view
  440. if (data.page > data.totalPages)
  441. this.turn('page', data.totalPages);
  442. }
  443. return this;
  444. },
  445. // Moves pages
  446. _movePages: function (from, change) {
  447. var page,
  448. data = this.data(),
  449. single = data.display == 'single',
  450. move = function (page) {
  451. var next = page + change,
  452. odd = next % 2;
  453. if (data.pageObjs[page])
  454. data.pageObjs[next] = data.pageObjs[page].removeClass('page' + page).addClass('page' + next);
  455. if (data.pagePlace[page] && data.pageWrap[page]) {
  456. data.pagePlace[next] = next;
  457. data.pageWrap[next] = data.pageWrap[page].css(pagePosition[(single) ? 0 : odd]).attr('page', next);
  458. if (data.pages[page])
  459. data.pages[next] = data.pages[page].flip('options', {
  460. page: next,
  461. next: (single || odd) ? next + 1 : next - 1,
  462. corners: (single) ? 'all' : ((odd) ? 'forward' : 'backward')
  463. });
  464. if (change) {
  465. delete data.pages[page];
  466. delete data.pagePlace[page];
  467. delete data.pageObjs[page];
  468. delete data.pageWrap[page];
  469. delete data.pageObjs[page];
  470. }
  471. }
  472. };
  473. if (change > 0)
  474. for (page = data.totalPages; page >= from; page--) move(page);
  475. else
  476. for (page = from; page <= data.totalPages; page++) move(page);
  477. },
  478. // Sets or Gets the display mode
  479. display: function (display) {
  480. var data = this.data(),
  481. currentDisplay = data.display;
  482. if (display) {
  483. if ($.inArray(display, displays) == -1)
  484. throw new Error('"' + display + '" is not a value for display');
  485. if (display == 'single') {
  486. if (!data.pageObjs[0]) {
  487. this.turn('stop').
  488. css({ 'overflow': 'hidden' });
  489. data.pageObjs[0] = $('<div />', { 'class': 'turn-page p-temporal' }).
  490. css({ width: this.width(), height: this.height() }).
  491. appendTo(this);
  492. }
  493. } else {
  494. if (data.pageObjs[0]) {
  495. this.turn('stop').
  496. css({ 'overflow': '' });
  497. data.pageObjs[0].remove();
  498. delete data.pageObjs[0];
  499. }
  500. }
  501. data.display = display;
  502. if (currentDisplay) {
  503. var size = this.turn('size');
  504. turnMethods._movePages.call(this, 1, 0);
  505. this.turn('size', size.width, size.height).
  506. turn('update');
  507. }
  508. return this;
  509. } else
  510. return currentDisplay;
  511. },
  512. // Detects if the pages are being animated
  513. animating: function () {
  514. return this.data().pageMv.length > 0;
  515. },
  516. // Disables and enables the effect
  517. disable: function (bool) {
  518. var page,
  519. data = this.data(),
  520. view = this.turn('view');
  521. data.disabled = bool === undefined || bool === true;
  522. for (page in data.pages)
  523. if (has(page, data.pages))
  524. data.pages[page].flip('disable', bool ? $.inArray(page, view) : false);
  525. return this;
  526. },
  527. // Gets and sets the size
  528. size: function (width, height) {
  529. if (width && height) {
  530. var data = this.data(), pageWidth = (data.display == 'double') ? width / 2 : width, page;
  531. this.css({ width: width, height: height });
  532. if (data.pageObjs[0])
  533. data.pageObjs[0].css({ width: pageWidth, height: height });
  534. for (page in data.pageWrap) {
  535. if (!has(page, data.pageWrap)) continue;
  536. data.pageObjs[page].css({ width: pageWidth, height: height });
  537. data.pageWrap[page].css({ width: pageWidth, height: height });
  538. if (data.pages[page])
  539. data.pages[page].css({ width: pageWidth, height: height });
  540. }
  541. this.turn('resize');
  542. return this;
  543. } else {
  544. return { width: this.width(), height: this.height() };
  545. }
  546. },
  547. // Resizes each page
  548. resize: function () {
  549. var page, data = this.data();
  550. if (data.pages[0]) {
  551. data.pageWrap[0].css({ left: -this.width() });
  552. data.pages[0].flip('resize', true);
  553. }
  554. for (page = 1; page <= data.totalPages; page++)
  555. if (data.pages[page])
  556. data.pages[page].flip('resize', true);
  557. },
  558. // Removes an animation from the cache
  559. _removeMv: function (page) {
  560. var i, data = this.data();
  561. for (i = 0; i < data.pageMv.length; i++)
  562. if (data.pageMv[i] == page) {
  563. data.pageMv.splice(i, 1);
  564. return true;
  565. }
  566. return false;
  567. },
  568. // Adds an animation to the cache
  569. _addMv: function (page) {
  570. var data = this.data();
  571. turnMethods._removeMv.call(this, page);
  572. data.pageMv.push(page);
  573. },
  574. // Gets indexes for a view
  575. _view: function (page) {
  576. var data = this.data();
  577. page = page || data.page;
  578. if (data.display == 'double')
  579. return (page % 2) ? [page - 1, page] : [page, page + 1];
  580. else
  581. return [page];
  582. },
  583. // Gets a view
  584. view: function (page) {
  585. var data = this.data(), view = turnMethods._view.call(this, page);
  586. return (data.display == 'double') ? [(view[0] > 0) ? view[0] : 0, (view[1] <= data.totalPages) ? view[1] : 0]
  587. : [(view[0] > 0 && view[0] <= data.totalPages) ? view[0] : 0];
  588. },
  589. // Stops animations
  590. stop: function (ok) {
  591. var i, opts, data = this.data(), pages = data.pageMv;
  592. data.pageMv = [];
  593. if (data.tpage) {
  594. data.page = data.tpage;
  595. delete data['tpage'];
  596. }
  597. for (i in pages) {
  598. if (!has(i, pages)) continue;
  599. opts = data.pages[pages[i]].data().f.opts;
  600. flipMethods._moveFoldingPage.call(data.pages[pages[i]], null);
  601. data.pages[pages[i]].flip('hideFoldedPage');
  602. data.pagePlace[opts.next] = opts.next;
  603. if (opts.force) {
  604. opts.next = (opts.page % 2 === 0) ? opts.page - 1 : opts.page + 1;
  605. delete opts['force'];
  606. }
  607. }
  608. this.turn('update');
  609. return this;
  610. },
  611. // Gets and sets the number of pages
  612. pages: function (pages) {
  613. var data = this.data();
  614. if (pages) {
  615. if (pages < data.totalPages) {
  616. for (var page = pages + 1; page <= data.totalPages; page++)
  617. this.turn('removePage', page);
  618. if (this.turn('page') > pages)
  619. this.turn('page', pages);
  620. }
  621. data.totalPages = pages;
  622. return this;
  623. } else
  624. return data.totalPages;
  625. },
  626. // Sets a page without effect
  627. _fitPage: function (page, ok) {
  628. var data = this.data(), newView = this.turn('view', page);
  629. if (data.page != page) {
  630. this.trigger('turning', [page, newView]);
  631. if ($.inArray(1, newView) != -1) this.trigger('first');
  632. if ($.inArray(data.totalPages, newView) != -1) this.trigger('last');
  633. }
  634. if (!data.pageObjs[page])
  635. return;
  636. data.tpage = page;
  637. this.turn('stop', ok);
  638. turnMethods._removeFromDOM.call(this);
  639. turnMethods._makeRange.call(this);
  640. this.trigger('turned', [page, newView]);
  641. },
  642. // Turns to a page
  643. _turnPage: function (page) {
  644. var current, next,
  645. data = this.data(),
  646. view = this.turn('view'),
  647. newView = this.turn('view', page);
  648. if (data.page != page) {
  649. this.trigger('turning', [page, newView]);
  650. if ($.inArray(1, newView) != -1) this.trigger('first');
  651. if ($.inArray(data.totalPages, newView) != -1) this.trigger('last');
  652. }
  653. if (!data.pageObjs[page])
  654. return;
  655. data.tpage = page;
  656. this.turn('stop');
  657. turnMethods._makeRange.call(this);
  658. if (data.display == 'single') {
  659. current = view[0];
  660. next = newView[0];
  661. } else if (view[1] && page > view[1]) {
  662. current = view[1];
  663. next = newView[0];
  664. } else if (view[0] && page < view[0]) {
  665. current = view[0];
  666. next = newView[1];
  667. }
  668. if (data.pages[current]) {
  669. var opts = data.pages[current].data().f.opts;
  670. data.tpage = next;
  671. if (opts.next != next) {
  672. opts.next = next;
  673. data.pagePlace[next] = opts.page;
  674. opts.force = true;
  675. }
  676. if (data.display == 'single')
  677. data.pages[current].flip('turnPage', (newView[0] > view[0]) ? 'br' : 'bl');
  678. else
  679. data.pages[current].flip('turnPage');
  680. }
  681. },
  682. // Gets and sets a page
  683. page: function (page) {
  684. page = parseInt(page, 10);
  685. var data = this.data();
  686. if (page > 0 && page <= data.totalPages) {
  687. if (!data.done || $.inArray(page, this.turn('view')) != -1)
  688. turnMethods._fitPage.call(this, page);
  689. else
  690. turnMethods._turnPage.call(this, page);
  691. return this;
  692. } else
  693. return data.page;
  694. },
  695. // Turns to the next view
  696. next: function () {
  697. var data = this.data();
  698. return this.turn('page', turnMethods._view.call(this, data.page).pop() + 1);
  699. },
  700. // Turns to the previous view
  701. previous: function () {
  702. var data = this.data();
  703. return this.turn('page', turnMethods._view.call(this, data.page).shift() - 1);
  704. },
  705. // Adds a motion to the internal list
  706. _addMotionPage: function () {
  707. var opts = $(this).data().f.opts,
  708. turn = opts.turn,
  709. dd = turn.data();
  710. opts.pageMv = opts.page;
  711. turnMethods._addMv.call(turn, opts.pageMv);
  712. dd.pagePlace[opts.next] = opts.page;
  713. turn.turn('update');
  714. },
  715. // This event is called in context of flip
  716. _start: function (e, opts, corner) {
  717. var data = opts.turn.data(),
  718. event = $.Event('start');
  719. e.stopPropagation();
  720. opts.turn.trigger(event, [opts, corner]);
  721. if (event.isDefaultPrevented()) {
  722. e.preventDefault();
  723. return;
  724. }
  725. if (data.display == 'single') {
  726. var left = corner.charAt(1) == 'l';
  727. if ((opts.page == 1 && left) || (opts.page == data.totalPages && !left))
  728. e.preventDefault();
  729. else {
  730. if (left) {
  731. opts.next = (opts.next < opts.page) ? opts.next : opts.page - 1;
  732. opts.force = true;
  733. } else
  734. opts.next = (opts.next > opts.page) ? opts.next : opts.page + 1;
  735. }
  736. }
  737. turnMethods._addMotionPage.call(this);
  738. },
  739. // This event is called in context of flip
  740. _end: function (e, turned) {
  741. var that = $(this),
  742. data = that.data().f,
  743. opts = data.opts,
  744. turn = opts.turn,
  745. dd = turn.data();
  746. e.stopPropagation();
  747. if (turned || dd.tpage) {
  748. if (dd.tpage == opts.next || dd.tpage == opts.page) {
  749. delete dd['tpage'];
  750. turnMethods._fitPage.call(turn, dd.tpage || opts.next, true);
  751. }
  752. } else {
  753. turnMethods._removeMv.call(turn, opts.pageMv);
  754. turn.turn('update');
  755. }
  756. },
  757. // This event is called in context of flip
  758. _pressed: function () {
  759. var page,
  760. that = $(this),
  761. data = that.data().f,
  762. turn = data.opts.turn,
  763. pages = turn.data().pages;
  764. for (page in pages)
  765. if (page != data.opts.page)
  766. pages[page].flip('disable', true);
  767. return data.time = new Date().getTime();
  768. },
  769. // This event is called in context of flip
  770. _released: function (e, point) {
  771. var that = $(this),
  772. data = that.data().f;
  773. e.stopPropagation();
  774. if ((new Date().getTime()) - data.time < 200 || point.x < 0 || point.x > $(this).width()) {
  775. e.preventDefault();
  776. data.opts.turn.data().tpage = data.opts.next;
  777. data.opts.turn.turn('update');
  778. $(that).flip('turnPage');
  779. }
  780. },
  781. // This event is called in context of flip
  782. _flip: function () {
  783. var opts = $(this).data().f.opts;
  784. opts.turn.trigger('turn', [opts.next]);
  785. },
  786. // Calculate the z-index value for pages during the animation
  787. calculateZ: function (mv) {
  788. var i, page, nextPage, placePage, dpage,
  789. that = this,
  790. data = this.data(),
  791. view = this.turn('view'),
  792. currentPage = view[0] || view[1],
  793. r = { pageZ: {}, partZ: {}, pageV: {} },
  794. addView = function (page) {
  795. var view = that.turn('view', page);
  796. if (view[0]) r.pageV[view[0]] = true;
  797. if (view[1]) r.pageV[view[1]] = true;
  798. };
  799. for (i = 0; i < mv.length; i++) {
  800. page = mv[i];
  801. nextPage = data.pages[page].data().f.opts.next;
  802. placePage = data.pagePlace[page];
  803. addView(page);
  804. addView(nextPage);
  805. dpage = (data.pagePlace[nextPage] == nextPage) ? nextPage : page;
  806. r.pageZ[dpage] = data.totalPages - Math.abs(currentPage - dpage);
  807. r.partZ[placePage] = data.totalPages * 2 + Math.abs(currentPage - dpage);
  808. }
  809. return r;
  810. },
  811. // Updates the z-index and display property of every page
  812. update: function () {
  813. var page,
  814. data = this.data();
  815. if (data.pageMv.length && data.pageMv[0] !== 0) {
  816. // Update motion
  817. var apage,
  818. pos = this.turn('calculateZ', data.pageMv),
  819. view = this.turn('view', data.tpage);
  820. if (data.pagePlace[view[0]] == view[0]) apage = view[0];
  821. else if (data.pagePlace[view[1]] == view[1]) apage = view[1];
  822. for (page in data.pageWrap) {
  823. if (!has(page, data.pageWrap)) continue;
  824. data.pageWrap[page].css({ display: (pos.pageV[page]) ? '' : 'none', 'z-index': pos.pageZ[page] || 0 });
  825. if (data.pages[page]) {
  826. data.pages[page].flip('z', pos.partZ[page] || null);
  827. if (pos.pageV[page])
  828. data.pages[page].flip('resize');
  829. if (data.tpage)
  830. data.pages[page].flip('disable', true); // data.disabled || page!=apage
  831. }
  832. }
  833. } else {
  834. // Update static pages
  835. for (page in data.pageWrap) {
  836. if (!has(page, data.pageWrap)) continue;
  837. var pageLocation = turnMethods._setPageLoc.call(this, page);
  838. if (data.pages[page])
  839. data.pages[page].flip('disable', data.disabled || pageLocation != 1).flip('z', null);
  840. }
  841. }
  842. },
  843. // Sets the z-index and display property of a page
  844. // It depends on the current view
  845. _setPageLoc: function (page) {
  846. var data = this.data(),
  847. view = this.turn('view');
  848. if (page == view[0] || page == view[1]) {
  849. data.pageWrap[page].css({ 'z-index': data.totalPages, display: '' });
  850. return 1;
  851. } else if ((data.display == 'single' && page == view[0] + 1) || (data.display == 'double' && page == view[0] - 2 || page == view[1] + 2)) {
  852. data.pageWrap[page].css({ 'z-index': data.totalPages - 1, display: '' });
  853. return 2;
  854. } else {
  855. data.pageWrap[page].css({ 'z-index': 0, display: 'none' });
  856. return 0;
  857. }
  858. }
  859. },
  860. // Methods and properties for the flip page effect
  861. flipMethods = {
  862. // Constructor
  863. init: function (opts) {
  864. if (opts.gradients) {
  865. opts.frontGradient = true;
  866. opts.backGradient = true;
  867. }
  868. this.data({ f: {} });
  869. this.flip('options', opts);
  870. flipMethods._addPageWrapper.call(this);
  871. return this;
  872. },
  873. setData: function (d) {
  874. var data = this.data();
  875. data.f = $.extend(data.f, d);
  876. return this;
  877. },
  878. options: function (opts) {
  879. var data = this.data().f;
  880. if (opts) {
  881. flipMethods.setData.call(this, { opts: $.extend({}, data.opts || flipOptions, opts) });
  882. return this;
  883. } else
  884. return data.opts;
  885. },
  886. z: function (z) {
  887. var data = this.data().f;
  888. data.opts['z-index'] = z;
  889. data.fwrapper.css({ 'z-index': z || parseInt(data.parent.css('z-index'), 10) || 0 });
  890. return this;
  891. },
  892. _cAllowed: function () {
  893. return corners[this.data().f.opts.corners] || this.data().f.opts.corners;
  894. },
  895. _cornerActivated: function (e) {
  896. if (e.originalEvent === undefined) {
  897. return false;
  898. }
  899. e = (isTouch) ? e.originalEvent.touches : [e];
  900. var data = this.data().f,
  901. pos = data.parent.offset(),
  902. width = this.width(),
  903. height = this.height(),
  904. c = { x: Math.max(0, e[0].pageX - pos.left), y: Math.max(0, e[0].pageY - pos.top) },
  905. csz = data.opts.cornerSize,
  906. allowedCorners = flipMethods._cAllowed.call(this);
  907. if (c.x <= 0 || c.y <= 0 || c.x >= width || c.y >= height) return false;
  908. if (c.y < csz) c.corner = 't';
  909. else if (c.y >= height - csz) c.corner = 'b';
  910. else return false;
  911. if (c.x <= csz) c.corner += 'l';
  912. else if (c.x >= width - csz) c.corner += 'r';
  913. else return false;
  914. return ($.inArray(c.corner, allowedCorners) == -1) ? false : c;
  915. },
  916. _c: function (corner, opts) {
  917. opts = opts || 0;
  918. return ({
  919. tl: point2D(opts, opts),
  920. tr: point2D(this.width() - opts, opts),
  921. bl: point2D(opts, this.height() - opts),
  922. br: point2D(this.width() - opts, this.height() - opts)
  923. })[corner];
  924. },
  925. _c2: function (corner) {
  926. return {
  927. tl: point2D(this.width() * 2, 0),
  928. tr: point2D(-this.width(), 0),
  929. bl: point2D(this.width() * 2, this.height()),
  930. br: point2D(-this.width(), this.height())
  931. }[corner];
  932. },
  933. _foldingPage: function (corner) {
  934. var opts = this.data().f.opts;
  935. if (opts.folding) return opts.folding;
  936. else if (opts.turn) {
  937. var data = opts.turn.data();
  938. if (data.display == 'single')
  939. return (data.pageObjs[opts.next]) ? data.pageObjs[0] : null;
  940. else
  941. return data.pageObjs[opts.next];
  942. }
  943. },
  944. _backGradient: function () {
  945. var data = this.data().f,
  946. turn = data.opts.turn,
  947. gradient = data.opts.backGradient &&
  948. (!turn || turn.data().display == 'single' || (data.opts.page != 2 && data.opts.page != turn.data().totalPages - 1));
  949. if (gradient && !data.bshadow)
  950. data.bshadow = $('<div/>', divAtt(0, 0, 1)).
  951. css({ 'position': '', width: this.width(), height: this.height() }).
  952. appendTo(data.parent);
  953. return gradient;
  954. },
  955. resize: function (full) {
  956. var data = this.data().f,
  957. width = this.width(),
  958. height = this.height(),
  959. size = Math.round(Math.sqrt(Math.pow(width, 2) + Math.pow(height, 2)));
  960. if (full) {
  961. data.wrapper.css({ width: size, height: size });
  962. data.fwrapper.css({ width: size, height: size }).
  963. children(':first-child').
  964. css({ width: width, height: height });
  965. data.fpage.css({ width: height, height: width });
  966. if (data.opts.frontGradient)
  967. data.ashadow.css({ width: height, height: width });
  968. if (flipMethods._backGradient.call(this))
  969. data.bshadow.css({ width: width, height: height });
  970. }
  971. if (data.parent.is(':visible')) {
  972. data.fwrapper.css({
  973. top: data.parent.offset().top,
  974. left: data.parent.offset().left
  975. });
  976. if (data.opts.turn)
  977. data.fparent.css({ top: -data.opts.turn.offset().top, left: -data.opts.turn.offset().left });
  978. }
  979. this.flip('z', data.opts['z-index']);
  980. },
  981. // Prepares the page by adding a general wrapper and another objects
  982. _addPageWrapper: function () {
  983. var att,
  984. data = this.data().f,
  985. parent = this.parent();
  986. if (!data.wrapper) {
  987. var left = this.css('left'),
  988. top = this.css('top'),
  989. width = this.width(),
  990. height = this.height(),
  991. size = Math.round(Math.sqrt(Math.pow(width, 2) + Math.pow(height, 2)));
  992. data.parent = parent;
  993. data.fparent = (data.opts.turn) ? data.opts.turn.data().fparent : $('#turn-fwrappers');
  994. if (!data.fparent) {
  995. var fparent = $('<div/>', { css: { 'pointer-events': 'none' } }).hide();
  996. fparent.data().flips = 0;
  997. if (data.opts.turn) {
  998. fparent.css(divAtt(-data.opts.turn.offset().top, -data.opts.turn.offset().left, 'auto', 'visible').css).
  999. appendTo(data.opts.turn);
  1000. data.opts.turn.data().fparent = fparent;
  1001. } else {
  1002. fparent.css(divAtt(0, 0, 'auto', 'visible').css).
  1003. attr('id', 'turn-fwrappers').
  1004. appendTo($('body'));
  1005. }
  1006. data.fparent = fparent;
  1007. }
  1008. this.css({ position: 'absolute', top: 0, left: 0, bottom: 'auto', right: 'auto' });
  1009. data.wrapper = $('<div/>', divAtt(0, 0, this.css('z-index'))).
  1010. appendTo(parent).
  1011. prepend(this);
  1012. data.fwrapper = $('<div/>', divAtt(parent.offset().top, parent.offset().left)).
  1013. hide().
  1014. appendTo(data.fparent);
  1015. data.fpage = $('<div/>', { css: { cursor: 'default' } }).
  1016. appendTo($('<div/>', divAtt(0, 0, 0, 'visible')).
  1017. appendTo(data.fwrapper));
  1018. if (data.opts.frontGradient)
  1019. data.ashadow = $('<div/>', divAtt(0, 0, 1)).
  1020. appendTo(data.fpage);
  1021. // Save data
  1022. flipMethods.setData.call(this, data);
  1023. // Set size
  1024. flipMethods.resize.call(this, true);
  1025. }
  1026. },
  1027. // Takes a 2P point from the screen and applies the transformation
  1028. _fold: function (point) {
  1029. var that = this,
  1030. a = 0,
  1031. alpha = 0,
  1032. beta,
  1033. px,
  1034. gradientEndPointA,
  1035. gradientEndPointB,
  1036. gradientStartV,
  1037. gradientSize,
  1038. gradientOpacity,
  1039. mv = point2D(0, 0),
  1040. df = point2D(0, 0),
  1041. tr = point2D(0, 0),
  1042. width = this.width(),
  1043. height = this.height(),
  1044. folding = flipMethods._foldingPage.call(this),
  1045. tan = Math.tan(alpha),
  1046. data = this.data().f,
  1047. ac = data.opts.acceleration,
  1048. h = data.wrapper.height(),
  1049. o = flipMethods._c.call(this, point.corner),
  1050. top = point.corner.substr(0, 1) == 't',
  1051. left = point.corner.substr(1, 1) == 'l',
  1052. compute = function () {
  1053. var rel = point2D((o.x) ? o.x - point.x : point.x, (o.y) ? o.y - point.y : point.y),
  1054. tan = (Math.atan2(rel.y, rel.x)),
  1055. middle;
  1056. alpha = A90 - tan;
  1057. a = deg(alpha);
  1058. middle = point2D((left) ? width - rel.x / 2 : point.x + rel.x / 2, rel.y / 2);
  1059. var gamma = alpha - Math.atan2(middle.y, middle.x),
  1060. distance = Math.max(0, Math.sin(gamma) * Math.sqrt(Math.pow(middle.x, 2) + Math.pow(middle.y, 2)));
  1061. tr = point2D(distance * Math.sin(alpha), distance * Math.cos(alpha));
  1062. if (alpha > A90) {
  1063. tr.x = tr.x + Math.abs(tr.y * Math.tan(tan));
  1064. tr.y = 0;
  1065. if (Math.round(tr.x * Math.tan(PI - alpha)) < height) {
  1066. point.y = Math.sqrt(Math.pow(height, 2) + 2 * middle.x * rel.x);
  1067. if (top) point.y = height - point.y;
  1068. return compute();
  1069. }
  1070. }
  1071. if (alpha > A90) {
  1072. var beta = PI - alpha, dd = h - height / Math.sin(beta);
  1073. mv = point2D(Math.round(dd * Math.cos(beta)), Math.round(dd * Math.sin(beta)));
  1074. if (left) mv.x = - mv.x;
  1075. if (top) mv.y = - mv.y;
  1076. }
  1077. px = Math.round(tr.y / Math.tan(alpha) + tr.x);
  1078. var side = width - px,
  1079. sideX = side * Math.cos(alpha * 2),
  1080. sideY = side * Math.sin(alpha * 2);
  1081. df = point2D(Math.round((left ? side - sideX : px + sideX)), Math.round((top) ? sideY : height - sideY));
  1082. // GRADIENTS
  1083. gradientSize = side * Math.sin(alpha);
  1084. var endingPoint = flipMethods._c2.call(that, point.corner),
  1085. far = Math.sqrt(Math.pow(endingPoint.x - point.x, 2) + Math.pow(endingPoint.y - point.y, 2));
  1086. gradientOpacity = (far < width) ? far / width : 1;
  1087. if (data.opts.frontGradient) {
  1088. gradientStartV = gradientSize > 100 ? (gradientSize - 100) / gradientSize : 0;
  1089. gradientEndPointA = point2D(gradientSize * Math.sin(A90 - alpha) / height * 100, gradientSize * Math.cos(A90 - alpha) / width * 100);
  1090. if (top) gradientEndPointA.y = 100 - gradientEndPointA.y;
  1091. if (left) gradientEndPointA.x = 100 - gradientEndPointA.x;
  1092. }
  1093. if (flipMethods._backGradient.call(that)) {
  1094. gradientEndPointB = point2D(gradientSize * Math.sin(alpha) / width * 100, gradientSize * Math.cos(alpha) / height * 100);
  1095. if (!left) gradientEndPointB.x = 100 - gradientEndPointB.x;
  1096. if (!top) gradientEndPointB.y = 100 - gradientEndPointB.y;
  1097. }
  1098. //
  1099. tr.x = Math.round(tr.x);
  1100. tr.y = Math.round(tr.y);
  1101. return true;
  1102. },
  1103. transform = function (tr, c, x, a) {
  1104. var f = ['0', 'auto'], mvW = (width - h) * x[0] / 100, mvH = (height - h) * x[1] / 100,
  1105. v = { left: f[c[0]], top: f[c[1]], right: f[c[2]], bottom: f[c[3]] },
  1106. aliasingFk = (a != 90 && a != -90) ? (left ? -1 : 1) : 0;
  1107. x = x[0] + '% ' + x[1] + '%';
  1108. that.css(v).transform(rotate(a) + translate(tr.x + aliasingFk, tr.y, ac), x);
  1109. data.fpage.parent().css(v);
  1110. data.wrapper.transform(translate(-tr.x + mvW - aliasingFk, -tr.y + mvH, ac) + rotate(-a), x);
  1111. data.fwrapper.transform(translate(-tr.x + mv.x + mvW, -tr.y + mv.y + mvH, ac) + rotate(-a), x);
  1112. data.fpage.parent().transform(rotate(a) + translate(tr.x + df.x - mv.x, tr.y + df.y - mv.y, ac), x);
  1113. if (data.opts.frontGradient)
  1114. gradient(data.ashadow,
  1115. point2D(left ? 100 : 0, top ? 100 : 0),
  1116. point2D(gradientEndPointA.x, gradientEndPointA.y),
  1117. [[gradientStartV, 'rgba(0,0,0,0)'],
  1118. [((1 - gradientStartV) * 0.8) + gradientStartV, 'rgba(0,0,0,' + (0.2 * gradientOpacity) + ')'],
  1119. [1, 'rgba(255,255,255,' + (0.2 * gradientOpacity) + ')']],
  1120. 3,
  1121. alpha);
  1122. if (flipMethods._backGradient.call(that))
  1123. gradient(data.bshadow,
  1124. point2D(left ? 0 : 100, top ? 0 : 100),
  1125. point2D(gradientEndPointB.x, gradientEndPointB.y),
  1126. [[0.8, 'rgba(0,0,0,0)'],
  1127. [1, 'rgba(0,0,0,' + (0.3 * gradientOpacity) + ')'],
  1128. [1, 'rgba(0,0,0,0)']],
  1129. 3);
  1130. };
  1131. switch (point.corner) {
  1132. case 'tl':
  1133. point.x = Math.max(point.x, 1);
  1134. compute();
  1135. transform(tr, [1, 0, 0, 1], [100, 0], a);
  1136. data.fpage.transform(translate(-height, -width, ac) + rotate(90 - a * 2), '100% 100%');
  1137. folding.transform(rotate(90) + translate(0, -height, ac), '0% 0%');
  1138. break;
  1139. case 'tr':
  1140. point.x = Math.min(point.x, width - 1);
  1141. compute();
  1142. transform(point2D(-tr.x, tr.y), [0, 0, 0, 1], [0, 0], -a);
  1143. data.fpage.transform(translate(0, -width, ac) + rotate(-90 + a * 2), '0% 100%');
  1144. folding.transform(rotate(270) + translate(-width, 0, ac), '0% 0%');
  1145. break;
  1146. case 'bl':
  1147. point.x = Math.max(point.x, 1);
  1148. compute();
  1149. transform(point2D(tr.x, -tr.y), [1, 1, 0, 0], [100, 100], -a);
  1150. data.fpage.transform(translate(-height, 0, ac) + rotate(-90 + a * 2), '100% 0%');
  1151. folding.transform(rotate(270) + translate(-width, 0, ac), '0% 0%');
  1152. break;
  1153. case 'br':
  1154. point.x = Math.min(point.x, width - 1);
  1155. compute();
  1156. transform(point2D(-tr.x, -tr.y), [0, 1, 1, 0], [0, 100], a);
  1157. data.fpage.transform(rotate(90 - a * 2), '0% 0%');
  1158. folding.transform(rotate(90) + translate(0, -height, ac), '0% 0%');
  1159. break;
  1160. }
  1161. data.point = point;
  1162. },
  1163. _moveFoldingPage: function (bool) {
  1164. var data = this.data().f,
  1165. folding = flipMethods._foldingPage.call(this);
  1166. if (folding) {
  1167. if (bool) {
  1168. if (!data.fpage.children()[data.ashadow ? '1' : '0']) {
  1169. flipMethods.setData.call(this, { backParent: folding.parent() });
  1170. data.fpage.prepend(folding);
  1171. }
  1172. } else {
  1173. if (data.backParent)
  1174. data.backParent.prepend(folding);
  1175. }
  1176. }
  1177. },
  1178. _showFoldedPage: function (c, animate) {
  1179. var folding = flipMethods._foldingPage.call(this),
  1180. dd = this.data(),
  1181. data = dd.f;
  1182. if (!data.point || data.point.corner != c.corner) {
  1183. var event = $.Event('start');
  1184. this.trigger(event, [data.opts, c.corner]);
  1185. if (event.isDefaultPrevented())
  1186. return false;
  1187. }
  1188. if (folding) {
  1189. if (animate) {
  1190. var that = this, point = (data.point && data.point.corner == c.corner) ? data.point : flipMethods._c.call(this, c.corner, 1);
  1191. this.animatef({
  1192. from: [point.x, point.y], to: [c.x, c.y], duration: 500, frame: function (v) {
  1193. c.x = Math.round(v[0]);
  1194. c.y = Math.round(v[1]);
  1195. flipMethods._fold.call(that, c);
  1196. }
  1197. });
  1198. } else {
  1199. flipMethods._fold.call(this, c);
  1200. if (dd.effect && !dd.effect.turning)
  1201. this.animatef(false);
  1202. }
  1203. if (!data.fwrapper.is(':visible')) {
  1204. data.fparent.show().data().flips++;
  1205. flipMethods._moveFoldingPage.call(this, true);
  1206. data.fwrapper.show();
  1207. if (data.bshadow)
  1208. data.bshadow.show();
  1209. }
  1210. return true;
  1211. }
  1212. return false;
  1213. },
  1214. hide: function () {
  1215. var data = this.data().f,
  1216. folding = flipMethods._foldingPage.call(this);
  1217. if ((--data.fparent.data().flips) === 0)
  1218. data.fparent.hide();
  1219. this.css({ left: 0, top: 0, right: 'auto', bottom: 'auto' }).transform('', '0% 100%');
  1220. data.wrapper.transform('', '0% 100%');
  1221. data.fwrapper.hide();
  1222. if (data.bshadow)
  1223. data.bshadow.hide();
  1224. folding.transform('', '0% 0%');
  1225. return this;
  1226. },
  1227. hideFoldedPage: function (animate) {
  1228. var data = this.data().f;
  1229. if (!data.point) return;
  1230. var that = this,
  1231. p1 = data.point,
  1232. hide = function () {
  1233. data.point = null;
  1234. that.flip('hide');
  1235. that.trigger('end', [false]);
  1236. };
  1237. if (animate) {
  1238. var p4 = flipMethods._c.call(this, p1.corner),
  1239. top = (p1.corner.substr(0, 1) == 't'),
  1240. delta = (top) ? Math.min(0, p1.y - p4.y) / 2 : Math.max(0, p1.y - p4.y) / 2,
  1241. p2 = point2D(p1.x, p1.y + delta),
  1242. p3 = point2D(p4.x, p4.y - delta);
  1243. this.animatef({
  1244. from: 0,
  1245. to: 1,
  1246. frame: function (v) {
  1247. var np = bezier(p1, p2, p3, p4, v);
  1248. p1.x = np.x;
  1249. p1.y = np.y;
  1250. flipMethods._fold.call(that, p1);
  1251. },
  1252. complete: hide,
  1253. duration: 800,
  1254. hiding: true
  1255. });
  1256. } else {
  1257. this.animatef(false);
  1258. hide();
  1259. }
  1260. },
  1261. turnPage: function (corner) {
  1262. var that = this,
  1263. data = this.data().f;
  1264. corner = { corner: (data.corner) ? data.corner.corner : corner || flipMethods._cAllowed.call(this)[0] };
  1265. var p1 = data.point || flipMethods._c.call(this, corner.corner, (data.opts.turn) ? data.opts.turn.data().opts.elevation : 0),
  1266. p4 = flipMethods._c2.call(this, corner.corner);
  1267. this.trigger('flip').
  1268. animatef({
  1269. from: 0,
  1270. to: 1,
  1271. frame: function (v) {
  1272. var np = bezier(p1, p1, p4, p4, v);
  1273. corner.x = np.x;
  1274. corner.y = np.y;
  1275. flipMethods._showFoldedPage.call(that, corner);
  1276. },
  1277. complete: function () {
  1278. that.trigger('end', [true]);
  1279. },
  1280. duration: data.opts.duration,
  1281. turning: true
  1282. });
  1283. data.corner = null;
  1284. },
  1285. moving: function () {
  1286. return 'effect' in this.data();
  1287. },
  1288. isTurning: function () {
  1289. return this.flip('moving') && this.data().effect.turning;
  1290. },
  1291. _eventStart: function (e) {
  1292. var data = this.data().f;
  1293. if (!data.disabled && !this.flip('isTurning')) {
  1294. data.corner = flipMethods._cornerActivated.call(this, e);
  1295. if (data.corner && flipMethods._foldingPage.call(this, data.corner)) {
  1296. flipMethods._moveFoldingPage.call(this, true);
  1297. this.trigger('pressed', [data.point]);
  1298. return false;
  1299. } else
  1300. data.corner = null;
  1301. }
  1302. },
  1303. _eventMove: function (e) {
  1304. var data = this.data().f;
  1305. if (!data.disabled) {
  1306. e = (isTouch) ? e.originalEvent.touches : [e];
  1307. if (data.corner) {
  1308. var pos = data.parent.offset();
  1309. data.corner.x = e[0].pageX - pos.left;
  1310. data.corner.y = e[0].pageY - pos.top;
  1311. flipMethods._showFoldedPage.call(this, data.corner);
  1312. } else if (!this.data().effect && this.is(':visible')) { // roll over
  1313. var corner = flipMethods._cornerActivated.call(this, e[0]);
  1314. if (corner) {
  1315. var origin = flipMethods._c.call(this, corner.corner, data.opts.cornerSize / 2);
  1316. corner.x = origin.x;
  1317. corner.y = origin.y;
  1318. flipMethods._showFoldedPage.call(this, corner, true);
  1319. } else
  1320. flipMethods.hideFoldedPage.call(this, true);
  1321. }
  1322. }
  1323. },
  1324. _eventEnd: function () {
  1325. var data = this.data().f;
  1326. if (!data.disabled && data.point) {
  1327. var event = $.Event('released');
  1328. this.trigger(event, [data.point]);
  1329. if (!event.isDefaultPrevented())
  1330. flipMethods.hideFoldedPage.call(this, true);
  1331. }
  1332. data.corner = null;
  1333. },
  1334. disable: function (disable) {
  1335. flipMethods.setData.call(this, { 'disabled': disable });
  1336. return this;
  1337. }
  1338. },
  1339. cla = function (that, methods, args) {
  1340. if (!args[0] || typeof (args[0]) == 'object')
  1341. return methods.init.apply(that, args);
  1342. else if (methods[args[0]] && args[0].toString().substr(0, 1) != '_')
  1343. return methods[args[0]].apply(that, Array.prototype.slice.call(args, 1));
  1344. else
  1345. throw args[0] + ' is an invalid value';
  1346. };
  1347. $.extend($.fn, {
  1348. flip: function (req, opts) {
  1349. return cla(this, flipMethods, arguments);
  1350. },
  1351. turn: function (req) {
  1352. return cla(this, turnMethods, arguments);
  1353. },
  1354. transform: function (transform, origin) {
  1355. var properties = {};
  1356. if (origin)
  1357. properties[vendor + 'transform-origin'] = origin;
  1358. properties[vendor + 'transform'] = transform;
  1359. return this.css(properties);
  1360. },
  1361. animatef: function (point) {
  1362. var data = this.data();
  1363. if (data.effect)
  1364. clearInterval(data.effect.handle);
  1365. if (point) {
  1366. if (!point.to.length) point.to = [point.to];
  1367. if (!point.from.length) point.from = [point.from];
  1368. if (!point.easing) point.easing = function (x, t, b, c, data) { return c * Math.sqrt(1 - (t = t / data - 1) * t) + b; };
  1369. var j, diff = [],
  1370. len = point.to.length,
  1371. that = this,
  1372. fps = point.fps || 30,
  1373. time = - fps,
  1374. f = function () {
  1375. var j, v = [];
  1376. time = Math.min(point.duration, time + fps);
  1377. for (j = 0; j < len; j++)
  1378. v.push(point.easing(1, time, point.from[j], diff[j], point.duration));
  1379. point.frame((len == 1) ? v[0] : v);
  1380. if (time == point.duration) {
  1381. clearInterval(data.effect.handle);
  1382. delete data['effect'];
  1383. that.data(data);
  1384. if (point.complete)
  1385. point.complete();
  1386. }
  1387. };
  1388. for (j = 0; j < len; j++)
  1389. diff.push(point.to[j] - point.from[j]);
  1390. data.effect = point;
  1391. data.effect.handle = setInterval(f, fps);
  1392. this.data(data);
  1393. f();
  1394. } else {
  1395. delete data['effect'];
  1396. }
  1397. }
  1398. });
  1399. $.isTouch = isTouch;
  1400. })(jQuery);
  1401. },
  1402. }
  1403. }
  1404. </script>
  1405. <!-- Add "scoped" attribute to limit CSS to this component only -->
  1406. <style>
  1407. /* @import '../css/style.css'; */
  1408. html{
  1409. height: 100%;
  1410. width: 100%;
  1411. }
  1412. body{
  1413. height: 100%;
  1414. width: 100%;
  1415. }
  1416. .boxbox{
  1417. padding-top: 10%;
  1418. height: 100%;
  1419. width: 100%;
  1420. margin: 0 auto;
  1421. text-align: center;
  1422. }
  1423. #flipbook{
  1424. margin: 0 auto;
  1425. text-align: center;
  1426. }
  1427. .top{
  1428. background-image:url(./../assets/1.jpg);
  1429. background-position:center;
  1430. background-size: 100%;
  1431. }
  1432. .top1{
  1433. background-image:url(./../assets/zs1.jpg);
  1434. background-position:center;
  1435. }
  1436. .hard{
  1437. background-color: #fff;
  1438. background-position:center;
  1439. background-size: 100%;
  1440. }
  1441. h3 {
  1442. margin: 40px 0 0;
  1443. }
  1444. ul {
  1445. list-style-type: none;
  1446. padding: 0;
  1447. }
  1448. li {
  1449. display: inline-block;
  1450. margin: 0 10px;
  1451. }
  1452. a {
  1453. color: #42b983;
  1454. }
  1455. </style>

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/weixin_40725706/article/detail/117232
推荐阅读
相关标签
  

闽ICP备14008679号