Eng sof CSS soati

Men sof CSS ob'ektlarini qanday yaratishni o'rganyapman. Men shu vaqtning o'zida analog soatni yaratmoqdamiz.

Savol: soatni ushbu soat bilan yaratishning eng sof yo'lidir.

Demak ... qo'llarni qanday qilib ko'tarish kerakligini bilaman, hozirgi soatni ko'rsatish uchun bir usulni bilaman (javascript bilan). Lekin hozirgi soatdan boshlab qo'llarni harakatga keltirolmayman.

Men aniqmi? Eng yaxshi yo'l nima? (Men hech qachon kamroq ishlatmaganman yoki boshqa birovni o'ldirganim yo'q, lekin uni sinab ko'rishim mumkin :))

Kodependagi mening kodim: codepen.io/AlexandraCardoso/pen/ZeQdxg

Yordamingiz uchun tashakkur va har qanday inglizcha xato haqida uzr so'raymiz.

0
Joriy vaqtni olish uchun sizga JavaScript kerak. Keyin animatsiyani boshlash uchun har bir soatda, daqiqada va ikkinchi displeyda qo'shimcha chig'anoq kerak. Qayta ishlashni yangilashingiz kerak bo'ladi: yukni har bir marta yuklang. Vizual, animatsiyalaringiz u yerdan boshlanadi ...
qo'shib qo'ydi muallif G-Cyr, manba
Joriy vaqtni olish uchun sizga JavaScript kerak. Keyin animatsiyani boshlash uchun har bir soatda, daqiqada va ikkinchi displeyda qo'shimcha chig'anoq kerak. Qayta ishlashni yangilashingiz kerak bo'ladi: yukni har bir marta yuklang. Vizual, animatsiyalaringiz u yerdan boshlanadi ...
qo'shib qo'ydi muallif G-Cyr, manba
Joriy vaqtni olish uchun sizga JavaScript kerak. Keyin animatsiyani boshlash uchun har bir soatda, daqiqada va ikkinchi displeyda qo'shimcha chig'anoq kerak. Qayta ishlashni yangilashingiz kerak bo'ladi: yukni har bir marta yuklang. Vizual, animatsiyalaringiz u yerdan boshlanadi ...
qo'shib qo'ydi muallif G-Cyr, manba
qo'shib qo'ydi muallif G-Cyr, manba

8 javoblar

CSS-ni iloji boricha "CSS Variables" -dan foydalanishingiz mumkin - bu bilan siz faqat soatni belgilashingiz va CSS-ni animatsiyaning

//  set current time on load
const now = new Date()
const docStyle = document.documentElement.style;
docStyle.setProperty('--seconds', now.getSeconds());
docStyle.setProperty('--minutes', now.getMinutes());
docStyle.setProperty('--hours',   now.getHours());

Here is a simple dummy http://codepen.io/jakob-e/pen/pePMzE

2
qo'shib qo'ydi

CSS-ni iloji boricha "CSS Variables" -dan foydalanishingiz mumkin - bu bilan siz faqat soatni belgilashingiz va CSS-ni animatsiyaning

//  set current time on load
const now = new Date()
const docStyle = document.documentElement.style;
docStyle.setProperty('--seconds', now.getSeconds());
docStyle.setProperty('--minutes', now.getMinutes());
docStyle.setProperty('--hours',   now.getHours());

Here is a simple dummy http://codepen.io/jakob-e/pen/pePMzE

2
qo'shib qo'ydi

CSS-ni iloji boricha "CSS Variables" -dan foydalanishingiz mumkin - bu bilan siz faqat soatni belgilashingiz va CSS-ni animatsiyaning

//  set current time on load
const now = new Date()
const docStyle = document.documentElement.style;
docStyle.setProperty('--seconds', now.getSeconds());
docStyle.setProperty('--minutes', now.getMinutes());
docStyle.setProperty('--hours',   now.getHours());

Here is a simple dummy http://codepen.io/jakob-e/pen/pePMzE

2
qo'shib qo'ydi

CSS-ni iloji boricha "CSS Variables" -dan foydalanishingiz mumkin - bu bilan siz faqat soatni belgilashingiz va CSS-ni animatsiyaning

//  set current time on load
const now = new Date()
const docStyle = document.documentElement.style;
docStyle.setProperty('--seconds', now.getSeconds());
docStyle.setProperty('--minutes', now.getMinutes());
docStyle.setProperty('--hours',   now.getHours());

Here is a simple dummy http://codepen.io/jakob-e/pen/pePMzE

2
qo'shib qo'ydi

The best I could do is this: http://codepen.io/anon/pen/zZZaNY

HTML:

.canvas
  .relogio
    #hora
    #minuto
    #segundo
    .centro

  .shadow
    .shadow-inner

CSS:

body{
  background-color:salmon;
}

.canvas{
  position: relative;
  margin: auto;
  display: block;
  width: 600px; height: 600px;
}

.relogio{
  position:absolute;
  background-color:white;
  width:600px; height:600px;
  border-radius:100%;
  border:25px solid lightsalmon;
  box-sizing: border-box;
}

#hora{
  z-index:3;
  position: absolute;
  width: 0; height: 0;
  border: 20px solid transparent;
  border-bottom: 60px solid darkgray;
  top: calc(45% - 120px); left: calc(50% - 20px);
  transform-origin: 50% 185%;
transform:rotate(12deg);
  animation-iteration-count: infinite;
  animation-timing-function: linear;
}

#hora:after {
  content: '';
  position: absolute;
  left: -20px; top: 60px;
  width: 0; height: 0;
  border: 20px solid transparent;
  border-top: 60px solid salmon;
}

#minuto{
  z-index:2;
  position: absolute;
  width: 0; height: 0;
  border: 20px solid transparent;
  border-bottom: 100px solid lightcoral;
  top: calc(45% - 200px) ; left: calc(50% - 20px);
  transform-origin: 50% 190%;
transform: rotate(6deg);
  animation-iteration-count: infinite;
  animation-timing-function: linear;
}

#minuto:after {
  content: '';
  position: absolute;
  left: -20px; top: 100px;
  width: 0; height: 0;
  border: 20px solid transparent;
  border-top: 100px solid lightcoral;
}

#segundo{
  z-index:1;
  position: absolute;
  width: 2px; height: 45%;
  background-color:darkgray;
  top:5%; left: calc(50% - 1px);
  transform:rotate(1deg);
  transform-origin: 50% 100%;
  animation-iteration-count: infinite;
  animation-timing-function: linear;
}

.centro {
  z-index:4;
  height: 5%;
  width: 5%;
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  margin: auto;
  background: salmon;
  border-radius: 100%;
}

.shadow{
  z-index:-1;
  position:absolute;
  width:600px; height:600px;
  transform:translate(0%, 50%);
}
.shadow-inner{
  width:600px; height:600px;
  transform:rotate(-45deg);
  transform-origin: 50% 0%;
  background: black;
  background: -webkit-linear-gradient(gray,transparent); 
  background: -o-linear-gradient(gray,transparent); 
  background: -moz-linear-gradient(gray,transparent); 
  background: linear-gradient(gray,transparent); 
}

JavaScript:

function myFunction() {
  var d = new Date();
  var h = d.getHours();
  var m = d.getMinutes();
  var s = d.getSeconds();
if(h>12){h=h-12;}
    var secAngle = s*6;
  var minAngle = m*6;
  var hourAngle = h*30;


  var segundos = document.getElementById('segundo').style.transform = "rotate(" + secAngle + "deg)";
  var minutos = document.getElementById("minuto").style.transform = "rotate(" + minAngle + "deg)";
    var horas = document.getElementById('hora').style.transform = "rotate(" + hourAngle + "deg)";
}
window.onload=function(){
myFunction();
setInterval(myFunction,1000);
}
$(document).ready(myFunction());
0
qo'shib qo'ydi

The best I could do is this: http://codepen.io/anon/pen/zZZaNY

HTML:

.canvas
  .relogio
    #hora
    #minuto
    #segundo
    .centro

  .shadow
    .shadow-inner

CSS:

body{
  background-color:salmon;
}

.canvas{
  position: relative;
  margin: auto;
  display: block;
  width: 600px; height: 600px;
}

.relogio{
  position:absolute;
  background-color:white;
  width:600px; height:600px;
  border-radius:100%;
  border:25px solid lightsalmon;
  box-sizing: border-box;
}

#hora{
  z-index:3;
  position: absolute;
  width: 0; height: 0;
  border: 20px solid transparent;
  border-bottom: 60px solid darkgray;
  top: calc(45% - 120px); left: calc(50% - 20px);
  transform-origin: 50% 185%;
transform:rotate(12deg);
  animation-iteration-count: infinite;
  animation-timing-function: linear;
}

#hora:after {
  content: '';
  position: absolute;
  left: -20px; top: 60px;
  width: 0; height: 0;
  border: 20px solid transparent;
  border-top: 60px solid salmon;
}

#minuto{
  z-index:2;
  position: absolute;
  width: 0; height: 0;
  border: 20px solid transparent;
  border-bottom: 100px solid lightcoral;
  top: calc(45% - 200px) ; left: calc(50% - 20px);
  transform-origin: 50% 190%;
transform: rotate(6deg);
  animation-iteration-count: infinite;
  animation-timing-function: linear;
}

#minuto:after {
  content: '';
  position: absolute;
  left: -20px; top: 100px;
  width: 0; height: 0;
  border: 20px solid transparent;
  border-top: 100px solid lightcoral;
}

#segundo{
  z-index:1;
  position: absolute;
  width: 2px; height: 45%;
  background-color:darkgray;
  top:5%; left: calc(50% - 1px);
  transform:rotate(1deg);
  transform-origin: 50% 100%;
  animation-iteration-count: infinite;
  animation-timing-function: linear;
}

.centro {
  z-index:4;
  height: 5%;
  width: 5%;
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  margin: auto;
  background: salmon;
  border-radius: 100%;
}

.shadow{
  z-index:-1;
  position:absolute;
  width:600px; height:600px;
  transform:translate(0%, 50%);
}
.shadow-inner{
  width:600px; height:600px;
  transform:rotate(-45deg);
  transform-origin: 50% 0%;
  background: black;
  background: -webkit-linear-gradient(gray,transparent); 
  background: -o-linear-gradient(gray,transparent); 
  background: -moz-linear-gradient(gray,transparent); 
  background: linear-gradient(gray,transparent); 
}

JavaScript:

function myFunction() {
  var d = new Date();
  var h = d.getHours();
  var m = d.getMinutes();
  var s = d.getSeconds();
if(h>12){h=h-12;}
    var secAngle = s*6;
  var minAngle = m*6;
  var hourAngle = h*30;


  var segundos = document.getElementById('segundo').style.transform = "rotate(" + secAngle + "deg)";
  var minutos = document.getElementById("minuto").style.transform = "rotate(" + minAngle + "deg)";
    var horas = document.getElementById('hora').style.transform = "rotate(" + hourAngle + "deg)";
}
window.onload=function(){
myFunction();
setInterval(myFunction,1000);
}
$(document).ready(myFunction());
0
qo'shib qo'ydi

The best I could do is this: http://codepen.io/anon/pen/zZZaNY

HTML:

.canvas
  .relogio
    #hora
    #minuto
    #segundo
    .centro

  .shadow
    .shadow-inner

CSS:

body{
  background-color:salmon;
}

.canvas{
  position: relative;
  margin: auto;
  display: block;
  width: 600px; height: 600px;
}

.relogio{
  position:absolute;
  background-color:white;
  width:600px; height:600px;
  border-radius:100%;
  border:25px solid lightsalmon;
  box-sizing: border-box;
}

#hora{
  z-index:3;
  position: absolute;
  width: 0; height: 0;
  border: 20px solid transparent;
  border-bottom: 60px solid darkgray;
  top: calc(45% - 120px); left: calc(50% - 20px);
  transform-origin: 50% 185%;
transform:rotate(12deg);
  animation-iteration-count: infinite;
  animation-timing-function: linear;
}

#hora:after {
  content: '';
  position: absolute;
  left: -20px; top: 60px;
  width: 0; height: 0;
  border: 20px solid transparent;
  border-top: 60px solid salmon;
}

#minuto{
  z-index:2;
  position: absolute;
  width: 0; height: 0;
  border: 20px solid transparent;
  border-bottom: 100px solid lightcoral;
  top: calc(45% - 200px) ; left: calc(50% - 20px);
  transform-origin: 50% 190%;
transform: rotate(6deg);
  animation-iteration-count: infinite;
  animation-timing-function: linear;
}

#minuto:after {
  content: '';
  position: absolute;
  left: -20px; top: 100px;
  width: 0; height: 0;
  border: 20px solid transparent;
  border-top: 100px solid lightcoral;
}

#segundo{
  z-index:1;
  position: absolute;
  width: 2px; height: 45%;
  background-color:darkgray;
  top:5%; left: calc(50% - 1px);
  transform:rotate(1deg);
  transform-origin: 50% 100%;
  animation-iteration-count: infinite;
  animation-timing-function: linear;
}

.centro {
  z-index:4;
  height: 5%;
  width: 5%;
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  margin: auto;
  background: salmon;
  border-radius: 100%;
}

.shadow{
  z-index:-1;
  position:absolute;
  width:600px; height:600px;
  transform:translate(0%, 50%);
}
.shadow-inner{
  width:600px; height:600px;
  transform:rotate(-45deg);
  transform-origin: 50% 0%;
  background: black;
  background: -webkit-linear-gradient(gray,transparent); 
  background: -o-linear-gradient(gray,transparent); 
  background: -moz-linear-gradient(gray,transparent); 
  background: linear-gradient(gray,transparent); 
}

JavaScript:

function myFunction() {
  var d = new Date();
  var h = d.getHours();
  var m = d.getMinutes();
  var s = d.getSeconds();
if(h>12){h=h-12;}
    var secAngle = s*6;
  var minAngle = m*6;
  var hourAngle = h*30;


  var segundos = document.getElementById('segundo').style.transform = "rotate(" + secAngle + "deg)";
  var minutos = document.getElementById("minuto").style.transform = "rotate(" + minAngle + "deg)";
    var horas = document.getElementById('hora').style.transform = "rotate(" + hourAngle + "deg)";
}
window.onload=function(){
myFunction();
setInterval(myFunction,1000);
}
$(document).ready(myFunction());
0
qo'shib qo'ydi

The best I could do is this: http://codepen.io/anon/pen/zZZaNY

HTML:

.canvas
  .relogio
    #hora
    #minuto
    #segundo
    .centro

  .shadow
    .shadow-inner

CSS:

body{
  background-color:salmon;
}

.canvas{
  position: relative;
  margin: auto;
  display: block;
  width: 600px; height: 600px;
}

.relogio{
  position:absolute;
  background-color:white;
  width:600px; height:600px;
  border-radius:100%;
  border:25px solid lightsalmon;
  box-sizing: border-box;
}

#hora{
  z-index:3;
  position: absolute;
  width: 0; height: 0;
  border: 20px solid transparent;
  border-bottom: 60px solid darkgray;
  top: calc(45% - 120px); left: calc(50% - 20px);
  transform-origin: 50% 185%;
transform:rotate(12deg);
  animation-iteration-count: infinite;
  animation-timing-function: linear;
}

#hora:after {
  content: '';
  position: absolute;
  left: -20px; top: 60px;
  width: 0; height: 0;
  border: 20px solid transparent;
  border-top: 60px solid salmon;
}

#minuto{
  z-index:2;
  position: absolute;
  width: 0; height: 0;
  border: 20px solid transparent;
  border-bottom: 100px solid lightcoral;
  top: calc(45% - 200px) ; left: calc(50% - 20px);
  transform-origin: 50% 190%;
transform: rotate(6deg);
  animation-iteration-count: infinite;
  animation-timing-function: linear;
}

#minuto:after {
  content: '';
  position: absolute;
  left: -20px; top: 100px;
  width: 0; height: 0;
  border: 20px solid transparent;
  border-top: 100px solid lightcoral;
}

#segundo{
  z-index:1;
  position: absolute;
  width: 2px; height: 45%;
  background-color:darkgray;
  top:5%; left: calc(50% - 1px);
  transform:rotate(1deg);
  transform-origin: 50% 100%;
  animation-iteration-count: infinite;
  animation-timing-function: linear;
}

.centro {
  z-index:4;
  height: 5%;
  width: 5%;
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  margin: auto;
  background: salmon;
  border-radius: 100%;
}

.shadow{
  z-index:-1;
  position:absolute;
  width:600px; height:600px;
  transform:translate(0%, 50%);
}
.shadow-inner{
  width:600px; height:600px;
  transform:rotate(-45deg);
  transform-origin: 50% 0%;
  background: black;
  background: -webkit-linear-gradient(gray,transparent); 
  background: -o-linear-gradient(gray,transparent); 
  background: -moz-linear-gradient(gray,transparent); 
  background: linear-gradient(gray,transparent); 
}

JavaScript:

function myFunction() {
  var d = new Date();
  var h = d.getHours();
  var m = d.getMinutes();
  var s = d.getSeconds();
if(h>12){h=h-12;}
    var secAngle = s*6;
  var minAngle = m*6;
  var hourAngle = h*30;


  var segundos = document.getElementById('segundo').style.transform = "rotate(" + secAngle + "deg)";
  var minutos = document.getElementById("minuto").style.transform = "rotate(" + minAngle + "deg)";
    var horas = document.getElementById('hora').style.transform = "rotate(" + hourAngle + "deg)";
}
window.onload=function(){
myFunction();
setInterval(myFunction,1000);
}
$(document).ready(myFunction());
0
qo'shib qo'ydi