CSS如何制作手拿着卡片的效果

发布于 2025-01-09 12:07:19 字数 506 浏览 1 评论 0原文

所以基本上我想要一个手拿着牌的透明图像,然后我想在曲线上显示牌,就像你手里拿着 10 张牌一样(当然不是固定的 10 张)。因此它们应该放置在弯曲的圆顶上。 我正在以角度工作,我知道我必须通过绝对位置和转换来完成此操作:translate-rotate css,只是不知道

我如何使用引导程序,所以这个带有卡片的图像应该在一个列中-12 并兼容较小的屏幕。

我只有从一个将元素定位在圆圈中的人那里获取的代码部分 - Bootstrap 3 将元素对齐到圆形 我尝试使用平移和旋转,但无法使其工作

在此处输入图像描述

So basically i want to have an transparent image of a hand holding cards, then i want to display cards on a curve like when you are holding 10 cards in your hand (not fixed 10 of course). So they should be positioned on a curved dome.
I'm working in angular, and i know that i have to accomplish this via position absolute and transform: translate-rotate css, just don't know how

I'm also working with bootstrap so this image with cards should be in a col-12 and compatible on a smaller screens.

I only have the parts of the code that i took from a guy that positioned elements in a circle - Bootstrap 3 align elements into circle
i tried to play around with translate and rotate but couldn't get it working

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

妥活 2025-01-16 12:07:19

这是我的处理方法。这里发生了很多事情,但它基本上是

  • 设置总体宽度
  • 使用预定义数量的卡片
  • 分布和倾斜卡片
  • ,并使用数学来设置整体角度余量,使用 transform-origin:bottom center; 来 给出效果
let cards = document.querySelector('.cards');
let w = cards.offsetWidth;
let totalarc = 270;
let numcards = 7;
let angles = Array(numcards).fill('').map((a, i) => (totalarc / numcards * (i + 1)) - (totalarc/2 + (totalarc / numcards) / 2));
let margins = angles.map((a, i) => w / numcards * (i + 1));

angles.forEach((a, i) => {
  let s = `transform:rotate(${angles[i]}deg);margin-left:${margins[i]}px;`
  let c = `<div class='card' style='${s}'></div>`;
  cards.innerHTML += c;
})
.container {
  position: relative;
  margin-left: 80px;
  width: 100%;
}

.cards {
  width: 150px;
}

.card {
  width: 120px;
  height: 200px;
  background: #999;
  border: 1px solid #000;
  position: absolute;
  opacity: .5;
  transform-origin: bottom center;
}
<div class='container'>
  <div class='cards'></div>
  <div class='hand'>
    <div>
    </div>

Here's the way I approached it. There's alot going on here, but it's basically

  • setting a overall width to work with
  • using a predefined number of cards and overall angle allowance
  • using math to distribute and angle the cards
  • using transform-origin: bottom center; to give the effect

let cards = document.querySelector('.cards');
let w = cards.offsetWidth;
let totalarc = 270;
let numcards = 7;
let angles = Array(numcards).fill('').map((a, i) => (totalarc / numcards * (i + 1)) - (totalarc/2 + (totalarc / numcards) / 2));
let margins = angles.map((a, i) => w / numcards * (i + 1));

angles.forEach((a, i) => {
  let s = `transform:rotate(${angles[i]}deg);margin-left:${margins[i]}px;`
  let c = `<div class='card' style='${s}'></div>`;
  cards.innerHTML += c;
})
.container {
  position: relative;
  margin-left: 80px;
  width: 100%;
}

.cards {
  width: 150px;
}

.card {
  width: 120px;
  height: 200px;
  background: #999;
  border: 1px solid #000;
  position: absolute;
  opacity: .5;
  transform-origin: bottom center;
}
<div class='container'>
  <div class='cards'></div>
  <div class='hand'>
    <div>
    </div>

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文