動画のように、青いグラデーションとともにバーを円形に回転させたいです。
https://www.youtube.com/watch?v=u-BWupHzTnU
バーを回転させる所までは出来ました。
https://jsfiddle.net/ghost7492/gd6rLzcs/6/
グラデーションを付けるアイディア、
何かないでしょうか。
svg+cssで出来そうなので、今、試し中です。
気になる質問をクリップする
クリップした質問は、後からいつでもMYページで確認できます。
またクリップした質問に回答があった際、通知やメールを受け取ることができます。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
回答2件
0
ベストアンサー
svg+cssで出来そうなので、今、試し中です。
CSSやSVGにおいてもこの挙動は全くお手軽ではありません.
CSSやSVGでは線形グラデーションと放射状(円形)グラデーションしかサポートしないからです.そのため, 円弧に沿ったグラデーションを表現するには何らかの細工を要します.
- 線形グラデーションを使ってグラデーション部をごまかす
- グラデーションは別途ラスタ画像としておく
例えば前者であれば次のように.
HTML
1<svg width="200px" height="200px"> 2 <defs> 3 <linearGradient id="lg" gradientUnits="userSpaceOnUse" x1="0" y1="0" x2="200" y2="200"> 4 <stop offset=".3" stop-opacity="1"/> 5 <stop offset=".5" stop-opacity="0"/> 6 </linearGradient> 7 <mask id="mask" stroke="white"> 8 <circle id="base" cx="100" cy="100" r="80" transform="rotate(-90,100,100)" stroke-width="20" fill="none"/> 9 </mask> 10 </defs> 11 <rect width="100" height="200" fill="url(#lg)" mask="url(#mask)"/> 12 <use xlink:href="#base" stroke="var(--bar)" stroke-dasharray="3,1000"/> 13</svg>
CSS
1svg{ 2 animation: rotate 60s linear 0s infinite; 3 --bar: navy; 4 --stroke: blue; 5} 6stop{ 7 stop-color: var(--stroke); 8} 9@keyframes rotate{ 10 0%{transform: rotatea(0deg);} 11 100%{transform: rotate(360deg);} 12}
投稿2018/03/29 00:29
総合スコア4756
0
ゴリ押css
rotateするとz-indexとかpositionの指定おかしくなるの初めて知った。
html
1<!doctype html> 2<html lang="jp"> 3<head> 4 <meta charset="UTF-8"> 5 <title>Document</title> 6 <style type="text/css"> 7html, body { 8 height: 100%; 9 background: #ffd740; 10 position: relative; 11} 12 13.clock { 14 width: 192px; 15 height: 192px; 16 border-radius: 50%; 17 background: #fff; 18 position: absolute; 19 top: 50%; 20 left: 50%; 21 transform: translate(-50%, -50%); 22} 23 24#bar { 25 width: 192px; 26 height: 192px; 27 background: radial-gradient(farthest-side at top right, #07f, #FFF); 28 transform: translate(-50%, -50%); 29 background-size: 50% 50%; 30 background-repeat: no-repeat; 31 border-radius: 50%; 32 position: absolute; 33} 34#bar:before, #bar:after { 35 content: ""; 36 display: block; 37} 38#bar::before { 39 width: 2px; 40 height: 20px; 41 border-radius: 4px; 42 background: #0175ad; 43 position: absolute; 44 bottom: 89%; 45 left: 50%; 46 transform: translate(-50%, 0); 47} 48 49#bar::after { 50 width: 4px; 51 height: 4px; 52 background: red; 53 border: 2px solid red; 54 position: absolute; 55 top: 50%; 56 left: 50%; 57 margin-top: -4px; 58 margin-left: -4px; 59} 60 61.gra { 62 width: 153px; 63 height: 153px; 64 margin: 20px; 65 border-radius: 50%; 66 background: #f1f1f1; 67 position: absolute; 68 top: 0; 69 left: 0; 70} 71 72 73 </style> 74</head> 75<body> 76 <div class="clock"> 77 <div id="bar"> 78 <div class="gra"></div> 79 </div> 80 </div> 81<script> 82 //https://codepen.io/chrisota/pen/JoYWQM 83 84// Yay for SO - http://stackoverflow.com/questions/23847310/css-and-jquery-analog-clock-smooth-animation 85//use requestAnimationFrame for smoothness (shimmed with setTimeout fallback) 86window.requestAnimFrame = (function () { 87 return window.requestAnimationFrame || 88 window.webkitRequestAnimationFrame || 89 window.mozRequestAnimationFrame || 90 function (callback) { 91 window.setTimeout(callback, 1000 / 60); 92 }; 93})(); 94 95//initialize the clock in a self-invoking function 96(function clock() { 97 const bar = document.getElementById("bar"); 98 const start = new Date(); 99 //set up a loop 100 (function loop() { 101 requestAnimFrame(loop); 102 draw(); 103 })(); 104 //position the hands 105 function draw() { 106 const now = new Date(); 107 const diffInMil = (now.getTime() - start.getTime());// difference in milliseconds 108 const h = (diffInMil / (1000 * 60 * 60));//hours 109 const m = (h * 60);//minutes 110 const s = (m * 60) * 3;//seconds 111 //rotate the hands accordingly 112 bar.style.webkitTransform = "rotate(" + (s * 6) + "deg)"; 113 } 114})(); 115 </script> 116</body> 117</html>
投稿2018/03/29 05:55
総合スコア3828
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
あなたの回答
tips
太字
斜体
打ち消し線
見出し
引用テキストの挿入
コードの挿入
リンクの挿入
リストの挿入
番号リストの挿入
表の挿入
水平線の挿入
プレビュー
質問の解決につながる回答をしましょう。 サンプルコードなど、より具体的な説明があると質問者の理解の助けになります。 また、読む側のことを考えた、分かりやすい文章を心がけましょう。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/03/29 18:51 編集