├── LICENSE ├── README.md ├── spherical.css └── spherical.js /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Chris Bateman 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Spherical.js 2 | ========= 3 | 4 | This was mainly a personal experiment to display spherical panoramas with CSS 3D transforms. You can see it in action [here] (http://chrisbateman.github.io/spherical/). 5 | 6 | The only thing you'll need to use it is a full 360x180 panorama, broken up into the six sides of a [cubic projection] (http://wiki.panotools.org/index.php?title=Cubic_Projection). Generating a cubic projection isn't too tricky with [Hugin] (http://hugin.sourceforge.net/). 7 | 8 | Include the JS and CSS, make a <div> for it to live in, and instantiate it: 9 | 10 | ```javascript 11 | new Spherical({ 12 | container: '#pano', 13 | front: 'images/front.jpg', 14 | back: 'images/back.jpg', 15 | left: 'images/left.jpg', 16 | right: 'images/right.jpg', 17 | top: 'images/top.jpg', 18 | bottom: 'images/bottom.jpg' 19 | }); 20 | ``` 21 | 22 | - Spherical.js works in Chrome, Firefox, iOS, and hopefully Android 4+. IE's a no-go until they start supporting preserve-3d. 23 | - Includes full-screen mode for browsers that support the Fullscreen API. 24 | - Zooming works, but is a bit buggy at the moment. 25 | - Supports AMD. 26 | 27 | This was a lot of fun to build, but if you need something a bit more robust, I'd take a look at [krpano] (http://krpano.com/), or even [three.js] (http://threejs.org/examples/#canvas_geometry_panorama), which can render out to CSS, canvas, or WebGL. 28 | -------------------------------------------------------------------------------- /spherical.css: -------------------------------------------------------------------------------- 1 | .spherical-container { 2 | position: relative; 3 | overflow: hidden; 4 | -webkit-user-select: none; 5 | -moz-user-select: -moz-none; 6 | -ms-user-select: none; 7 | user-select: none; 8 | cursor: move; 9 | } 10 | .spherical-cube { 11 | width: 800px; 12 | height: 800px; 13 | position: absolute; 14 | left: 50%; 15 | top: 50%; 16 | margin: -400px 0 0 -400px; 17 | -webkit-transform-style: preserve-3d; 18 | transform-style: preserve-3d; 19 | } 20 | .spherical-cube > div { 21 | background-color: #000; 22 | width: inherit; 23 | height: inherit; 24 | position: absolute; 25 | background-repeat: no-repeat; 26 | background-size: cover; 27 | transform-style: preserve-3d; 28 | } 29 | 30 | .spherical-cube .spherical-front { 31 | -webkit-transform: translateZ(-398px); 32 | transform: translateZ(-398px); 33 | } 34 | .spherical-cube .spherical-back { 35 | -webkit-transform: rotateY(180deg) translateZ(-398px); 36 | transform: rotateY(180deg) translateZ(-398px); 37 | } 38 | .spherical-cube .spherical-left { 39 | -webkit-transform: rotateY(90deg) translateZ(-398px); 40 | transform: rotateY(90deg) translateZ(-398px); 41 | } 42 | .spherical-cube .spherical-right { 43 | -webkit-transform: rotateY(-90deg) translateZ(-398px); 44 | transform: rotateY(-90deg) translateZ(-398px); 45 | } 46 | .spherical-cube .spherical-top { 47 | -webkit-transform: rotateX(-90deg) translateZ(-398px); 48 | transform: rotateX(-90deg) translateZ(-398px); 49 | } 50 | .spherical-cube .spherical-bottom { 51 | -webkit-transform: rotateX(90deg) translateZ(-398px); 52 | transform: rotateX(90deg) translateZ(-398px); 53 | } 54 | 55 | .spherical-container:-webkit-full-screen { 56 | width: 100% !important; 57 | height: 100% !important; 58 | } 59 | .spherical-container:full-screen { 60 | width: 100% !important; 61 | height: 100% !important; 62 | } 63 | 64 | .spherical-container.spherical-pseudo-fs { 65 | position: fixed !important; 66 | left: 0; 67 | right: 0; 68 | top: 0; 69 | bottom: 0; 70 | width: auto !important; 71 | height: auto !important; 72 | z-index: 1; 73 | } 74 | 75 | .spherical-fullbutton { 76 | width: 16px; 77 | height: 16px; 78 | padding: 12px; 79 | background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQBAMAAADt3eJSAAAAJFBMVEUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACmWAJHAAAAC3RSTlMAFYTc93m7xIwoJdcuXkAAAABcSURBVAjXY9i9exMDg/bu3UBGAAMDK4ixRYCBgdEbyPA2ZGAQ3rKbYZPwNgaGbENtBgXGLAaGZQJMDMSAAMZMBoZpAqwMW4W3MzBUG0YjDERYsbuBgYEDaCnMGQAADCA2TyNOPQAAAABJRU5ErkJggg==) transparent no-repeat center; 80 | opacity: 0.4; 81 | cursor: pointer; 82 | border: 0 none; 83 | z-index: 1; 84 | position: absolute; 85 | bottom: 0; 86 | right: 0; 87 | -webkit-transform: translateZ(0); 88 | transform: translateZ(0); 89 | } -------------------------------------------------------------------------------- /spherical.js: -------------------------------------------------------------------------------- 1 | // UMD - https://github.com/umdjs/umd/blob/master/amdWeb.js 2 | (function (root, moduleFactory) { 3 | if (typeof define === 'function' && define.amd) { 4 | define(['impetus'], moduleFactory); 5 | } else { 6 | root.Spherical = moduleFactory(root.Impetus); 7 | } 8 | }(this, function (Impetus) { 9 | 10 | var Spherical = function(cfg) { 11 | 'use strict'; 12 | 13 | var _container; 14 | var _cube; 15 | var _cubeZ; 16 | var _cubeRotateX = 0; 17 | var _cubeRotateY = 0; 18 | var _impetus; 19 | var _enableFullscreen = true; 20 | var _isFullscreen = false; 21 | var _fsButton; 22 | var _supportsFullscreenAPI = !!document.webkitCancelFullScreen || !!document.mozCancelFullScreen || !!document.cancelFullScreen; 23 | var _fullscreenEnabled = document.fullscreenEnabled || document.mozFullScreenEnabled || document.documentElement.webkitRequestFullScreen; 24 | var _cubeTemplate = '