Heim Web-Frontend H5-Tutorial Mehrperspektivische 3D-drehbare HTML5-Logo-Animation_html5-Tutorial-Fähigkeiten

Mehrperspektivische 3D-drehbare HTML5-Logo-Animation_html5-Tutorial-Fähigkeiten

May 16, 2016 pm 03:45 PM
3D-Rotation html5 logo

Dies ist ein 3D-Animations-Spezialeffekt, der auf HTML5 und CSS3 basiert. Im Gegensatz zu den vorherigen 3D-Spezialeffekten wird dieser vollständig mithilfe von HTML5-Funktionen implementiert, anstatt mehrere Bilder zu überlagern. Ein weiteres Merkmal dieser 3D-Animation ist, dass sie sich unendlich drehen lässt, sodass das HTML5-Logo aus mehreren Perspektiven betrachtet werden kann.

Online-Demo Quellcode-Download

HTML-Code

XML/HTML-CodeInhalt in die Zwischenablage kopieren
  1. <div class="link-overlay"> 
  2. div>
  3. <canvas id="canvas" style="background-color:#ddd">< /Leinwand>

JavaScript-Code

JavaScript-CodeInhalt in die Zwischenablage kopieren
  1. // an den Fenster-Onload-Handler binden   
  2. window.addEventListener('load', onloadHandler, false);   
  3.   
  4. /** 
  5.  * Window-Onload-Handler  
  6.  */  
  7. Funktion onloadHandler()   
  8. {   
  9.    var canvas = document.getElementById('canvas');   
  10.    canvas.width = window.innerWidth;   
  11.    canvas.height = window.innerHeight;   
  12.    var k3dmain = neu K3D.Controller(canvas, true );   
  13.   
  14.    // 3D-Objekte generieren   
  15.   
  16.    var obj1 = new K3D.K3DObject();   
  17.    mit (obj1)   
  18.    {   
  19.       drawmode = "solid";   
  20.       shademode = "lightsource";   
  21.       sortmode = "unsorted";   
  22.       addphi = -0,5;   
  23.       abouty = -90;   
  24.       perslevel = 1000;   
  25.       init(   
  26.          [{x:-80,y:180,z:0},{x:0,y:180,z:-80},{x:0,y:0,z:-80 },{x:-80,y:20,z:0},{x:-50,y:150,z:-30},{x:0,y:150,z:-80},{x :0,y:130,z:-80},{x:-30,y:130,z:-50},{x:-28,y:110,z:-52},{x:0, y:110,z:-80},{x:0,y:90,z:-80},{x:-45,y:90,z:-35},{x:-44,y:80 ,z:-36},{x:-25,y:80,z:-55},{x:-22,y:66,z:-58},{x:0,y:60,z: -80},{x:0,y:40,z:-80},{x:-40,y:50,z:-40}],   
  27.          [],   
  28.          [{color:[227,76,38],vertices:[0,1,2,3,0]},{color:[235,235,235],vertices:[4,5,6,7 ,8,9,10,11,4]},{color:[235,235,235],vertices:[12,13,14,15,16,17,12]}]   
  29.       );   
  30.    }  
  31.    k3dmain.addK3DObject(obj1);   
  32.   
  33.    var obj2 = new K3D.K3DObject();   
  34.    mit (obj2)   
  35.    {   
  36.       drawmode = "solid";   
  37.       shademode = "lightsource";   
  38.       sortmode = "unsorted";   
  39.       addphi = -0,5;   
  40.       abouty = -90;   
  41.       perslevel = 1000;   
  42.       init(   
  43.          [{x:0,y:180,z:-80},{x:80,y:180,z:0},{x:80,y:20,z:0}, {x:0,y:0,z:-80},{x:0,y:165,z:-80},{x:68,y:165,z:-12},{x:55, y:35,z:-25},{x:0,y:20,z:-80},{x:0,y:150,z:-80},{x:50,y:150,z :-30},{x:47,y:130,z:-33},{x:0,y:130,z:-80},{x:0,y:110,z:-80}, {x:45,y:110,z:-35},{x:40,y:50,z:-40},{x:0,y:40,z:-80},{x:0, y:60,z:-80},{x:20,y:66,z:-60},{x:23,y:90,z:-57},{x:0,y:90,z :-80}],   
  44.          [],   
  45.          [{color:[227,76,38],vertices:[0,1,2,3,0]},{color:[240,101,41],vertices:[4,5,6 ,7,4]},{color:[235,235,235],vertices:[8,9,10,11,8]},{color:[235,235,235],vertices:[12,13,14,15,16,17 ,18,19,12]}]   
  46.       );   
  47.    }   
  48.    k3dmain.addK3DObject(obj2);   
  49.   
  50.    var obj3 = new K3D.K3DObject();   
  51.    mit (obj3)   
  52.    {   
  53.       drawmode = "solid";   
  54.       shademode = "lightsource";   
  55.       sortmode = "unsorted";   
  56.       addphi = -0,5;   
  57.       abouty = -90;   
  58.       perslevel = 1000;   
  59.       init(   
  60.          [{x:80,y:180,z:0},{x:0,y:180,z:80},{x:0,y:0,z:80},{ x:80,y:20,z:0},{x:50,y:150,z:30},{x:0,y:150,z:80},{x:0,y:130, z:80},{x:30,y:130,z:50},{x:28,y:110,z:52},{x:0,y:110,z:80},{x: 0,y:90,z:80},{x:45,y:90,z:35},{x:44,y:80,z:36},{x:25,y:80,z: 55},{x:22,y:66,z:58},{x:0,y:60,z:80},{x:0,y:40,z:80},{x:40, y:50,z:40}],   
  61.          [],   
  62.          [{color:[227,76,38],vertices:[0,1,2,3,0]},{color:[235,235,235],vertices:[4,5,6,7 ,8,9,10,11,4]},{color:[235,235,235],vertices:[12,13,14,15,16,17,12]}]   
  63.       );   
  64.    }  
  65.    k3dmain.addK3DObject(obj3);   
  66.   
  67.    var obj4 = new K3D.K3DObject();   
  68.    mit (obj4)   
  69.    {   
  70.       drawmode = "solid";   
  71.       shademode = "lightsource";   
  72.       sortmode = "unsorted";   
  73.       addphi = -0,5;   
  74.       abouty = -90;   
  75.       perslevel = 1000;   
  76.       init(   
  77.          [{x:0,y:180,z:80},{x:-80,y:180,z:0},{x:-80,y:20,z:0} ,{x:0,y:0,z:80},{x:0,y:165,z:80},{x:-68,y:165,z:12},{x:-55, y:35,z:25},{x:0,y:20,z:80},{x:0,y:150,z:80},{x:-50,y:150,z:30 },{x:-47,y:130,z:33},{x:0,y:130,z:80},{x:0,y:110,z:80},{x:-45 ,y:110,z:35},{x:-40,y:50,z:40},{x:0,y:40,z:80},{x:0,y:60,z: 80},{x:-20,y:66,z:60},{x:-23,y:90,z:57},{x:0,y:90,z:80}],   
  78.          [],   
  79.          [{color:[227,76,38],vertices:[0,1,2,3,0]},{color:[240,101,41],vertices:[4,5,6 ,7,4]},{color:[235,235,235],vertices:[8,9,10,11,8]},{color:[235,235,235],vertices:[12,13,14,15,16,17 ,18,19,12]}]   
  80.       );   
  81.    }   
  82.    k3dmain.addK3DObject(obj4);   
  83.   
  84.    var objBase = new K3D.K3DObject();   
  85.    mit (objBase)   
  86.    {   
  87.       drawmode = "solid";   
  88.       shademode = "lightsource";   
  89.       sortmode = "unsorted";   
  90.       addphi = -0,5;   
  91.       abouty = -90;   
  92.       perslevel = 1000;   
  93.       init(   
  94.          [{x:0,y:0,z:-80},{x:-80,y:20,z:0},{x:0,y:0,z:80} ,{x:80,y:20,z:0}],   
  95.          [],   
  96.          [{color:[227,76,38],vertices:[0,2,1,0]},{color:[227,76,38],vertices:[0,3,2 ,0]}]   
  97.       );   
  98.    }  
  99.    k3dmain.addK3DObject(objBase);   
  100.   
  101.    var objHtml = new K3D.K3DObject();   
  102.    mit (objHtml)   
  103.    {   
  104.       drawmode = "solid";   
  105.       shademode = "lightsource";   
  106.       //sortmode = "unsorted";   
  107.       color = [64,64,64];   
  108.       doublesided = true;   
  109.       addphi = -0,5;   
  110.       abouty = 100;   
  111.       Skala = 0,75;   
  112.       perslevel = 1000;   
  113.       init(   
  114.          [{x:-80,y:40,z:0},{x:-70,y:40,z:0},{x:-70,y:30,z:0 },{x:-60,y:30,z:0},{x:-60,y:40,z:0},{x:-50,y:40,z:0},{x: -50,y:10,z:0},{x:-60,y:10,z:0},{x:-60,y:20,z:0},{x:-70,y: 20,z:0},{x:-70,y:10,z:0},{x:-80,y:10,z:0},{x:-40,y:40,z:0 },{x:-10,y:40,z:0},{x:-10,y:30,z:0},{x:-20,y:30,z:0},{x: -20,y:10,z:0},{x:-30,y:10,z:0},{x:-30,y:30,z:0},{x:-40,y: 30,z:0},{x:0,y:40,z:0},{x:10,y:40,z:0},{x:20,y:30,z:0},{ x:30,y:40,z:0},{x:40,y:40,z:0},{x:40,y:10,z:0},{x:30,y:10, z:0},{x:30,y:30,z:0},{x:20,y:20,z:0},{x:10,y:30,z:0},{x: 10,y:10,z:0},{x:0,y:10,z:0},{x:50,y:40,z:0},{x:60,y:40,z: 0},{x:60,y:20,z:0},{x:80,y:20,z:0},{x:80,y:10,z:0},{x:50, y:10,z:0}],   
  115.          [],   
  116.          [{vertices:[0,1,2,3,4,5,6,7,8,9,10,11,0]},{vertices:[12,13,14,15 ,16,17,18,19,12]},{Vertices:[20,21,22,23,24,25,26,27,28,29,30,31,20]},{Vertices:[32 ,33,34,35,36,37,32]}]   
  117.       );   
  118.    }  
  119.    k3dmain.addK3DObject(objHtml);   
  120.   
  121.    // Rückruf für Renderschleife hinzufügen   
  122.    var ctx = canvas.getContext('2d');   
  123.    var rotationOffset = 0;   
  124.    var len = (canvas.height > canvas.width ? canvas.height : canvas.width) * 0.7;   
  125.    k3dmain.clearBackground = false;   
  126.    k3dmain.callback = function()   
  127.    {   
  128.       // bg manuell löschen – da wir einige zusätzliche Goodies gerendern möchten   
  129.       ctx.clearRect(0, 0, canvas.width, canvas.height);   
  130.   
  131.       // BG-Effekt zeichnen, bevor K3D sein 3D-Rendering durchführt   
  132.       ctx.save();   
  133.       ctx.translate(canvas.width/2, canvas.height/2);   
  134.       ctx.rotate(rotationOffset);   
  135.   
  136.       // erster Fülldurchgang - äußere Strahlen   
  137.       var RAYCOUNT = 24;   
  138.       ctx.fillStyle = "#eee";   
  139.       ctx.beginPath();   
  140.       for (var i=0; i
  141.       {   
  142.          // Kontext drehen   
  143.          ctx.rotate(TWOPI / RAYCOUNT);   
  144.          ctx.moveTo(0, 0);   
  145.          ctx.lineTo(-20, len);   
  146.          ctx.lineTo(20, len);   
  147.       }  
  148.       ctx.closePath();   
  149.       ctx.fill();   
  150.       // zweiter Fülldurchgang – innere Strahlen   
  151.       ctx.fillStyle = "#fff";   
  152.       ctx.beginPath();   
  153.       for (var i=0; i
  154.       {   
  155.          // Kontext drehen   
  156.          ctx.rotate(TWOPI / RAYCOUNT);   
  157.          ctx.moveTo(0, 0);   
  158.          ctx.lineTo(-15, len);   
  159.          ctx.lineTo(15, len);   
  160.       }   
  161.       ctx.closePath();   
  162.       ctx.fill();   
  163.       ctx.restore();   
  164.       rotationOffset  = 0,005;   
  165.   
  166.       // Benutzerinteraktion auf Rotation anwenden   
  167.       for (var i=0, objs=k3dmain.objects; i
  168.       {   
  169.          objs[i].ophi  = targetRotationX;   
  170.       }   
  171.   
  172.       if (targetRotationX > -0.5) targetRotationX -= 0.05;   
  173.       else if (targetRotationX < -0.55) targetRotationX  = 0.05;   
  174.       if (targetRotationX > -0.55 && targetRotationX < -0.5) targetRotationX = -0.5;   
  175.    };   
  176.   
  177.    // Demoschleife starten   
  178.    k3dmain.paused = true;   
  179.    setInterval(function(){k3dmain.tick()}, 1000/60);   
  180. }  
  181.   
  182. // raffinierter Drag/Touch-Ereigniserfassungscode, geliehen von Mr.Doob http://mrdoob.com/   
  183. var targetRotationX = 0;   
  184. var targetRotationOnMouseDownX = 0;   
  185. var mouseX = 0;   
  186. var mouseXOnMouseDown = 0;   
  187. var targetRotationY = 0;   
  188. var targetRotationOnMouseDownY = 0;   
  189. var mouseY = 0;   
  190. var mouseYOnMouseDown = 0;   
  191.   
  192. var windowHalfX = window.innerWidth / 2;   
  193. var windowHalfY = window.innerHeight / 2;   
  194.   
  195. document.addEventListener('mousedown', onDocumentMouseDown, false);   
  196. document.addEventListener('touchstart', onDocumentTouchStart, false);   
  197. document.addEventListener('touchmove', onDocumentTouchMove, false);   
  198.   
  199. Funktion onDocumentMouseDown( event ) {   
  200.   
  201.  event.preventDefault();   
  202.   
  203.  document.addEventListener('mousemove', onDocumentMouseMove, false);   
  204.  document.addEventListener('mouseup', onDocumentMouseUp, false);   
  205.  document.addEventListener('mouseout', onDocumentMouseOut, false);   
  206.   
  207.  mouseXOnMouseDown = event.clientX - windowHalfX;   
  208.  targetRotationOnMouseDownX = targetRotationX;   
  209.  mouseYOnMouseDown = event.clientY - windowHalfY;   
  210.  targetRotationOnMouseDownY = targetRotationY;   
  211. }   
  212.   
  213. Funktion onDocumentMouseMove( event )   
  214. {   
  215.  mouseX = event.clientX - windowHalfX;   
  216.  targetRotationX = targetRotationOnMouseDownX   (mouseX - mouseXOnMouseDown) * 0,02;   
  217.  mouseY = event.clientY - windowHalfY;   
  218.  targetRotationY = targetRotationOnMouseDownY   (mouseY - mouseYOnMouseDown) * 0,02;   
  219. }  
  220.   
  221. fonction onDocumentMouseUp( event )   
  222. {   
  223.  document.removeEventListener('mousemove', onDocumentMouseMove, false);   
  224.  document.removeEventListener('mouseup', onDocumentMouseUp, false);   
  225.  document.removeEventListener('mouseout', onDocumentMouseOut, false);   
  226. }   
  227.   
  228. fonction onDocumentMouseOut( event )   
  229. {   
  230.  document.removeEventListener('mousemove', onDocumentMouseMove, false);   
  231.  document.removeEventListener('mouseup', onDocumentMouseUp, false);   
  232.  document.removeEventListener('mouseout', onDocumentMouseOut, false);   
  233. }   
  234.   
  235. fonction onDocumentTouchStart( event )   
  236. {   
  237.  if (event.touches.length == 1)   
  238.  {   
  239.   event.preventDefault();   
  240.   
  241.   mouseXOnMouseDown = event.touches[0].pageX - windowHalfX ;   
  242.   targetRotationOnMouseDownX = targetRotationX;   
  243.   mouseYOnMouseDown = event.touches[0].pageY - windowHalfY;   
  244.   targetRotationOnMouseDownY = targetRotationY;   
  245.  }   
  246. }   
  247.   
  248. fonction onDocumentTouchMove( event )   
  249. {   
  250.  if (event.touches.length == 1)   
  251.  {   
  252.   event.preventDefault();   
  253.   
  254.   mouseX = event.touches[0].pageX - windowHalfX ;   
  255.   targetRotationX = targetRotationOnMouseDownX   (mouseX - mouseXOnMouseDown) * 0,05 ;   
  256.   mouseY = event.touches[0].pageY - windowHalfY;   
  257.   targetRotationY = targetRotationOnMouseDownY   (mouseX - mouseYOnMouseDown) * 0,05 ;   
  258.  }   
  259. }   

以上就是本文的全部内容,希望对大家的学习有所帮助。

Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn

Heiße KI -Werkzeuge

Undresser.AI Undress

Undresser.AI Undress

KI-gestützte App zum Erstellen realistischer Aktfotos

AI Clothes Remover

AI Clothes Remover

Online-KI-Tool zum Entfernen von Kleidung aus Fotos.

Undress AI Tool

Undress AI Tool

Ausziehbilder kostenlos

Clothoff.io

Clothoff.io

KI-Kleiderentferner

AI Hentai Generator

AI Hentai Generator

Erstellen Sie kostenlos Ai Hentai.

Heißer Artikel

R.E.P.O. Energiekristalle erklärten und was sie tun (gelber Kristall)
3 Wochen vor By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Beste grafische Einstellungen
3 Wochen vor By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. So reparieren Sie Audio, wenn Sie niemanden hören können
3 Wochen vor By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: Wie man alles in Myrise freischaltet
4 Wochen vor By 尊渡假赌尊渡假赌尊渡假赌

Heiße Werkzeuge

Notepad++7.3.1

Notepad++7.3.1

Einfach zu bedienender und kostenloser Code-Editor

SublimeText3 chinesische Version

SublimeText3 chinesische Version

Chinesische Version, sehr einfach zu bedienen

Senden Sie Studio 13.0.1

Senden Sie Studio 13.0.1

Leistungsstarke integrierte PHP-Entwicklungsumgebung

Dreamweaver CS6

Dreamweaver CS6

Visuelle Webentwicklungstools

SublimeText3 Mac-Version

SublimeText3 Mac-Version

Codebearbeitungssoftware auf Gottesniveau (SublimeText3)

Tabellenrahmen in HTML Tabellenrahmen in HTML Sep 04, 2024 pm 04:49 PM

Anleitung zum Tabellenrahmen in HTML. Hier besprechen wir verschiedene Möglichkeiten zum Definieren von Tabellenrändern anhand von Beispielen für den Tabellenrand in HTML.

HTML-Rand links HTML-Rand links Sep 04, 2024 pm 04:48 PM

Anleitung zum HTML-Rand links. Hier besprechen wir einen kurzen Überblick über HTML margin-left und seine Beispiele sowie seine Code-Implementierung.

Verschachtelte Tabelle in HTML Verschachtelte Tabelle in HTML Sep 04, 2024 pm 04:49 PM

Dies ist eine Anleitung für verschachtelte Tabellen in HTML. Hier diskutieren wir anhand der entsprechenden Beispiele, wie man eine Tabelle innerhalb der Tabelle erstellt.

HTML-Tabellenlayout HTML-Tabellenlayout Sep 04, 2024 pm 04:54 PM

Leitfaden zum HTML-Tabellenlayout. Hier besprechen wir die Werte des HTML-Tabellenlayouts zusammen mit den Beispielen und Ausgaben im Detail.

HTML-Eingabeplatzhalter HTML-Eingabeplatzhalter Sep 04, 2024 pm 04:54 PM

Leitfaden für HTML-Eingabeplatzhalter. Hier besprechen wir die Beispiele für HTML-Eingabeplatzhalter zusammen mit den Codes und Ausgaben.

HTML-geordnete Liste HTML-geordnete Liste Sep 04, 2024 pm 04:43 PM

Leitfaden zur HTML-geordneten Liste. Hier besprechen wir auch die Einführung von HTML-geordneten Listen und Typen sowie deren Beispiele

Text in HTML verschieben Text in HTML verschieben Sep 04, 2024 pm 04:45 PM

Anleitung zum Verschieben von Text in HTML. Hier besprechen wir eine Einführung, wie Marquee-Tags funktionieren, mit Syntax und Beispielen für die Implementierung.

HTML-Onclick-Button HTML-Onclick-Button Sep 04, 2024 pm 04:49 PM

Anleitung zum HTML-OnClick-Button. Hier diskutieren wir deren Einführung, Funktionsweise, Beispiele und Onclick-Events in verschiedenen Veranstaltungen.

See all articles