英文:
How to code div/object rotating around another object/div with 3d illusion
问题
我遇到了一个技术和智力上的难题。问题是:我想要文本围绕着图像旋转,并看起来像是在图像的前面或后面移动,而图像保持固定/静止不动。
到目前为止的做法是:
- 旋转的文本被嵌套在一个名为 "loader" 的 div 内。
- 每个字母都有自己的 div,因此可以应用 deg 和旋转。
- 动画集将所有字母都旋转,使它们看起来像是在围绕旋转。我希望整个结构中的最后一个 div 保持不动。
以下是代码:
<!-- 这里是你的 HTML 代码 -->
看起来:
- 我尝试将
<img>
放在一个<div>
中,并通过使用position:fixed
影响其类。 - 也尝试了创建一个逆时针旋转的动画,持续时间相当长,但没有成功。
到目前为止,我只能使 <img>
或 "phone_static" div 以相反的方向旋转,但不能停止。
如果您需要进一步的帮助,请告诉我。
英文:
I've come to a technical and intellectual impasse. The problem is: I want text to encircle an image and appear like its moving infront of behind the image while the image remains fixed/static.
So far the 1) text that is rotating is nested in side a div=loader. 2) Each letter has its own div so the deg and rotation works and 3) the animation set rotates all the letters so it appears they are encircling. I want the last div within the overall structure to not move at all.
Here's the code
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-css -->
body {
background-color: #333;
}
:root {
font-size: calc(16px + (24 - 16)*(100vw - 320px)/ (1280 - 320));
}
.preloader {
display: flex;
}
{
background: #313030;
color: #D3E2C0;
font: 1em Dosis, sans-serif;
height: 100vh;
line-height: 1.5;
perspective: 40em;
}
.preloader {
animation: tiltSpin 10s linear infinite;
flex-direction: column;
justify-content: center;
align-items: center;
margin: auto;
width: 17em;
height: 17em;
}
.preloader,
.preloader__ring {
transform-style: preserve-3d;
}
.preloader__ring {
animation-name: spin;
animation-duration: 70s;
animation-timing-function: inherit;
animation-iteration-count: inherit;
font-size: 2em;
position: relative;
top: 100px;
height: 3rem;
width: 1.5rem;
}
.phone_static {
position: absolute;
top: 50%;
left: 70%;
transform: translate(-50%, -50%);
}
}
.preloader__ring:nth-child(even) {
animation-direction: forward;
}
.second_preloader:nth-child(even) {
animation-direction: forward;
animation-duration: 100s;
}
.preloader__sector {
font-weight: 600;
position: absolute;
top: 0;
left: 0;
text-align: center;
text-transform: uppercase;
transform: translateZ(7rem);
}
.preloader__sector,
.preloader__sector:empty:before {
display: inline-block;
width: 100%;
height: 100%;
}
.preloader__sector:empty:before {
background: linear-gradient(transparent 45%, currentColor 45% 55%, transparent 55%);
content: "";
}
.preloader__sector:nth-child(2) {
transform: rotateY(12deg) translateZ(7rem);
}
.preloader__sector:nth-child(3) {
transform: rotateY(24deg) translateZ(7rem);
}
.preloader__sector:nth-child(4) {
transform: rotateY(36deg) translateZ(7rem);
}
.preloader__sector:nth-child(5) {
transform: rotateY(48deg) translateZ(7rem);
}
.preloader__sector:nth-child(6) {
transform: rotateY(60deg) translateZ(7rem);
}
.preloader__sector:nth-child(7) {
transform: rotateY(72deg) translateZ(7rem);
}
.preloader__sector:nth-child(8) {
transform: rotateY(84deg) translateZ(7rem);
}
.preloader__sector:nth-child(9) {
transform: rotateY(96deg) translateZ(7rem);
}
.preloader__sector:nth-child(10) {
transform: rotateY(108deg) translateZ(7rem);
}
.preloader__sector:nth-child(11) {
transform: rotateY(120deg) translateZ(7rem);
}
.preloader__sector:nth-child(12) {
transform: rotateY(132deg) translateZ(7rem);
}
.preloader__sector:nth-child(13) {
transform: rotateY(144deg) translateZ(7rem);
}
.preloader__sector:nth-child(14) {
transform: rotateY(156deg) translateZ(7rem);
}
.preloader__sector:nth-child(15) {
transform: rotateY(168deg) translateZ(7rem);
}
.preloader__sector:nth-child(16) {
transform: rotateY(180deg) translateZ(7rem);
}
.preloader__sector:nth-child(17) {
transform: rotateY(192deg) translateZ(7rem);
}
.preloader__sector:nth-child(18) {
transform: rotateY(204deg) translateZ(7rem);
}
.preloader__sector:nth-child(19) {
transform: rotateY(216deg) translateZ(7rem);
}
.preloader__sector:nth-child(20) {
transform: rotateY(228deg) translateZ(7rem);
}
.preloader__sector:nth-child(21) {
transform: rotateY(240deg) translateZ(7rem);
}
.preloader__sector:nth-child(22) {
transform: rotateY(252deg) translateZ(7rem);
}
.preloader__sector:nth-child(23) {
transform: rotateY(264deg) translateZ(7rem);
}
.preloader__sector:nth-child(24) {
transform: rotateY(276deg) translateZ(7rem);
}
.preloader__sector:nth-child(25) {
transform: rotateY(288deg) translateZ(7rem);
}
.preloader__sector:nth-child(26) {
transform: rotateY(300deg) translateZ(7rem);
}
.preloader__sector:nth-child(27) {
transform: rotateY(312deg) translateZ(7rem);
}
.preloader__sector:nth-child(28) {
transform: rotateY(324deg) translateZ(7rem);
}
.preloader__sector:nth-child(29) {
transform: rotateY(336deg) translateZ(7rem);
}
.preloader__sector:nth-child(30) {
transform: rotateY(348deg) translateZ(7rem);
}
/* Animations */
@keyframes tiltSpin {
from {
transform: rotateY(0) rotateX(30deg);
}
to {
transform: rotateY(1turn) rotateX(30deg);
}
}
@keyframes spin {
from {
transform: rotateY(0deg);
}
to {
transform: rotateY(360deg);
}
}
@keyframes reversespin {
from {
transform: rotateY(deg);
}
to {
transform: rotateY(-360deg);
}
}
<!-- language: lang-html -->
<div class="preloader">
<div class="preloader__ring">
<div class="preloader__sector"></div>
<div class="preloader__sector">S</div>
<div class="preloader__sector">E</div>
<div class="preloader__sector">A</div>
<div class="preloader__sector">M</div>
<div class="preloader__sector">L</div>
<div class="preloader__sector">E</div>
<div class="preloader__sector">S</div>
<div class="preloader__sector">S</div>
<div class="preloader__sector"></div>
<div class="preloader__sector"></div>
<div class="preloader__sector"></div>
<div class="preloader__sector"></div>
<div class="preloader__sector"></div>
<div class="preloader__sector"></div>
<div class="preloader__sector"></div>
<div class="preloader__sector"></div>
<div class="preloader__sector"></div>
<div class="preloader__sector"></div>
<div class="preloader__sector"></div>
<div class="preloader__sector"></div>
<div class="preloader__sector"></div>
<div class="preloader__sector"></div>
<div class="preloader__sector"></div>
<div class="preloader__sector"></div>
<div class="preloader__sector"></div>
<div class="preloader__sector"></div>
<div class="preloader__sector"></div>
<div class="preloader__sector"></div>
<div class="preloader__sector"></div>
<div class="preloader__sector"></div>
</div>
<div class="preloader__ring">
<div class="preloader__sector">U</div>
<div class="preloader__sector">S</div>
<div class="preloader__sector">E</div>
<div class="preloader__sector">R</div>
<div class="preloader__sector"></div>
<div class="preloader__sector">E</div>
<div class="preloader__sector">X</div>
<div class="preloader__sector">P</div>
<div class="preloader__sector">E</div>
<div class="preloader__sector">R</div>
<div class="preloader__sector">I</div>
<div class="preloader__sector">E</div>
<div class="preloader__sector">N</div>
<div class="preloader__sector">C</div>
<div class="preloader__sector">S</div>
<div class="preloader__sector"></div>
<div class="preloader__sector"></div>
<div class="preloader__sector"></div>
<div class="preloader__sector"></div>
<div class="preloader__sector"></div>
<div class="preloader__sector"></div>
<div class="preloader__sector"></div>
<div class="preloader__sector"></div>
<div class="preloader__sector"></div>
<div class="preloader__sector"></div>
<div class="preloader__sector"></div>
<div class="preloader__sector"></div>
<div class="preloader__sector"></div>
<div class="preloader__sector"></div>
<div class="preloader__sector"></div>
</div>
<div class="phone_static">
<img src="https://github.com/Jitlclarke/ux_portfolio/blob/main/images/small_version_mockup.png?raw=true" alt="" height=560 width=300>
</div>
</div>
<!-- end snippet -->
What it looks like
- i've tried putting the <img> inside a <div> and affecting the class by using position:fixed and 2) also tried simply creating an animation with deg going the opposite direction with a duration that's quite long but, no luck.
So far i can only get the <img> or "phone_static" div to rotate in the opposite direction but not stop.
答案1
得分: 0
以下是您要翻译的内容:
"The phone need to be outside the animated container and you have to add transform-style: preserve-3d;
to the body element as well. Then all you have to do is to adjust the position of the image."
"手机需要放在动画容器外部,并且您还需要在 body 元素中添加 transform-style: preserve-3d;
。然后您只需调整图像的位置即可。"
英文:
The phone need to be outside the animated container and you have to add transform-style: preserve-3d;
to the body element as well. Then all you have to do is to adjust the position of the image.
Here is a non-perfect example that you can easily adjust
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-css -->
body {
background-color: #333;
}
:root {
font-size: calc(16px + (24 - 16)*(100vw - 320px)/ (1280 - 320));
}
.preloader {
display: flex;
}
.preloader {
animation: tiltSpin 10s linear infinite;
flex-direction: column;
justify-content: center;
align-items: center;
margin: auto;
width: 17em;
height: 17em;
}
body,
.preloader,
.preloader__ring {
transform-style: preserve-3d;
}
.preloader__ring {
animation-name: spin;
animation-duration: 70s;
animation-timing-function: inherit;
animation-iteration-count: inherit;
font-size: 2em;
position: relative;
top: 100px;
height: 3rem;
width: 1.5rem;
}
.phone_static {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-39%, -13%);
}
.phone_static img {
width: 250px;
height: auto;
}
}
.preloader__ring:nth-child(even) {
animation-direction: forward;
}
.second_preloader:nth-child(even) {
animation-direction: forward;
animation-duration: 100s;
}
.preloader__sector {
font-weight: 600;
position: absolute;
top: 0;
left: 0;
text-align: center;
text-transform: uppercase;
transform: translateZ(7rem);
}
.preloader__sector,
.preloader__sector:empty:before {
display: inline-block;
width: 100%;
height: 100%;
}
.preloader__sector:empty:before {
background: linear-gradient(transparent 45%, currentColor 45% 55%, transparent 55%);
content: "";
}
.preloader__sector:nth-child(2) {
transform: rotateY(12deg) translateZ(7rem);
}
.preloader__sector:nth-child(3) {
transform: rotateY(24deg) translateZ(7rem);
}
.preloader__sector:nth-child(4) {
transform: rotateY(36deg) translateZ(7rem);
}
.preloader__sector:nth-child(5) {
transform: rotateY(48deg) translateZ(7rem);
}
.preloader__sector:nth-child(6) {
transform: rotateY(60deg) translateZ(7rem);
}
.preloader__sector:nth-child(7) {
transform: rotateY(72deg) translateZ(7rem);
}
.preloader__sector:nth-child(8) {
transform: rotateY(84deg) translateZ(7rem);
}
.preloader__sector:nth-child(9) {
transform: rotateY(96deg) translateZ(7rem);
}
.preloader__sector:nth-child(10) {
transform: rotateY(108deg) translateZ(7rem);
}
.preloader__sector:nth-child(11) {
transform: rotateY(120deg) translateZ(7rem);
}
.preloader__sector:nth-child(12) {
transform: rotateY(132deg) translateZ(7rem);
}
.preloader__sector:nth-child(13) {
transform: rotateY(144deg) translateZ(7rem);
}
.preloader__sector:nth-child(14) {
transform: rotateY(156deg) translateZ(7rem);
}
.preloader__sector:nth-child(15) {
transform: rotateY(168deg) translateZ(7rem);
}
.preloader__sector:nth-child(16) {
transform: rotateY(180deg) translateZ(7rem);
}
.preloader__sector:nth-child(17) {
transform: rotateY(192deg) translateZ(7rem);
}
.preloader__sector:nth-child(18) {
transform: rotateY(204deg) translateZ(7rem);
}
.preloader__sector:nth-child(19) {
transform: rotateY(216deg) translateZ(7rem);
}
.preloader__sector:nth-child(20) {
transform: rotateY(228deg) translateZ(7rem);
}
.preloader__sector:nth-child(21) {
transform: rotateY(240deg) translateZ(7rem);
}
.preloader__sector:nth-child(22) {
transform: rotateY(252deg) translateZ(7rem);
}
.preloader__sector:nth-child(23) {
transform: rotateY(264deg) translateZ(7rem);
}
.preloader__sector:nth-child(24) {
transform: rotateY(276deg) translateZ(7rem);
}
.preloader__sector:nth-child(25) {
transform: rotateY(288deg) translateZ(7rem);
}
.preloader__sector:nth-child(26) {
transform: rotateY(300deg) translateZ(7rem);
}
.preloader__sector:nth-child(27) {
transform: rotateY(312deg) translateZ(7rem);
}
.preloader__sector:nth-child(28) {
transform: rotateY(324deg) translateZ(7rem);
}
.preloader__sector:nth-child(29) {
transform: rotateY(336deg) translateZ(7rem);
}
.preloader__sector:nth-child(30) {
transform: rotateY(348deg) translateZ(7rem);
}
/* Animations */
@keyframes tiltSpin {
from {
transform: rotateY(0) rotateX(30deg);
}
to {
transform: rotateY(1turn) rotateX(30deg);
}
}
@keyframes spin {
from {
transform: rotateY(0deg);
}
to {
transform: rotateY(360deg);
}
}
<!-- language: lang-html -->
<div class="preloader">
<div class="preloader__ring">
<div class="preloader__sector"></div>
<div class="preloader__sector">S</div>
<div class="preloader__sector">E</div>
<div class="preloader__sector">A</div>
<div class="preloader__sector">M</div>
<div class="preloader__sector">L</div>
<div class="preloader__sector">E</div>
<div class="preloader__sector">S</div>
<div class="preloader__sector">S</div>
<div class="preloader__sector"></div>
<div class="preloader__sector"></div>
<div class="preloader__sector"></div>
<div class="preloader__sector"></div>
<div class="preloader__sector"></div>
<div class="preloader__sector"></div>
<div class="preloader__sector"></div>
<div class="preloader__sector"></div>
<div class="preloader__sector"></div>
<div class="preloader__sector"></div>
<div class="preloader__sector"></div>
<div class="preloader__sector"></div>
<div class="preloader__sector"></div>
<div class="preloader__sector"></div>
<div class="preloader__sector"></div>
<div class="preloader__sector"></div>
<div class="preloader__sector"></div>
<div class="preloader__sector"></div>
<div class="preloader__sector"></div>
<div class="preloader__sector"></div>
<div class="preloader__sector"></div>
<div class="preloader__sector"></div>
</div>
<div class="preloader__ring">
<div class="preloader__sector">U</div>
<div class="preloader__sector">S</div>
<div class="preloader__sector">E</div>
<div class="preloader__sector">R</div>
<div class="preloader__sector"></div>
<div class="preloader__sector">E</div>
<div class="preloader__sector">X</div>
<div class="preloader__sector">P</div>
<div class="preloader__sector">E</div>
<div class="preloader__sector">R</div>
<div class="preloader__sector">I</div>
<div class="preloader__sector">E</div>
<div class="preloader__sector">N</div>
<div class="preloader__sector">C</div>
<div class="preloader__sector">S</div>
<div class="preloader__sector"></div>
<div class="preloader__sector"></div>
<div class="preloader__sector"></div>
<div class="preloader__sector"></div>
<div class="preloader__sector"></div>
<div class="preloader__sector"></div>
<div class="preloader__sector"></div>
<div class="preloader__sector"></div>
<div class="preloader__sector"></div>
<div class="preloader__sector"></div>
<div class="preloader__sector"></div>
<div class="preloader__sector"></div>
<div class="preloader__sector"></div>
<div class="preloader__sector"></div>
<div class="preloader__sector"></div>
</div>
</div>
<div class="phone_static">
<img src="https://github.com/Jitlclarke/ux_portfolio/blob/main/images/small_version_mockup.png?raw=true" alt="" height=560 width=300>
</div>
<!-- end snippet -->
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论