One Js demo every day: mobile-side panorama-panoramic decoration. Key knowledge points: css3, rotation angle detection, Panorama css3

Source: Internet
Author: User

One Js demo every day: mobile-side panorama-panoramic decoration. Key knowledge points: css3, rotation angle detection, Panorama css3

<! DOCTYPE html>
<Html lang = "en">
<Head>
<Meta name = "viewport" content = "width = device-width, user-scalable = no"/>
<Meta charset = "UTF-8">
<Title> Document </title>
<Style type = "text/css">
Body,
Html {
Margin: 0;
Height: 100%;
Overflow: hidden;
Position: relative;
}
. Wrap {
Position: relative;
Height: 100%;
}
. View,
. BoxZ,
. Box {
Position: absolute;
Left: 50%;
Top: 50%;
-Webkit-transform-style: preserve-3d;
Transform-style: preserve-3d;
}
. Box {
-Webkit-transform: rotateY (0deg );
Transform: rotateY (0deg );
-Webkit-animation: 36 s rotate infinite linear;
Animation: 36 s rotate infinite linear;
}
. Box span {
Position: absolute;
Left: 50%;
Top: 50%;
Margin:-512px 0 0-512px;
Width: 1024px;
Height: 1024px;
Text-align: center;
-Webkit-backface-visibility: hidden;
Backface-visibility: hidden;
/*
Back, the opposite of the angle and the parent angle is the background
*/
}
. Box span: nth-of-type (1 ){
-Webkit-transform: rotateY (0deg) translateZ (-510px );
Transform: rotateY (0deg) translateZ (-pixel px );
Background: URLs (img/neg-x.png) no-repeat;
}
. Box span: nth-of-type (2 ){
-Webkit-transform: rotateY (90deg) translateZ (-pixel px );
Transform: rotateY (90deg) translateZ (-pixel px );
Background: URLs (img/neg-z.png) no-repeat;
}
. Box span: nth-of-type (3 ){
-Webkit-transform: rotateY (180deg) translateZ (-pixel px );
Transform: rotateY (180deg) translateZ (-pixel px );
Background: URLs (img/pos-x.png) no-repeat;
}
. Box span: nth-of-type (4 ){
Background: URLs (img/pos-z.png) no-repeat;
-Webkit-transform: rotateY (270deg) translateZ (-pixel px );
Transform: rotateY (270deg) translateZ (-pixel px );
}
. Box span: nth-of-type (5 ){
Background: url (img/pos-y.png );
-Webkit-transform: rotateX (-90deg) translateZ (-pixel px );
Transform: rotateX (-90deg) translateZ (-pixel px );
}
. Box span: nth-of-type (6 ){
Background: url (img/neg-y.png );
-Webkit-transform: rotateX (90deg) translateZ (-pixel px );
Transform: rotateX (90deg) translateZ (-pixel px );
}
/*
Transform-origin Z axis settings, compatibility issues in ios
*/
# Loading {
Position: fixed;
Left: 0;
Top: 0;
Width: 100%;
Height: 100%;
Z-index: 10;
Background: # fff url (img/loading.gif) no-repeat center;
}
</Style>
</Head>
<Body>
<Div id = "loading"> </div>
<Script type = "text/javascript">
/* Check image Loading completed */
(Function (){
Var imgData = [
"Img/neg-x.png ",
"Img/neg-y.png ",
"Img/neg-z.png ",
"Img/pos-x.png ",
"Img/pos-y.png ",
"Img/pos-z.png"
];
Var nub = 0;
For (var I = 0; I Load (imgData [I]);
}
Function load (url ){
Var img = new Image ();
Img. onload = function (){
Nub ++;
If (nub = imgData. length ){
Loading. style. display = "none ";
}
};
Img. src = url;
}
})();
</Script>
<Div class = "wrap">
<Div class = "view">
<Div class = "boxZ">
<Div class = "box">
<Span> </span>
<Span> </span>
<Span> </span>
<Span> </span>
<Span> </span>
<Span> </span>
</Div>
</Div>
</Div>
</Div>
<Script type = "text/javascript" src = "js/m. touch. js"> </script>
<Script type = "text/javascript">
(Function (){
SetPerspective ();
Window. addEventListener ('resize', function (e ){
SetPerspective ();
});
Function setPerspective (){
Var wrap = document. querySelector ('. wrap ');
Var view = document. querySelector ('. view ');
Var boxZ = document. querySelector ('. boxz ');
Var deg = 45; // The angle of the field of view (the smaller the angle, the wider the range, the larger the angle, and the smaller the range );
Var Z = Math. round (Math. tan (deg * Math. PI/180) * wrap. clientHeight/2); // calculates the depth of field
Wrap. style. perspective = wrap. style. WebKitPerspective = Z + "px ";
// The distance from the scene remains the same, so the size of the picture will remain unchanged.
Css (view, "translateZ", Z );
Css (boxZ, "translateZ",-100 );
}
})();
(Function (){
Var box = document. querySelector ('. box ');
Css (box, "rotateX", 0 );
Css (box, "rotateY", 0 );
Window. addEventListener ('deviceorientation', function (e ){
Var x = e. beta;
Var y = e. gamma;
Var z = e. alpha;
Var rotateX = x-90;
Var rotateY = (y + z) %360;
If (rotateX> 60 ){
RotateX = 60;
} Else if (rotateX <-60 ){
RotateX =-60;
}
Css (box, "rotateX", rotateX );
Css (box, "rotateY",-rotateY );
});
})();
// Http://antario.act.qq.com/
</Script>
</Body>
</Html>

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.