Tailwind.css में सरल एनिमेटेड एनालॉग घड़ी

केवल Tailwind.css में एनीमेशन के साथ एक बहुत ही सरल एनालॉग घड़ी कैसे बनाएं

ए क्लॉकवर्क टेलविंड

जिन परियोजनाओं पर मैं काम कर रहा हूं (मेरे पोर्टफोलियो-पेज से उपलब्ध) के लिए विवरण पृष्ठ डिजाइन करते समय, मैंने एक साधारण एनिमेटेड एनालॉग घड़ी भी लागू की जो परियोजना की अवधि के बगल में प्रदान की जाती है।

क्योंकि मैं किसी भी नए बाहरी पुस्तकालय या वीडियो का उपयोग नहीं करना चाहता था, इसलिए मैंने घड़ी को Tailwind.css और इसकी महान एनीमेशन उपयोगिताओं के माध्यम से लागू करने का निर्णय लिया।

कोड उदाहरण

कहने के लिए और कुछ नहीं है, जैसा कि मैंने सोचा था कि यह आपके लिए सबसे उपयोगी होगा जब मैं पुन: प्रयोज्यता के लिए कुछ कोड उदाहरण प्रदान करता हूं।

हर उदाहरण में लेआउट लगभग एक जैसा ही है। मैं बस एक दूसरे के शीर्ष पर पूर्ण स्थिति के माध्यम से कुछ div-boxes प्रस्तुत करता हूं। चूंकि प्रत्येक बॉक्स में केवल सबसे छोटी चौड़ाई उपलब्ध होती है, वे घड़ी में दिखाई देने वाले कर्सर प्रतीत होते हैं।

आखिरी उदाहरण दर्शाता है कि 12 बजे कैसे शुरू किया जाए। पहले दो उदाहरण प्रत्येक 3 बजे शुरू होते हैं, क्योंकि उन्हें पंक्ति में रखा गया है।

उदाहरण 1: सबसे सरल घड़ी

Image dbead4b8e463

export function Clock() {
  return (
    <div className="flex justify-center py-10 group">
      <div className="relative flex items-center justify-end w-20 h-20 overflow-hidden bg-gray-900 rounded-full ">
        <div className="absolute w-1/2 h-1 bg-white rounded-full origin-left -rotate-12 group-hover:rotate-[215deg] duration-1000 ease-in-out" />

        <div className="absolute w-1/2 h-1  origin-left rotate-[70] group-hover:rotate-[340deg] duration-1000 ease-in-out">
          <div className="w-2/3 h-full bg-white rounded-full" />
        </div>

        <div className="absolute flex justify-center flex-1 w-full">
          <div className="w-1 h-1 bg-white rounded-full" />
        </div>
      </div>
    </div>
  );
}

उदाहरण 2: सीमा और संकेतकों वाली घड़ी

Image 06597167696f

import React from "react";
// Note that I'm using 'clsx' for
// composing classnames.
import clsx from "clsx";

export function Clock() {
  return (
    <div className="relative flex items-center justify-end w-20 h-20 overflow-hidden rounded-full ring-gray-600 ring-1">
      {Array.from({ length: 8 }, (_, i) => (
        <div
          key={i}
          style={{ height: 1 }}
          className={clsx("absolute w-1/2 origin-left flex justify-end", {
            "rotate-0": i === 0,
            "rotate-45": i === 1,
            "rotate-90": i === 2,
            "rotate-[135deg]": i === 3,
            "rotate-180": i === 4,
            "rotate-[225deg]": i === 5,
            "rotate-[270deg]": i === 6,
            "rotate-[315deg]": i === 7,
          })}>
          <div className="w-1/3 h-full bg-gray-600 rounded-full" />
        </div>
      ))}

      <div className="absolute w-1/2 h-1 bg-gray-300 rounded-full origin-left -rotate-12 group-hover:rotate-[215deg] duration-1000 ease-in-out" />

      <div className="absolute w-1/2 h-1  origin-left rotate-[85deg] group-hover:rotate-[340deg] duration-1000 ease-in-out">
        <div className="w-2/3 h-full bg-gray-300 rounded-full" />
      </div>

      <div className="absolute flex justify-center flex-1 w-full">
        <div className="w-1 h-1 bg-gray-300 rounded-full" />
      </div>
    </div>
  );
}

उदाहरण 3: आधी रात से शुरू होने वाली घड़ी

Image c2d6bdde9e1e

export function Clock() {
  return (
    <div className="flex justify-center py-10 group">
      <div className="relative flex flex-col items-center justify-start w-20 h-20 overflow-hidden bg-gray-900 rounded-full ">
        <div className="absolute w-1 duration-1000 ease-in-out origin-bottom bg-gradient-to-t from-white to-red-400 rounded-full h-1/2 group-hover:rotate-[200deg]" />

        <div className="absolute h-1/2 w-1 origin-bottom rotate-[55deg] group-hover:rotate-[340deg] duration-1000 ease-in-out flex flex-col justify-end">
          <div className="w-full rounded-full bg-gradient-to-t from-white to-blue-400 h-2/3" />
        </div>

        <div className="absolute flex items-center justify-center flex-1 w-full h-full">
          <div className="w-1 h-1 bg-white rounded-full" />
        </div>
      </div>
    </div>
  );
}

सुझाव

संबंधित

परिशिष्ट

भाषाएँ