The technique of 3D turn-book special effects _javascript based on JavaScript HTML5

Source: Internet
Author: User

This is a very cool HTML5 3D book page animation, the effect is relatively simple, drag and drop the mouse simulation hand-page, more beautiful is the process of turning the page, showing a realistic 3D stereo effect. The text and pictures in the books will also be displayed in 3D, very cool.

Online Demo Source Download

HTML code

<div class= "book p3d" >
 <div class= "Back-cover p3d" >
 <div class= "page back Flip" ></div >
 <div class= "page front p3d" >
  <div class= "Shadow" ></div>
  <div class= "Dino" > </div>
 </div>
 </div>
 <div class= "Front-cover p3d" >
 <div class= "page Front Flip P3d ">
  <p>lorem ipsum dolor sit amet, consectetur adipiscing. Nam fermentum nisl quis nulla eleifend dignissim. Curabitur varius lobortis tincidunt. Maecenas gravida, nulla quis luctus imperdiet, ipsum nibh consectetur ante, in Sodales Massa tortor eget. Donec Porta Ligula massa, id sagittis est. ut nisl tellus, faucibus nec feugiat ut, laoreet iaculis. Suspendisse ultrices mauris vel tellus suscipit. Integer vitae tortor erat. Pellentesque non tempor nisi.</p>
 </div>
 <div class= "page back" ></div>
 </ Div>
</div>

CSS Code

. book {width:300px;
 height:300px;
 Margin-top: -150px;
 Position:absolute;
 left:50%;
 top:50%;
 -webkit-transform:rotatex (60DEG);
 -moz-transform:rotatex (60DEG);
 -ms-transform:rotatex (60DEG);
 -o-transform:rotatex (60DEG);
 Transform:rotatex (60DEG);
 -webkit-user-select:none;
 -moz-user-select:none;
 -ms-user-select:none;
 -o-user-select:none;
User-select:none;
 }. page {width:300px;
 height:300px;
 Padding:1em;
 Position:absolute;
 left:0;
 top:0;
Text-indent:2em;
 }. Front {background-color: #d93e2b;} back {background-color: #fff;} front-cover {cursor:move;
 -webkit-transform-origin:0 50%;
 -moz-transform-origin:0 50%;
 -ms-transform-origin:0 50%;
 -o-transform-origin:0 50%;
 Transform-origin:0 50%;
 -webkit-transform:rotatey (0DEG);
 -moz-transform:rotatey (0DEG);
 -ms-transform:rotatey (0DEG);
 -o-transform:rotatey (0DEG);
Transform:rotatey (0DEG);
 }. Front-cover. Back {Background-image:url (mdn.png);
 Background-repeat:no-repeat; Background-position:50% 50%;
 -webkit-transform:translatez (3PX);
 -moz-transform:translatez (3PX);
 -ms-transform:translatez (3PX);
 -o-transform:translatez (3PX);
Transform:translatez (3PX);
 }. Back-cover. Back {-webkit-transform:translatez ( -3px);
 -moz-transform:translatez ( -3PX);
 -ms-transform:translatez ( -3PX);
 -o-transform:translatez ( -3PX); 
Transform:translatez ( -3PX);
 }. p3d {-webkit-transform-style:preserve-3d;
 -moz-transform-style:preserve-3d;
 -ms-transform-style:preserve-3d;
 -o-transform-style:preserve-3d;
transform-style:preserve-3d;
 Flip {-webkit-transform:rotatey (180deg);
 -moz-transform:rotatey (180DEG);
 -ms-transform:rotatey (180DEG);
 -o-transform:rotatey (180DEG);
Transform:rotatey (180DEG);
 }. Dino, shadow {width:196px;
 height:132px;
 Position:absolute;
 left:60px;
 top:60px;
 -webkit-transform-origin:0 100%;
 -moz-transform-origin:0 100%;
 -ms-transform-origin:0 100%;
 -o-transform-origin:0 100%;
Transform-origin:0 100%; }
.Dino {Background:url (dino.png) no-repeat;

 }. Shadow {Background:url (Shadow.png) no-repeat;}

JavaScript code

(Function (window, document) {var prefixes = [' Webkit ', ' Moz ', ' Ms ', ' O ', '], book = Document.queryselectorall ('. Boo K ') [0], page = Document.queryselectorall ('. Front-cover ') [0], Dino = Document.queryselectorall ('. Dino ') [0], shadow = doc Ument.queryselectorall ('. Shadow ') [0], hold = false, CenterPoint = WINDOW.INNERWIDTH/2, pageSize =, clamp = funct
 Ion (Val, Min, max) {return Math.max (min, Math.min (val, Max));

 };
 Page.onmousedown = function () {hold = true;

 };
 Window.onmouseup = function () {if (hold) {hold = false;

 }
 };
 Window.onresize = function () {centerpoint = WINDOW.INNERWIDTH/2;

 };
 Window.onmousemove = function (evt) {if (!hold) {return;

 var angle = Clamp (Centerpoint-evt.pagex + pageSize)/pageSize * -90, -180, 0), I, J;  for (i = 0, j = prefixes.length I < J; i++) {book.style[prefixes[i] + ' Transform '] = ' Rotatex (' + (+ ANGLE/8) +
 ' Deg ';
 Page.style[prefixes[i] + ' Transform '] = ' rotatey (' + angle + ' deg '); Dino. style[prefixes[i] + ' Transform '] = ' Rotatex (' + (ANGLE/2) + ' deg ');
 Shadow.style[prefixes[i] + ' Transform '] = ' Translatez (1px) skewx (' + (ANGLE/8) + ' deg ');

}
 };
 }) (window, document);

The above is the HTML5 3D book page animation of the example code, I hope to learn about JavaScript programming help.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.