パーツ番号 08-09-07 ・ JavaScript使用
ダブルタップいいねバースト
写真をダブルクリックすると大きなハートが弾んで消え、いいね数が加算されます。WordPressのSNS風フィードやギャラリーに使えます。
プレビュー
ソースコード
HTML
<div class="d08-09-07-stage">
<div class="d08-09-07-photo">
<span class="d08-09-07-hint">ダブルクリックでいいね</span>
</div>
<span class="d08-09-07-count">
<svg viewBox="0 0 24 24" width="14" height="14" aria-hidden="true"><path fill="#ff5470" d="M12 21s-7.5-4.8-10-9.2C.6 9 1.6 5.5 4.8 4.8 7 4.3 8.9 5.5 12 8.4c3.1-2.9 5-4.1 7.2-3.6C22.4 5.5 23.4 9 22 11.8 19.5 16.2 12 21 12 21z"/></svg>
<b class="d08-09-07-num">128</b>
</span>
</div>CSS
.d08-09-07-stage{position:relative;width:100%;max-width:220px}
.d08-09-07-photo{position:relative;width:100%;height:150px;border-radius:14px;background:linear-gradient(135deg,#38bdf8,#6a5cff);display:flex;align-items:center;justify-content:center;overflow:hidden;cursor:pointer;-webkit-tap-highlight-color:transparent;user-select:none}
.d08-09-07-hint{color:rgba(255,255,255,.85);font-size:12px;font-weight:600}
.d08-09-07-count{display:flex;align-items:center;gap:6px;margin-top:10px;font-size:13px;font-weight:700;color:#555}
.d08-09-07-heart{position:absolute;top:50%;left:50%;width:64px;height:64px;transform:translate(-50%,-50%) scale(0);opacity:0;pointer-events:none}
.d08-09-07-heart.is-go{animation:d08-09-07-pop .8s cubic-bezier(.2,1.4,.4,1) forwards}
@keyframes d08-09-07-pop{0%{transform:translate(-50%,-50%) scale(0);opacity:0}25%{transform:translate(-50%,-50%) scale(1.15);opacity:1}45%{transform:translate(-50%,-50%) scale(.95)}100%{transform:translate(-50%,-50%) scale(1.3);opacity:0}}JavaScript
(function(){
var photo=document.querySelector('#item-08-09-07 .d08-09-07-photo');
var stage=document.querySelector('#item-08-09-07 .d08-09-07-stage');
var num=document.querySelector('#item-08-09-07 .d08-09-07-num');
if(!photo||!stage||!num)return;
var liked=false;
photo.addEventListener('dblclick',function(){
var heart=document.createElement('span');heart.className='d08-09-07-heart is-go';
heart.innerHTML='<svg viewBox="0 0 24 24" width="64" height="64" aria-hidden="true"><path fill="#fff" stroke="#ff5470" stroke-width="1" d="M12 21s-7.5-4.8-10-9.2C.6 9 1.6 5.5 4.8 4.8 7 4.3 8.9 5.5 12 8.4c3.1-2.9 5-4.1 7.2-3.6C22.4 5.5 23.4 9 22 11.8 19.5 16.2 12 21 12 21z"/></svg>';
stage.appendChild(heart);
setTimeout(function(){heart.remove();},820);
if(!liked){liked=true;num.textContent=String(Number(num.textContent)+1);}
});
})();クラス名 .d08-09-07 は本ライブラリ内での識別用です。複数のパーツを同じページで使う場合は、重複しないよう名前を変更してください。