使用HTML,CSS和JS创建鼠标3D可旋转papertoy

Mouseferi

我想用HTML元素和CSS创建一个纸质玩具。我希望它可以通过鼠标拖动将其旋转3D

我的玩具是 在此处输入图片说明 在此处输入图片说明

我该如何实现?(头部的左右是梯形,而前面和身体有三角形的切口)

如何创建3D立方体(我想要类似“ https://www.foldable.me/foldables/new ”的东西)?鼠标拖动即可旋转

闪耀

alright first of all you need to learn how to make a simple cube with html and css => Fiddle http://jsfiddle.net/sijav/4W5bX/10/
this fiddle was somewhat rotational logo cube with 5 logos, you see there are 6 li that is 6 square of a cube, in order we want to make front bottom top left right back, we can move them to their rightful position by a great css rules ... transform, in transform we want to transform the squares at the correct location so we must use two property first one is rotatex and rotatey and second is translatez, we can use rotatex to rotate a square to be like floor or roof (bottom or top) and rotatey to make them be the walls (left, right and back). for front we should just translate it to come forth so transform: translatez(5em); would be enough. for back we need to rotatey it 180 degree and translate it to go back ... why not just translate it with negative value? that would make the li on right position but sadly it will also show it like ambulance logo on the hood like ecnalubma ... inverted like in mirror! so we must rotate it 180 degree transform: rotatey(180deg) translatez(5em); we should do the same for left rotatey(-90deg) and right rotatey(90deg). now for top and bottom we should use rotatex and rotate them 90deg and translate it forth again. a simplify of top fiddle can be seen at http://jsfiddle.net/sijav/4W5bX/12/.
now that you have learnt how to make a simple easy cube lets move it with mouse shall we? first we create a mousedown function so that until mouse is down the cube should move with mouse, $('.container').on('mousedown',createMouseMoveFunction); then we create an event called createMouseMoveFunction to set properties that our cube needs before move,

firstX = e.pageX;
firstY = e.pageY;
firstRY = parseInt($('.cube').css('rotateY'));
firstRX = parseInt($('.cube').css('rotateX'));
CubeMove = true;
$('.container').off('mousedown',createMouseMoveFunction);
$(document).on('mousemove',MouseMove);
$(document).on('mouseup',removeMouseMoveFunction);

you see we first save the mouse states on x or y on the page, then we set the current rotate state o the cube so that it can resume rotate.
and then a set the cube to move, then set off the mouse down event listener and set another listener for mouse move on the document and mouse up for stop the cube from moving with mouse! now the mousemove function ->

if(CubeMove){
    $('.cube').css({
        rotateY: firstRY + (el.pageX - firstX),
        rotateX: firstRX + (firstY - el.pageY)
    });

您会看到cubemove属性为true时,它将基于鼠标位置(el.pageXY)旋转x和y。firstXY是第一个鼠标指针,因为我们希望基于第一个鼠标位置创建立方体,而firstRXY是第一个立方体位置,因此我们进行了更改多维数据集也基于它的第一个位置。
现在是mousedown函数,我们使用.off jquery从文档中删除任何鼠标移动句柄

CubeMove = false;
$(document).off('mousemove',MouseMove);
$(document).off('mouseup',removeMouseMoveFunction);
$('.container').on('mousedown',createMouseMoveFunction);

小提琴 http://fiddle.jshell.net/4W5bX/45/



玩得开心

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

创建可旋转的3D地球

来自分类Dev

如何在使用D3.js和html canvas在3d地球上拖动时为移动设备添加旋转逻辑

来自分类Dev

JS操纵CSS 3D旋转动画

来自分类Dev

使用CSS,如何在鼠标进入时将3D框旋转180度,并在离开时继续旋转360度?

来自分类Dev

CSS3动画功能可实现流畅的3D旋转?

来自分类Dev

如何在wxPython中使用鼠标旋转matplotlib 3D图?

来自分类Dev

如何使用鼠标旋转wxPython中的matplotlib 3D图?

来自分类Dev

如何使用HTML和CSS创建旋转效果?

来自分类Dev

CSS 3D轮播项目旋转

来自分类Dev

CSS 3D Box旋转

来自分类Dev

Java:旋转和3D变形

来自分类Dev

3D 相机移动和旋转

来自分类Dev

使用JavaScript从matrix3d()获取3D CSS旋转值

来自分类Dev

从jsartoolkit和three.js创建3D环境

来自分类Dev

如何仅使用 Html 和 Css 插入 3D 照片

来自分类Dev

使用JavaScript旋转CSS3 3d立方体

来自分类Dev

如何使3D旋转木马自动旋转,无需单击鼠标并在鼠标悬停时停止

来自分类Dev

可以使用CSS创建3D照明效果?

来自分类Dev

CSS3变换使用鼠标位置旋转

来自分类Dev

使用three.js从2D旋转到3D

来自分类Dev

如何使用CSS沿X轴旋转3D立方体?

来自分类Dev

AngularJS:使用动画和视图,如何制作3D立方体旋转效果?

来自分类Dev

使用CSS和Javascript的3D动画

来自分类Dev

仅CSS 3D旋转文本

来自分类Dev

CSS 3D等距简单旋转变换

来自分类Dev

CSS 3D等距简单旋转变换

来自分类Dev

旋转和处理MATLAB 3D对象

来自分类Dev

旋转和处理MATLAB 3D对象

来自分类Dev

三种js 3D旋转