HTML+CSS+JavaScript实现图片3D展览的示例代码_html5教程技巧

来源:脚本之家  责任编辑:小易  

@1653-webkit-keyframes rotate{from{-webkit-transform: rotate(0deg)}to{-webkit-transform: rotate(360deg)}}@-moz-keyframes rotate{from{-moz-transform: rotate(0deg)}to{-moz-transform: rotate(359deg)}}@-o-keyframes rotate{from{-o-transform: rotate(0deg)}to{-o-transform: rotate(359deg)}}@keyframes rotate{from{transform: rotate(0deg)}to{transform: rotate(359deg)}}.cicle{border-radius:100%;-webkit-animation: rotate .3s linear infinite;-moz-animation: rotate .3s linear infinite;-o-animation: rotate .3s linear infinite;animation: rotate .3s linear infinite;}<img src="..." class="cicle">追问比如我有五张图片呢。。不只一张就是五张图片O形转追答五张图片都加上class="cicle" 这个类就可以了,border-radius:30px;width:30px;height:30px;这是一个园追问我想实现的是几张图片O形运动的哦,我想实现的是几张图片O形运动的哦,本回答被网友采纳www.zgxue.com防采集请勿采集本网。

一、图片3D展览效果

1、新建一个html文件,命名为test.html,在test.html文件内,使用img标签创建一张图片,图片是images文件夹下面的1.jpg。 2、为了展示隐藏图片后的效果,在img标签的外部使用div标签,同时设置div标签的class属性为mydiv。 3、在test.html文件内

上传图片的大小有限制,录制的GIF图展示效果不是很好

123456 .test1{ transform:rotate(360deg);/*旋转代码*/ transition:all 1s linear;/*可以不需要,只是为了能让你看到这个过程*/ }

图片3D展览效果

录屏的效果见链接:https://www.bilibili.com/video/BV1Bi4y1E7wk/

html,body {margin:0; padding:0; overflow:hidden}section {width:100vw; height:100vw}div {width:calc(100% - 5vw); height:calc(100% - 5vw); padding:2vw; border:0.5vw solid black; border-radius:50%}window.onload=function(){ var div

二、代码实现

、 看是这些吗?是的话采纳下,私信我发给你!

1. HTML代码

加入正方形宽高为100px, ul li:nth-child(1){background-color: red;transform: translate(-100px) rotateY(90deg);}ul li:nth-child(2){background-color: blue;transform: translate(100px) rotateY(90deg);}ul li:nth-child(3){background-c

<!DOCTYPE HTML><html><head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"> <meta name="HandheldFriendly" content="true"> <meta name="description" content="图片3D展览屋"> <meta name="keywords" content="canvas,3D_picture,perspective,texturing,gallery"> <link href="res/slider-wb.css" rel="stylesheet"> <title>图片3D展览屋</title> <style> html { overflow:visible; -ms-touch-action: none; -ms-content-zooming: none; } body { position: absolute; margin: 0px; padding: 0px; background: #fff; width: 100%; height: 100%; } #canvas { position: absolute; width: 100%; height: 100%; background: #fff; } </style> <script type="text/javascript" src="res/ge1doot.js"></script> <script type="text/javascript"> "use strict"; (function () { /* ==== definitions ==== */ var diapo = [], layers = [], ctx, pointer, scr, camera, light, fps = 0, quality = [1, 2], // ---- poly constructor ----Poly = function (parent, face) { this.parent = parent; this.ctx = ctx; this.color = face.fill || false; this.points = []; if (!face.img) { // ---- create points ---- for (var i = 0; i < 4; i++) { this.points[i] = new ge1doot.transform3D.Point(parent.pc.x + (face.x[i] * parent.normalZ) + (face.z[i] * parent.normalX),parent.pc.y + face.y[i],parent.pc.z + (face.x[i] * parent.normalX) + (-face.z[i] * parent.normalZ)); } this.points[3].next = false; }}, // ---- diapo constructor ----Diapo = function (path, img, structure) { // ---- create image ---- this.img = new ge1doot.transform3D.Image(this, path + img.img, 1, { isLoaded: function (img) { img.parent.isLoaded = true; img.parent.loaded(img); }}); this.visible = false; this.normalX = img.nx; this.normalZ = img.nz; // ---- point center ---- this.pc = new ge1doot.transform3D.Point(img.x, img.y, img.z); // ---- target positions ---- this.tx = img.x + (img.nx * Math.sqrt(camera.focalLength) * 20); this.tz = img.z - (img.nz * Math.sqrt(camera.focalLength) * 20); // ---- create polygons ---- this.poly = []; for (var i = -1, p; p = structure[++i]; ) { layers[i] = (p.img === true ? 1 : 2); this.poly.push(new Poly(this, p)); }}, // ---- init section ----init = function (json) { // draw poly primitive Poly.prototype.drawPoly = ge1doot.transform3D.drawPoly; // ---- init screen ---- scr = new ge1doot.Screen({ container: "canvas" }); ctx = scr.ctx; scr.resize(); // ---- init pointer ---- pointer = new ge1doot.Pointer({ tap: function () { if (camera.over) { if (camera.over === camera.target.elem) { // ---- return to the center ---- camera.target.x = 0; camera.target.z = 0; camera.target.elem = false; } else { // ---- goto diapo ---- camera.target.elem = camera.over; camera.target.x = camera.over.tx; camera.target.z = camera.over.tz; // ---- adapt tesselation level to distance ---- for (var i = 0, d; d = diapo[i++]; ) { var dx = camera.target.x - d.pc.x; var dz = camera.target.z - d.pc.z; var dist = Math.sqrt(dx * dx + dz * dz); var lev = (dist > 1500) ? quality[0] : quality[1]; d.img.setLevel(lev); } } } } }); // ---- init camera ---- camera = new ge1doot.transform3D.Camera({ focalLength: Math.sqrt(scr.width) * 10, easeTranslation: 0.025, easeRotation: 0.06, disableRz: true }, { move: function () { this.over = false; // ---- rotation ---- if (pointer.isDraging) { this.target.elem = false; this.target.ry = -pointer.Xi * 0.01; this.target.rx = (pointer.Y - scr.height * 0.5) / (scr.height * 0.5); } else { if (this.target.elem) { this.target.ry = Math.atan2(this.target.elem.pc.x - this.x,this.target.elem.pc.z - this.z); } } this.target.rx *= 0.9; } }); camera.z = -10000; camera.py = 0; // ---- create images ---- for (var i = 0, img; img = json.imgdata[i++]; ) { diapo.push(new Diapo(json.options.imagesPath,img,json.structure)); } // ---- start engine ---- >>> setInterval(function () { quality = (fps > 50) ? [2, 3] : [1, 2]; fps = 0; }, 1000); run();}, // ---- main loop ----run = function () { // ---- clear screen ---- ctx.clearRect(0, 0, scr.width, scr.height); // ---- camera ---- camera.move(); // ---- draw layers ---- for (var k = -1, l; l = layers[++k]; ) { light = false; for (var i = 0, d; d = diapo[i++]; ) { (l === 1 && d.draw()) ||(d.visible && d.poly[k].draw()); } } // ---- cursor ---- if (camera.over && !pointer.isDraging) { scr.setCursor("pointer"); } else { scr.setCursor("move"); } // ---- loop ---- fps++; requestAnimFrame(run);}; /* ==== prototypes ==== */ Poly.prototype.draw = function () { // ---- color light ---- var c = this.color; if (c.light || !light) { var s = c.light ? this.parent.light : 1; // ---- rgba color ---- light = "rgba(" +Math.round(c.r * s) + "," +Math.round(c.g * s) + "," +Math.round(c.b * s) + "," + (c.a || 1) + ")"; ctx.fillStyle = light; } // ---- paint poly ---- if (!c.light || this.parent.light < 1) { // ---- projection ---- for (var i = 0;this.points[i++].projection();); this.drawPoly(); ctx.fill(); } } /* ==== image onload ==== */ Diapo.prototype.loaded = function (img) { // ---- create points ---- var d = [-1, 1, 1, -1, 1, 1, -1, -1]; var w = img.texture.width * 0.5; var h = img.texture.height * 0.5; for (var i = 0; i < 4; i++) { img.points[i] = new ge1doot.transform3D.Point(this.pc.x + (w * this.normalZ * d[i]),this.pc.y + (h * d[i + 4]),this.pc.z + (w * this.normalX * d[i])); } } /* ==== images draw ==== */ Diapo.prototype.draw = function () { // ---- visibility ---- this.pc.projection(); if (this.pc.Z > -(camera.focalLength >> 1) && this.img.transform3D(true)) { // ---- light ---- this.light = 0.5 + Math.abs(this.normalZ * camera.cosY - this.normalX * camera.sinY) * 0.6; // ---- draw image ---- this.visible = true; this.img.draw(); // ---- test pointer inside ---- if (pointer.hasMoved || pointer.isDown) { if (this.img.isPointerInside(pointer.X,pointer.Y)) camera.over = this; } } else this.visible = false; return true; } return { // --- load data ---- load: function (data) { window.addEventListener('load', function () { ge1doot.loadJS("res/imageTransform3D.js",init, data); }, false); } } })().load({ imgdata: [ // north{img: 'imgs/001.jpg', x: -1000, y: 0, z: 1500, nx: 0, nz: 1 },{ img: 'imgs/002.jpg', x: 0, y: 0, z: 1500, nx: 0, nz: 1 },{ img: 'imgs/003.jpg', x: 1000, y: 0, z: 1500, nx: 0, nz: 1 }, // east{img: 'imgs/004.jpg', x: 1500, y: 0, z: 1000, nx: -1, nz: 0 },{ img: 'imgs/005.jpg', x: 1500, y: 0, z: 0, nx: -1, nz: 0 },{ img: 'imgs/006.jpg', x: 1500, y: 0, z: -1000, nx: -1, nz: 0 }, // south{img: 'imgs/007.jpg', x: 1000, y: 0, z: -1500, nx: 0, nz: -1 },{ img: 'imgs/008.jpg', x: 0, y: 0, z: -1500, nx: 0, nz: -1 },{ img: 'imgs/009.jpg', x: -1000, y: 0, z: -1500, nx: 0, nz: -1 }, // west{img: 'imgs/010.jpg', x: -1500, y: 0, z: -1000, nx: 1, nz: 0 },{ img: 'imgs/011.jpg', x: -1500, y: 0, z: 0, nx: 1, nz: 0 },{ img: 'imgs/012.jpg', x: -1500, y: 0, z: 1000, nx: 1, nz: 0 }], structure: [{ // wall fill: { r: 255, g: 255, b: 255, light: 1 }, x: [-1001, -490, -490, -1001], z: [-500, -500, -500, -500], y: [500, 500, -500, -500]}, { // wall fill: { r: 255, g: 255, b: 255, light: 1 }, x: [-501, 2, 2, -500], z: [-500, -500, -500, -500], y: [500, 500, -500, -500]}, { // wall fill: { r: 255, g: 255, b: 255, light: 1 }, x: [0, 502, 502, 0], z: [-500, -500, -500, -500], y: [500, 500, -500, -500]}, { // wall fill: { r: 255, g: 255, b: 255, light: 1 }, x: [490, 1002, 1002, 490], z: [-500, -500, -500, -500], y: [500, 500, -500, -500]}, { // shadow fill: { r: 0, g: 0, b: 0, a: 0.2 }, x: [-420, 420, 420, -420], z: [-500, -500, -500, -500], y: [150, 150, -320, -320]}, { // shadow fill: { r: 0, g: 0, b: 0, a: 0.2 }, x: [-20, 20, 20, -20], z: [-500, -500, -500, -500], y: [250, 250, 150, 150]}, { // shadow fill: { r: 0, g: 0, b: 0, a: 0.2 }, x: [-20, 20, 20, -20], z: [-500, -500, -500, -500], y: [-320, -320, -500, -500]}, { // shadow fill: { r: 0, g: 0, b: 0, a: 0.2 }, x: [-20, 20, 10, -10], z: [-500, -500, -100, -100], y: [-500, -500, -500, -500]}, { // base fill: { r: 32, g: 32, b: 32 }, x: [-50, 50, 50, -50], z: [-150, -150, -50, -50], y: [-500, -500, -500, -500]}, { // support fill: { r: 16, g: 16, b: 16 }, x: [-10, 10, 10, -10], z: [-100, -100, -100, -100], y: [300, 300, -500, -500]}, { // frame fill: { r: 255, g: 255, b: 255 }, x: [-320, -320, -320, -320], z: [0, -20, -20, 0], y: [-190, -190, 190, 190]}, { // frame fill: { r: 255, g: 255, b: 255 }, x: [320, 320, 320, 320], z: [0, -20, -20, 0], y: [-190, -190, 190, 190]},{ img: true },{ // ceilingLight fill: { r: 255, g: 128, b: 0 }, x: [-50, 50, 50, -50], z: [450, 450, 550, 550], y: [500, 500, 500, 500]}, { // groundLight fill: { r: 255, g: 128, b: 0 }, x: [-50, 50, 50, -50], z: [450, 450, 550, 550], y: [-500, -500, -500, -500]}], options: { imagesPath: "" } });</script></head><body><a href="https://blog.csdn.net/fyfugoyfa/article/details/108845194" target="_blank">CSDN文章</a><br /> <canvas id="canvas">建议用谷歌浏览器打开</canvas></body></html>

2. CSS代码

#icon {background: rgb(255, 144, 0); border-radius: 6px 0px 0px; transition:0.6s ease-in-out; left: 65px; top: 6px; width: 40px; height: 40px; overflow: hidden; position: relative; cursor: pointer; -moz-transition: all 0.6s ease-in-out 0s; -webkit-transition: all 0.6s ease-in-out 0s; -o-transition: all 0.6s ease-in-out 0s;}#icon div {background: none; position: absolute;}#icon div:nth-child(1) {border-width: 7px 0px 7px 8px; border-style: solid; border-color: transparent rgb(255, 255, 255); left: 20px; top: 50%; width: 0px; height: 0px; margin-top: -7px; position: absolute;}#icon div:nth-child(2) {background: rgb(255, 255, 255); left: 12px; top: 50%; width: 8px; height: 6px; margin-top: -3px; position: absolute;}#nav {top: 10px; width: 100px; height: 0px; position: absolute; -ms-user-select: none; -webkit-user-select: none; -moz-user-select: none;}#nav-switch {display: none;}#nav .label {display: block; cursor: pointer;}#nav .container {transition:left 0.3s ease-in-out; left: -100px; width: 100%; position: absolute; -moz-transition: left 0.3s ease-in-out 0s; -webkit-transition: left 0.3s ease-in-out 0s; -o-transition: left 0.3s ease-in-out 0s;}#nav .container > div {padding: 0px; width: 50%; float: left;}#nav .container .nav-on {color: rgb(51, 51, 51); padding-left: 0px;}#nav .container .nav-off {width: 40px; height: 40px; padding-right: 10px;}:checked#nav-switch + .label .container {left: 10px;}:checked#nav-switch + .label #icon {background: rgb(0, 101, 203); border-radius: 0px 0px 6px; transform: rotate(-180deg); -webkit-transform: rotate(-180deg); -moz-transform: rotate(-180deg); -o-transform: rotate(-180deg);}.title {margin: 0px; padding: 0px; left: 170px; top: 2px; height: 40px; color: rgb(51, 51, 51); line-height: 40px; font-family: "Segoe UI Light", "Segoe UI", Frutiger, "Frutiger Linotype", "Dejavu Sans", "Helvetica Neue", Arial, sans-serif; font-size: 24px; font-weight: bold; white-space: nowrap; position: absolute; -ms-user-select: none; -webkit-user-select: none; -moz-user-select: none; -o-user-select: none; user-select: none;}.menu {margin: 0px; padding: 0px; left: 0px; top: 6px; color: rgb(51, 51, 51); font-family: "Segoe UI Light", "Segoe UI", Frutiger, "Frutiger Linotype", "Dejavu Sans", "Helvetica Neue", Arial, sans-serif; font-size: 1em; font-weight: lighter; list-style-type: none; position: relative; cursor: pointer;}.menu li {list-style: none; width: 100px; height: 40px; border-right-color: rgb(221, 221, 221); border-right-width: 1px; border-right-style: solid; position: relative; cursor: pointer;}.menu a {color: rgb(51, 51, 51); line-height: 40px; padding-left: 40px; text-decoration: none; display: block; position: relative;}.menu li a:hover {background: rgb(255, 144, 0);}.menu li a:focus {background: rgb(255, 144, 0);}.menu li a:active {background: rgb(255, 144, 0);}#nav li::before {top: 50%; margin-left: 10px; position: absolute; content: "";}#nav li::after {top: 50%; margin-left: 10px; position: absolute; content: "";}#nav li a::before {top: 50%; margin-left: 10px; position: absolute; content: "";}#nav li a::after {top: 50%; margin-left: 10px; position: absolute; content: "";}#nav .home a::before {border-width: 8px 7px; border-style: solid; border-color: transparent transparent rgb(51, 51, 51); left: 2px; margin-top: -16px;}#nav .home a::after {border-width: 3px 4px 0px; border-style: solid; border-color: rgb(51, 51, 51) rgb(51, 51, 51) transparent; left: 4px; width: 2px; height: 4px; margin-top: 0px;}#nav .arrow a::before {border-width: 7px 0px 7px 8px; border-style: solid; border-color: transparent rgb(51, 51, 51); left: 8px; margin-top: -7px;}#nav .arrow a::after {background: rgb(51, 51, 51); left: 0px; width: 8px; height: 6px; margin-top: -3px;}#nav .back.arrow a::before {border-width: 7px 8px 7px 0px; left: 0px;}#nav .back.arrow a::after {left: 8px;}#nav .list a::before {background: none; border-width: 6px 0px; border-style: double; border-color: rgb(51, 51, 51); left: 5px; top: 14px; width: 12px; height: 2px;}#nav .list a::after {background: none; border-width: 6px 0px; border-style: double; border-color: rgb(51, 51, 51); left: 1px; top: 14px; width: 2px; height: 2px;}

3. JavaScript代码

// ===== ge1doot global ===== js文件1var ge1doot = ge1doot || {json: null,screen: null,pointer: null,camera: null,loadJS: function (url, callback, data) {if (typeof url == "string") url = [url];var load = function (src) {var script = document.createElement("script");if (callback) {if (script.readyState){script.onreadystatechange = function () {if (script.readyState == "loaded" || script.readyState == "complete"){script.onreadystatechange = null;if (--n === 0) callback(data || false);}}} else {script.onload = function() {if (--n === 0) callback(data || false);}}}script.src = src;document.getElementsByTagName("head")[0].appendChild(script);}for (var i = 0, n = url.length; i < n; i++) load(url[i]);}}// ===== html/canvas container =====ge1doot.Screen = function (setup) {ge1doot.screen = this;this.elem = document.getElementById(setup.container) || setup.container;this.ctx = this.elem.tagName == "CANVAS" ? this.elem.getContext("2d") : false;this.style = this.elem.style;this.left = 0;this.top = 0;this.width = 0;this.height = 0;this.cursor = "default";this.setup = setup;this.resize = function () {var o = this.elem;this.width = o.offsetWidth;this.height = o.offsetHeight;for (this.left = 0, this.top = 0; o != null; o = o.offsetParent) {this.left += o.offsetLeft;this.top += o.offsetTop;}if (this.ctx) {this.elem.width = this.width;this.elem.height = this.height;}this.setup.resize && this.setup.resize();}this.setCursor = function (type) {if (type !== this.cursor && 'ontouchstart' in window === false) {this.cursor = type;this.style.cursor = type;}}window.addEventListener('resize', function () {ge1doot.screen.resize();}, false);!this.setup.resize && this.resize();}// ==== unified touch events handler ====ge1doot.Pointer = function (setup) {ge1doot.pointer = this;var self = this;var body = document.body;var html = document.documentElement;this.setup = setup;this.screen = ge1doot.screen;this.elem = this.screen.elem;this.X = 0;this.Y = 0;this.Xi = 0;this.Yi = 0;this.bXi = 0;this.bYi = 0;this.Xr = 0;this.Yr = 0;this.startX = 0;this.startY = 0;this.scale = 0;this.wheelDelta = 0;this.isDraging = false;this.hasMoved = false;this.isDown = false;this.evt = false;var sX = 0;var sY = 0;// prevent default behaviorif (setup.tap) this.elem.onclick = function () { return false; }if (!setup.documentMove) {document.ontouchmove = function(e) { e.preventDefault(); }}document.addEventListener("MSHoldVisual", function(e) { e.preventDefault(); }, false);if (typeof this.elem.style.msTouchAction != 'undefined') this.elem.style.msTouchAction = "none";this.pointerDown = function (e) {if (!this.isDown) {if (this.elem.setCapture) this.elem.setCapture();this.isDraging = false;this.hasMoved = false;this.isDown = true;this.evt = e;this.Xr = (e.clientX !== undefined ? e.clientX : e.touches[0].clientX);this.Yr = (e.clientY !== undefined ? e.clientY : e.touches[0].clientY);this.X = sX = this.Xr - this.screen.left;this.Y = sY = this.Yr - this.screen.top + ((html && html.scrollTop) || body.scrollTop);this.setup.down && this.setup.down(e);}}this.pointerMove = function(e) {this.Xr = (e.clientX !== undefined ? e.clientX : e.touches[0].clientX);this.Yr = (e.clientY !== undefined ? e.clientY : e.touches[0].clientY);this.X = this.Xr - this.screen.left;this.Y = this.Yr - this.screen.top + ((html && html.scrollTop) || body.scrollTop);if (this.isDown) {this.Xi = this.bXi + (this.X - sX);this.Yi = this.bYi - (this.Y - sY);}if (Math.abs(this.X - sX) > 11 || Math.abs(this.Y - sY) > 11) {this.hasMoved = true;if (this.isDown) {if (!this.isDraging) {this.startX = sX;this.startY = sY;this.setup.startDrag && this.setup.startDrag(e);this.isDraging = true;} else {this.setup.drag && this.setup.drag(e);}} else {sX = this.X;sY = this.Y;}}this.setup.move && this.setup.move(e);}this.pointerUp = function(e) {this.bXi = this.Xi;this.bYi = this.Yi;if (!this.hasMoved) {this.X = sX;this.Y = sY;this.setup.tap && this.setup.tap(this.evt);} else {this.setup.up && this.setup.up(this.evt);}this.isDraging = false;this.isDown = false;this.hasMoved = false;this.setup.up && this.setup.up(this.evt);if (this.elem.releaseCapture) this.elem.releaseCapture();this.evt = false;}this.pointerCancel = function(e) {if (this.elem.releaseCapture) this.elem.releaseCapture();this.isDraging = false;this.hasMoved = false;this.isDown = false;this.bXi = this.Xi;this.bYi = this.Yi;sX = 0;sY = 0;}if ('ontouchstart' in window) {this.elem.ontouchstart = function (e) { self.pointerDown(e); return false; }this.elem.ontouchmove = function (e) { self.pointerMove(e); return false; }this.elem.ontouchend = function (e) { self.pointerUp(e); return false; }this.elem.ontouchcancel = function (e) { self.pointerCancel(e); return false;}}document.addEventListener("mousedown", function (e) {if (e.target === self.elem || (e.target.parentNode && e.target.parentNode === self.elem) || (e.target.parentNode.parentNode && e.target.parentNode.parentNode === self.elem)) {if (typeof e.stopPropagation != "undefined") {e.stopPropagation();} else {e.cancelBubble = true;}e.preventDefault();self.pointerDown(e); }}, false);document.addEventListener("mousemove", function (e) { self.pointerMove(e); }, false);document.addEventListener("mouseup", function (e) {self.pointerUp(e);}, false);document.addEventListener('gesturechange', function(e) {e.preventDefault();if (e.scale > 1) self.scale = 0.1; else if (e.scale < 1) self.scale = -0.1; else self.scale = 0;self.setup.scale && self.setup.scale(e);return false;}, false);if (window.navigator.msPointerEnabled) {var nContact = 0;var myGesture = new MSGesture();myGesture.target = this.elem;this.elem.addEventListener("MSPointerDown", function(e) {if (e.pointerType == e.MSPOINTER_TYPE_TOUCH) {myGesture.addPointer(e.pointerId);nContact++;}}, false);this.elem.addEventListener("MSPointerOut", function(e) {if (e.pointerType == e.MSPOINTER_TYPE_TOUCH) {nContact--;}}, false);this.elem.addEventListener("MSGestureHold", function(e) {e.preventDefault();}, false);this.elem.addEventListener("MSGestureChange", function(e) {if (nContact > 1) {if (e.preventDefault) e.preventDefault(); self.scale = e.velocityExpansion;self.setup.scale && self.setup.scale(e);}return false;}, false);}if (window.addEventListener) this.elem.addEventListener('DOMMouseScroll', function(e) { if (e.preventDefault) e.preventDefault(); self.wheelDelta = e.detail * 10;self.setup.wheel && self.setup.wheel(e);return false; }, false); this.elem.onmousewheel = function () { self.wheelDelta = -event.wheelDelta * .25;self.setup.wheel && self.setup.wheel(event);return false; }}// ===== request animation frame =====window.requestAnimFrame = (function(){return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame || function( run ){window.setTimeout(run, 16);};})();

// ===== ge1doot global ===== js文件1var ge1doot = ge1doot || {json: null,screen: null,pointer: null,camera: null,loadJS: function (url, callback, data) {if (typeof url == "string") url = [url];var load = function (src) {var script = document.createElement("script");if (callback) {if (script.readyState){script.onreadystatechange = function () {if (script.readyState == "loaded" || script.readyState == "complete"){script.onreadystatechange = null;if (--n === 0) callback(data || false);}}} else {script.onload = function() {if (--n === 0) callback(data || false);}}}script.src = src;document.getElementsByTagName("head")[0].appendChild(script);}for (var i = 0, n = url.length; i < n; i++) load(url[i]);}}// ===== html/canvas container =====ge1doot.Screen = function (setup) {ge1doot.screen = this;this.elem = document.getElementById(setup.container) || setup.container;this.ctx = this.elem.tagName == "CANVAS" ? this.elem.getContext("2d") : false;this.style = this.elem.style;this.left = 0;this.top = 0;this.width = 0;this.height = 0;this.cursor = "default";this.setup = setup;this.resize = function () {var o = this.elem;this.width = o.offsetWidth;this.height = o.offsetHeight;for (this.left = 0, this.top = 0; o != null; o = o.offsetParent) {this.left += o.offsetLeft;this.top += o.offsetTop;}if (this.ctx) {this.elem.width = this.width;this.elem.height = this.height;}this.setup.resize && this.setup.resize();}this.setCursor = function (type) {if (type !== this.cursor && 'ontouchstart' in window === false) {this.cursor = type;this.style.cursor = type;}}window.addEventListener('resize', function () {ge1doot.screen.resize();}, false);!this.setup.resize && this.resize();}// ==== unified touch events handler ====ge1doot.Pointer = function (setup) {ge1doot.pointer = this;var self = this;var body = document.body;var html = document.documentElement;this.setup = setup;this.screen = ge1doot.screen;this.elem = this.screen.elem;this.X = 0;this.Y = 0;this.Xi = 0;this.Yi = 0;this.bXi = 0;this.bYi = 0;this.Xr = 0;this.Yr = 0;this.startX = 0;this.startY = 0;this.scale = 0;this.wheelDelta = 0;this.isDraging = false;this.hasMoved = false;this.isDown = false;this.evt = false;var sX = 0;var sY = 0;// prevent default behaviorif (setup.tap) this.elem.onclick = function () { return false; }if (!setup.documentMove) {document.ontouchmove = function(e) { e.preventDefault(); }}document.addEventListener("MSHoldVisual", function(e) { e.preventDefault(); }, false);if (typeof this.elem.style.msTouchAction != 'undefined') this.elem.style.msTouchAction = "none";this.pointerDown = function (e) {if (!this.isDown) {if (this.elem.setCapture) this.elem.setCapture();this.isDraging = false;this.hasMoved = false;this.isDown = true;this.evt = e;this.Xr = (e.clientX !== undefined ? e.clientX : e.touches[0].clientX);this.Yr = (e.clientY !== undefined ? e.clientY : e.touches[0].clientY);this.X = sX = this.Xr - this.screen.left;this.Y = sY = this.Yr - this.screen.top + ((html && html.scrollTop) || body.scrollTop);this.setup.down && this.setup.down(e);}}this.pointerMove = function(e) {this.Xr = (e.clientX !== undefined ? e.clientX : e.touches[0].clientX);this.Yr = (e.clientY !== undefined ? e.clientY : e.touches[0].clientY);this.X = this.Xr - this.screen.left;this.Y = this.Yr - this.screen.top + ((html && html.scrollTop) || body.scrollTop);if (this.isDown) {this.Xi = this.bXi + (this.X - sX);this.Yi = this.bYi - (this.Y - sY);}if (Math.abs(this.X - sX) > 11 || Math.abs(this.Y - sY) > 11) {this.hasMoved = true;if (this.isDown) {if (!this.isDraging) {this.startX = sX;this.startY = sY;this.setup.startDrag && this.setup.startDrag(e);this.isDraging = true;} else {this.setup.drag && this.setup.drag(e);}} else {sX = this.X;sY = this.Y;}}this.setup.move && this.setup.move(e);}this.pointerUp = function(e) {this.bXi = this.Xi;this.bYi = this.Yi;if (!this.hasMoved) {this.X = sX;this.Y = sY;this.setup.tap && this.setup.tap(this.evt);} else {this.setup.up && this.setup.up(this.evt);}this.isDraging = false;this.isDown = false;this.hasMoved = false;this.setup.up && this.setup.up(this.evt);if (this.elem.releaseCapture) this.elem.releaseCapture();this.evt = false;}this.pointerCancel = function(e) {if (this.elem.releaseCapture) this.elem.releaseCapture();this.isDraging = false;this.hasMoved = false;this.isDown = false;this.bXi = this.Xi;this.bYi = this.Yi;sX = 0;sY = 0;}if ('ontouchstart' in window) {this.elem.ontouchstart = function (e) { self.pointerDown(e); return false; }this.elem.ontouchmove = function (e) { self.pointerMove(e); return false; }this.elem.ontouchend = function (e) { self.pointerUp(e); return false; }this.elem.ontouchcancel = function (e) { self.pointerCancel(e); return false;}}document.addEventListener("mousedown", function (e) {if (e.target === self.elem || (e.target.parentNode && e.target.parentNode === self.elem) || (e.target.parentNode.parentNode && e.target.parentNode.parentNode === self.elem)) {if (typeof e.stopPropagation != "undefined") {e.stopPropagation();} else {e.cancelBubble = true;}e.preventDefault();self.pointerDown(e); }}, false);document.addEventListener("mousemove", function (e) { self.pointerMove(e); }, false);document.addEventListener("mouseup", function (e) {self.pointerUp(e);}, false);document.addEventListener('gesturechange', function(e) {e.preventDefault();if (e.scale > 1) self.scale = 0.1; else if (e.scale < 1) self.scale = -0.1; else self.scale = 0;self.setup.scale && self.setup.scale(e);return false;}, false);if (window.navigator.msPointerEnabled) {var nContact = 0;var myGesture = new MSGesture();myGesture.target = this.elem;this.elem.addEventListener("MSPointerDown", function(e) {if (e.pointerType == e.MSPOINTER_TYPE_TOUCH) {myGesture.addPointer(e.pointerId);nContact++;}}, false);this.elem.addEventListener("MSPointerOut", function(e) {if (e.pointerType == e.MSPOINTER_TYPE_TOUCH) {nContact--;}}, false);this.elem.addEventListener("MSGestureHold", function(e) {e.preventDefault();}, false);this.elem.addEventListener("MSGestureChange", function(e) {if (nContact > 1) {if (e.preventDefault) e.preventDefault(); self.scale = e.velocityExpansion;self.setup.scale && self.setup.scale(e);}return false;}, false);}if (window.addEventListener) this.elem.addEventListener('DOMMouseScroll', function(e) { if (e.preventDefault) e.preventDefault(); self.wheelDelta = e.detail * 10;self.setup.wheel && self.setup.wheel(e);return false; }, false); this.elem.onmousewheel = function () { self.wheelDelta = -event.wheelDelta * .25;self.setup.wheel && self.setup.wheel(event);return false; }}// ===== request animation frame =====window.requestAnimFrame = (function(){return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame || function( run ){window.setTimeout(run, 16);};})();

到此这篇关于HTML+CSS+JavaScript实现图片3D展览的示例代码的文章就介绍到这了,更多相关HTML图片3D展览内容请搜索真格学网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持真格学网!

CSS3除了为开发者提供二2113维变形之外,还将动5261画从二维平面推动到了三维立体状态4102,能够实现真正的三维特效。1653三维变形和二维变形一样,均使用的是transform属性。想要触发三维变形有两种方式:一种方式是通过语法告知浏览器“请采用三维方式进行变形处理”,另一种方式是直接使用CSS3三维变形的语法。触发方法1:告知浏览器变形方式-webkit-transform-style:preserve-3d;Tips:IE不支持三维变形,在移动端,绝大多数的浏览器均为WebKit内核,因此,在此句代码之前需要书写-webkit-的前缀内核。Tips:不要为body元素设置-webkit- transform-style: preserve 3d,否则会对position:fixed定位的元素造成布局影响。在开发当中,如果当前元素属于body的子级元素,又希望应用三维变形,则在body和当前元素之间多嵌套一层结构,并为这层元素应用三维变形即可。触发方法2:直接使用CSS3变形语法<!DOCTYPE html><head>    <meta charset="UTF-8">    <title>言成科技/title>    <style>        .box1 {            width: 150px;            height: 150px;            border: 2px solid blue;        }        .box1 div {            height: 150px;            background: rgba(0, 0, 0, 0.5);            -webkit-transform: translate3d(30px, 60px, 20px) rotateX(30deg);            transform: translate3d(30px, 60px, 20px) rotateX(30deg);        }    </style></head><body>    <div class="box1">        <div></div>    </div></body></html>具体三维变形的具体属性详见《CSS3-3D相关知识详解—视角以及变形方向》3D效果制作需求制作一个立方体,并进行旋转代码实例<!DOCTYPE HTML><html><head> <meta charset="utf-8" /> <title>言成科技</title> <link rel="stylesheet" type="text/css" href="https://css.h5course.cn/reset-1.0.0.css" /> <style>  .main-bac { -webkit-perspective:1500; } /*设定透视距离*/  .main{   width:200px;    height:200px;    margin: 0 auto;   position:relative;   -webkit-transform-style:preserve-3d;   -webkit-transition:-webkit-transform 2s ease 0s;/*过渡时间*/  }  /*基本样式*/  .main p{   position: absolute;    margin: 0;    padding: 0;    width: 200px;    height: 200px;     text-align: center;    line-height: 200px;    font-size: 26px;    opacity:0.5;  }  /*将第一个元素Z轴向前移动100px,形成第一个面(正面)*/  .main p:nth-of-type(1) {   background-color:red;   -webkit-transform:translateZ(100px);  }  /*将第一个元素Z轴向前移动100px,绕x轴旋转90度形成上面的面*/  .main p:nth-of-type(2) {   background-color:orange;    -webkit-transform:rotateX(90deg) translateZ(100px);  }  /*将第一个元素Z轴向前移动100px,绕x轴旋转-90度形成下边的面*/  .main p:nth-of-type(3) {   background-color:yellow;   -webkit-transform:rotateX(-90deg) translateZ(100px);  }  /*将第一个元素Z轴向前移动100px,绕y轴旋转90度形成右侧的面*/  .main p:nth-of-type(4) {   background-color:green;   -webkit-transform:rotateY(90deg) translateZ(100px);  }  /*将第一个元素Z轴向前移动100px,绕y轴旋转-90度形成左侧的面*/  .main p:nth-of-type(5) {   background-color:#b435bf;   -webkit-transform:rotateY(-90deg) translateZ(100px);  }  /*将第一个元素Z轴向前移动100px,绕y轴旋转180度形成后面(背面)*/  .main p:nth-of-type(6) {   background-color:blue;   -webkit-transform:rotateY(180deg) translateZ(100px);  }  /*鼠标移入时绕Y轴旋转180度,绕Z轴旋转180度*/  .main:hover {-webkit-transform:rotateY(180deg) rotateZ(180deg); }    </style></head><body> <div class="main-bac">  <div class="main">   <p>言成科技</p>   <p>3D立方体</p>   <p>HTML5学堂</p>   <p>3D立方体</p>   <p>码匠</p>   <p>JavaScript</p>  </div>               </div></body></html>代码解析当鼠标移入的时候,立方体逐渐的发生旋转(非突变),围绕X轴旋转45度的同时,围绕Y轴旋转45度。当鼠标移出立方体时,立方体恢复到初始状态。在最开始状态时,并没有采用无限远的视角,设置一定的视角,让刚开始时直视立方体时,不会觉得是一个平面。3D效果制作-目标效果图以上资料来源:《HTML5布局之路》,老子云自动化3D云引擎刚上线了H5单模型编辑器,可对成品模型自由编辑,个性化的材质、背景、热点、音乐等功能设置后,无障碍、一键分享至手机端。案例:内容来自www.zgxue.com请勿采集。


  • 本文相关:
  • 利用css3制作简单的3d半透明立方体图片展示
  • 使用css3实现一个3d相册效果实例
  • css3制作炫酷带方向感应的鼠标滑过图片3d动画
  • css3实现超立体3d图片侧翻倾斜效果
  • HTML5如何在网页中实现3D效果
  • html5或者css3实现图片圆周O运动展示
  • 3、javascript+CSS+Html5实现图片预览(本地和网络...
  • 精通HTML5+CSS3+JavaScript网页设计怎么样
  • html中,如何动态显示几个图片,就是从左到右依次...
  • 怎么用HTML5+css代码让一张图片360度自转?求详细代码
  • html5画多个同心圆,详细代码,最好把css代码和js...
  • 谁有html5+css 3+javascript网页设计案例课堂光盘实例
  • html5 css3怎么用无序列表写一个3d立体正方体,目...
  • HTML5+CSS3网页设计案例教程课后习题
  • 网站首页网页制作脚本下载服务器操作系统网站运营平面设计媒体动画电脑基础硬件教程网络安全主页网页制作html5htmlcssjavascript图片3d展览使用css3实现一个3d相册效果实例css3制作炫酷带方向感应的鼠标滑过图片3d动画css3实现超立体3d图片侧翻倾斜效果html/xhtmlhtml5cssxml/xsltdreamweaver教程frontpage教程心得技巧css 如何让背景图片拉伸填充避免重复显示html5 input placeholder 颜色修改示例基于第一个phonegap(cordova)的应用详解 html5配合css3实现带提示文字的输入框(摆脱js)html5定位获取当前位置并在百度地图上显示将html5 canvas的内容保存为图片借助todataurl实现html5中如何显示视频呢 html5视频播放demo让ie支持html5的方法微信浏览器取消缓存的方法html5的存储方式sessionstorage和localstorage详解html+css+javascript实现图片3d展览的示例代码html5逐步分析实现拖放功能的方法移动端html5 input常见问题(小结)html5超文本标记语言的实现方法html5 webrtc简单实现视频调用的示例代码html5之webcoekt播放jpeg图片流如何在canvas上的图形/图像绑定事件监听的实现canvas 绘图时位置偏离的问题解决关于canvas.todataurl 在ios运行失败的问题解决 canvas绘制图片drawimage使用方法
    免责声明 - 关于我们 - 联系我们 - 广告联系 - 友情链接 - 帮助中心 - 频道导航
    Copyright © 2017 www.zgxue.com All Rights Reserved