Pular para o conteúdo
#150LEVESEM DEPS

Drag Cards

Cards podem ser arrastados.

Categoria:
Cards
Subcategoria:
Cards
Complexidade:
Intermediário
Performance:
Muito leve
Compatibilidade:
React · Next.js · HTML · Tailwind

Preview

Preview executado em iframe sandbox isolado. Efeitos de scroll: role dentro do preview. Em touch, interações de mouse viram animação automática.

Prompt

Transforme o efeito personalizado em uma instrução técnica clara para sua IA.

Stack

Código

import { useEffect, useRef } from "react";

// Drag Cards — gerado pelo Effect Prompt Lab
// Isolado em Shadow DOM para não vazar CSS. Cleanup automático no unmount.
const SETTINGS = {
  "primary": "#8b5cf6",
  "secondary": "#22d3ee",
  "background": "#0b0b12",
  "text": "#f5f5f7",
  "speed": 1,
  "duration": 2,
  "delay": 0,
  "intensity": 60,
  "opacity": 100,
  "blur": 12,
  "glow": 24,
  "scale": 1,
  "rotation": 0,
  "depth": 120,
  "perspective": 900,
  "count": 40,
  "direction": "right",
  "loop": true,
  "autoplay": true,
  "mouse": true,
  "scroll": true,
  "mobile": true,
  "reducedMotion": true,
  "start": 0,
  "end": 100,
  "prefix": "",
  "suffix": "",
  "separator": ".",
  "images": [
    "aurora",
    "city",
    "ocean",
    "forest",
    "desert"
  ],
  "headline": "Sua próxima página começa aqui",
  "transition": "fade",
  "zoom": 1.2,
  "parallax": 40,
  "scrub": 1
};

const CSS = ":host{--fx-primary:#8b5cf6;--fx-secondary:#22d3ee;--fx-bg:#0b0b12;--fx-text:#f5f5f7;--fx-speed:1;--fx-dur:2.00s;--fx-delay:0s;--fx-intensity:0.6;--fx-opacity:1;--fx-blur:12px;--fx-glow:24px;--fx-scale:1;--fx-rot:0deg;--fx-depth:120px;--fx-persp:900px;--fx-dir-x:1;--fx-dir-y:0;--fx-iter:infinite;--fx-play:running}\n.cd{position:relative;width:min(86vw,340px);padding:28px;border-radius:22px;background:linear-gradient(160deg,#1b1b26,#111118);border:1px solid rgba(255,255,255,.09);color:var(--fx-text)}.cd h3{font:700 22px system-ui;margin:14px 0 8px}.cd p{opacity:.65;line-height:1.5;font-size:15px}.cd .ic{width:48px;height:48px;border-radius:14px;display:grid;place-items:center;background:linear-gradient(135deg,var(--fx-primary),var(--fx-secondary));font-size:22px}.cd .img{height:170px;border-radius:14px;overflow:hidden;margin:-8px -8px 0}.cd .img img{width:100%;height:100%;object-fit:cover}.dg{display:block}.dr{position:absolute;width:300px;cursor:grab;touch-action:none;transform:rotate(var(--r));transition:box-shadow .2s,scale .2s;user-select:none;box-shadow:0 20px 40px rgba(0,0,0,.4)}.dr.on{cursor:grabbing;scale:1.05;box-shadow:0 40px 80px rgba(0,0,0,.6)}";
const HTML = "<div class=\"stage dg\"><article class=\"cd dr\" style=\"--r:-8deg;left:calc(50% - 150px + -100px);top:calc(50% - 130px + 0px)\" tabindex=\"0\"><div class=\"img\"><img data-i=\"0\" alt=\"\" draggable=\"false\"></div><h3>Arraste-me 1</h3></article><article class=\"cd dr\" style=\"--r:5deg;left:calc(50% - 150px + -50px);top:calc(50% - 130px + 30px)\" tabindex=\"0\"><div class=\"img\"><img data-i=\"1\" alt=\"\" draggable=\"false\"></div><h3>Arraste-me 2</h3></article><article class=\"cd dr\" style=\"--r:-3deg;left:calc(50% - 150px + 0px);top:calc(50% - 130px + 0px)\" tabindex=\"0\"><div class=\"img\"><img data-i=\"2\" alt=\"\" draggable=\"false\"></div><h3>Arraste-me 3</h3></article><article class=\"cd dr\" style=\"--r:9deg;left:calc(50% - 150px + 50px);top:calc(50% - 130px + 30px)\" tabindex=\"0\"><div class=\"img\"><img data-i=\"3\" alt=\"\" draggable=\"false\"></div><h3>Arraste-me 4</h3></article><article class=\"cd dr\" style=\"--r:-5deg;left:calc(50% - 150px + 100px);top:calc(50% - 130px + 0px)\" tabindex=\"0\"><div class=\"img\"><img data-i=\"4\" alt=\"\" draggable=\"false\"></div><h3>Arraste-me 5</h3></article></div>";
const RUNTIME = "(function(){\nvar FX=window.FX;\nFX.reduced=!!FX.reducedMotion&&window.matchMedia('(prefers-reduced-motion: reduce)').matches;\nFX.isTouch=window.matchMedia('(hover: none)').matches;\nif(FX.reduced)document.documentElement.classList.add('fx-reduced');\nwindow.$=function(s,r){return (r||document).querySelector(s)};\nwindow.$$=function(s,r){return Array.prototype.slice.call((r||document).querySelectorAll(s))};\nFX.clamp=function(v,a,b){return Math.min(b,Math.max(a,v))};\nFX.lerp=function(a,b,t){return a+(b-a)*t};\nFX.tick=function(fn){var id,t0=performance.now(),run=true;function f(t){if(run&&!document.hidden)fn((t-t0)/1000*FX.speed,t);if(run)id=requestAnimationFrame(f)}id=requestAnimationFrame(f);return{stop:function(){run=false;cancelAnimationFrame(id)}}};\nFX.pointer=function(el,cb){el=el||document.body;var last=-1e9;function mv(e){var p=e.touches?e.touches[0]:e;var r=el.getBoundingClientRect();last=performance.now();cb((p.clientX-r.left)/r.width,(p.clientY-r.top)/r.height,true,p.clientX-r.left,p.clientY-r.top)}\nif(FX.mouse){el.addEventListener('mousemove',mv);el.addEventListener('touchmove',mv,{passive:true});el.addEventListener('touchstart',mv,{passive:true});}\nif(FX.autoplay&&!FX.reduced)FX.tick(function(t){if(performance.now()-last>2500){var x=.5+Math.sin(t*.9)*.3,y=.5+Math.cos(t*1.3)*.25;var r=el.getBoundingClientRect();cb(x,y,false,x*r.width,y*r.height)}})};\nFX.progress=function(el){var r=el.getBoundingClientRect();var d=r.height-innerHeight;return d<=0?0:FX.clamp(-r.top/d,0,1)};\nFX.visible=function(el){var r=el.getBoundingClientRect();return FX.clamp((innerHeight-r.top)/(innerHeight+r.height),0,1)};\nFX.onScroll=function(cb){var q=false;function h(){if(q)return;q=true;requestAnimationFrame(function(){q=false;cb(scrollY)})}if(FX.scroll)addEventListener('scroll',h,{passive:true});cb(scrollY)};\nFX.inView=function(els,cb,th){var io=new IntersectionObserver(function(es){es.forEach(function(e){cb(e.target,e.isIntersecting,e)})},{threshold:th||.2});els.forEach(function(e){io.observe(e)});return io};\nFX.img=function(i,w,h){var s=(FX.images&&FX.images[i%5])||('fx'+i);if(/^(https?:|data:|\\/)/.test(s))return s;return 'https://picsum.photos/seed/'+encodeURIComponent(s+(i>=5?i:''))+'/'+(w||800)+'/'+(h||600)};\nFX.canvas=function(el){var c=document.createElement('canvas');c.style.cssText='position:absolute;inset:0;width:100%;height:100%;display:block';el.appendChild(c);var ctx=c.getContext('2d');var o={c:c,ctx:ctx,w:0,h:0};function rs(){var d=Math.min(2,devicePixelRatio||1);o.w=el.clientWidth;o.h=el.clientHeight;c.width=o.w*d;c.height=o.h*d;ctx.setTransform(d,0,0,d,0,0)}rs();addEventListener('resize',rs);return o};\nFX.hex=function(h,a){h=h.replace('#','');if(h.length===3)h=h.split('').map(function(x){return x+x}).join('');var n=parseInt(h,16);return 'rgba('+(n>>16&255)+','+(n>>8&255)+','+(n&255)+','+(a==null?1:a)+')'};\nwindow.$$=window.$$;document.querySelectorAll('[data-fx-headline]').forEach(function(e){if(FX.headline)e.textContent=FX.headline});\nFX.fmt=function(v,dec){var s=Math.round(v).toString();if(FX.separator)s=s.replace(/\\B(?=(\\d{3})+(?!\\d))/g,FX.separator);return (FX.prefix||'')+s+(FX.suffix||'')};\n})();";
const EFFECT = "$$('img[data-i]').forEach(function(i){i.src=FX.img(+i.dataset.i,+(i.dataset.w||700),+(i.dataset.h||500))});var z=10;$$('.dr').forEach(function(c){var sx,sy,ox,oy;c.addEventListener('pointerdown',function(e){c.setPointerCapture(e.pointerId);c.classList.add('on');c.style.zIndex=++z;sx=e.clientX;sy=e.clientY;ox=c.offsetLeft;oy=c.offsetTop;function mv(e){c.style.left=ox+e.clientX-sx+'px';c.style.top=oy+e.clientY-sy+'px'}function up(){c.classList.remove('on');c.removeEventListener('pointermove',mv);c.removeEventListener('pointerup',up)}c.addEventListener('pointermove',mv);c.addEventListener('pointerup',up)});c.addEventListener('keydown',function(e){var d={ArrowLeft:[-20,0],ArrowRight:[20,0],ArrowUp:[0,-20],ArrowDown:[0,20]}[e.key];if(d){e.preventDefault();c.style.left=c.offsetLeft+d[0]+'px';c.style.top=c.offsetTop+d[1]+'px'}})});";

export default function DragCards() {
  const hostRef = useRef<HTMLDivElement>(null);

  useEffect(() => {
    const host = hostRef.current;
    if (!host) return;
    // Para produção, prefira portar o EFFECT para hooks nativos (useEffect + refs).
    const iframe = document.createElement("iframe");
    iframe.title = "Drag Cards";
    iframe.setAttribute("sandbox", "allow-scripts");
    iframe.style.cssText = "width:100%;height:100%;border:0;display:block";
    iframe.srcdoc =
      "<!doctype html><html><head><style>" + CSS.replace(":host", ":root") + "</style></head><body>" + HTML +
      "<script>window.FX=" + JSON.stringify(SETTINGS) + ";" + RUNTIME + ";(function(){" + EFFECT + "})()<\/script></body></html>";
    host.appendChild(iframe);
    return () => {
      iframe.remove(); // destrói RAF, listeners e observers do efeito
    };
  }, []);

  return <div ref={hostRef} className="relative h-[480px] w-full overflow-hidden rounded-2xl" aria-label="Drag Cards" />;
}

Dependências

  • JSNativo do navegador — sem instalação

Referências

Nenhuma referência cadastrada ainda. Adicione URLs, screenshots ou vídeos que inspiram este efeito.

Efeitos semelhantes

#141
NOVOPOPULARLEVESEM DEPS

Cards · Cards

Border Beam Card

Feixe viaja pela borda.

⚡ Muito leve◆ Fácil⧉ CSS
Visualizar
#136
POPULARLEVESEM DEPS3D

Cards · Cards

3D Tilt Card

Card inclina de acordo com cursor.

⚡ Muito leve◆ Fácil⧉ CSS, JS
Visualizar
#145
LEVESEM DEPS

Cards · Cards

Expandable Card

Card cresce para exibir conteúdo.

⚡ Muito leve◆ Fácil⧉ CSS, JS
Visualizar