samlax12 commited on
Commit
dbf76b9
·
verified ·
1 Parent(s): e318da8

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +88 -8
index.html CHANGED
@@ -397,7 +397,14 @@
397
  50% { transform: translateY(-15px) rotate(10deg); }
398
  }
399
 
400
- /* 响应式优化 */
 
 
 
 
 
 
 
401
  @media (max-height: 700px) {
402
  .container {
403
  padding: 10px;
@@ -514,6 +521,10 @@
514
  <input type="text" class="note-input" placeholder="写点什么暖心的话吧~ ♡">
515
  </div>
516
 
 
 
 
 
517
  <button class="pay-button" onclick="showPayment()">
518
  💖 确认打赏 💖
519
  </button>
@@ -554,17 +565,12 @@
554
  const amount = element.dataset.amount;
555
 
556
  if (selectedItems.has(amount)) {
557
- // 增加数量
558
  itemQuantities[amount] = (itemQuantities[amount] || 1) + 1;
559
 
560
  // 更新数量显示
561
  const qtyElement = element.querySelector('.quantity');
562
- if (!qtyElement) {
563
- const span = document.createElement('span');
564
- span.className = 'quantity';
565
- span.textContent = `×${itemQuantities[amount]}`;
566
- element.appendChild(span);
567
- } else {
568
  qtyElement.textContent = `×${itemQuantities[amount]}`;
569
  }
570
  } else {
@@ -582,6 +588,80 @@
582
  updateTotalAmount();
583
  }
584
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
585
  function updateTotalAmount() {
586
  let total = 0;
587
  selectedItems.forEach(amount => {
 
397
  50% { transform: translateY(-15px) rotate(10deg); }
398
  }
399
 
400
+ /* 添加使用说明样式 */
401
+ .usage-tip {
402
+ font-size: 12px;
403
+ color: #d4a5a5;
404
+ text-align: center;
405
+ margin-top: 10px;
406
+ opacity: 0.8;
407
+ }
408
  @media (max-height: 700px) {
409
  .container {
410
  padding: 10px;
 
521
  <input type="text" class="note-input" placeholder="写点什么暖心的话吧~ ♡">
522
  </div>
523
 
524
+ <div class="usage-tip">
525
+ 点击选择项目 | 长按或右键减少数量
526
+ </div>
527
+
528
  <button class="pay-button" onclick="showPayment()">
529
  💖 确认打赏 💖
530
  </button>
 
565
  const amount = element.dataset.amount;
566
 
567
  if (selectedItems.has(amount)) {
568
+ // 已选中的项目,增加数量
569
  itemQuantities[amount] = (itemQuantities[amount] || 1) + 1;
570
 
571
  // 更新数量显示
572
  const qtyElement = element.querySelector('.quantity');
573
+ if (qtyElement) {
 
 
 
 
 
574
  qtyElement.textContent = `×${itemQuantities[amount]}`;
575
  }
576
  } else {
 
588
  updateTotalAmount();
589
  }
590
 
591
+ // 添加长按或右键点击来减少数量的功能
592
+ function handleRightClick(element, event) {
593
+ event.preventDefault(); // 阻止默认的右键菜单
594
+ const amount = element.dataset.amount;
595
+
596
+ if (selectedItems.has(amount) && itemQuantities[amount] > 0) {
597
+ if (itemQuantities[amount] === 1) {
598
+ // 如果数量为1,取消选择
599
+ element.classList.remove('active');
600
+ selectedItems.delete(amount);
601
+ delete itemQuantities[amount];
602
+
603
+ // 移除数量标签
604
+ const qtyElement = element.querySelector('.quantity');
605
+ if (qtyElement) {
606
+ qtyElement.remove();
607
+ }
608
+ } else {
609
+ // 数量大于1,减少数量
610
+ itemQuantities[amount]--;
611
+ const qtyElement = element.querySelector('.quantity');
612
+ if (qtyElement) {
613
+ qtyElement.textContent = `×${itemQuantities[amount]}`;
614
+ }
615
+ }
616
+
617
+ // 确保至少有一个项目被选中
618
+ if (selectedItems.size === 0) {
619
+ const firstItem = document.querySelector('.payment-item');
620
+ firstItem.classList.add('active');
621
+ const firstAmount = firstItem.dataset.amount;
622
+ selectedItems.add(firstAmount);
623
+ itemQuantities[firstAmount] = 1;
624
+
625
+ const span = document.createElement('span');
626
+ span.className = 'quantity';
627
+ span.textContent = '×1';
628
+ firstItem.appendChild(span);
629
+ }
630
+
631
+ updateTotalAmount();
632
+ }
633
+ }
634
+
635
+ // 初始化事件监听
636
+ document.addEventListener('DOMContentLoaded', function() {
637
+ // 为所有付款项目添加右键点击事件
638
+ document.querySelectorAll('.payment-item').forEach(item => {
639
+ item.addEventListener('contextmenu', function(e) {
640
+ handleRightClick(this, e);
641
+ });
642
+
643
+ // 添加长按事件(移动端)
644
+ let pressTimer;
645
+ item.addEventListener('touchstart', function(e) {
646
+ pressTimer = setTimeout(() => {
647
+ handleRightClick(this, e);
648
+ // 添加触觉反馈(如果设备支持)
649
+ if (navigator.vibrate) {
650
+ navigator.vibrate(50);
651
+ }
652
+ }, 500); // 500毫秒长按
653
+ });
654
+
655
+ item.addEventListener('touchend', function() {
656
+ clearTimeout(pressTimer);
657
+ });
658
+
659
+ item.addEventListener('touchmove', function() {
660
+ clearTimeout(pressTimer);
661
+ });
662
+ });
663
+ });
664
+
665
  function updateTotalAmount() {
666
  let total = 0;
667
  selectedItems.forEach(amount => {