miniwhite commited on
Commit
60a46cc
·
verified ·
1 Parent(s): 92cc861

视频封面整个区域都可以进行点击播放,视频列表中视频详情有点赞功能

Browse files
Files changed (3) hide show
  1. components/video-card.js +46 -9
  2. script.js +2 -3
  3. style.css +2 -2
components/video-card.js CHANGED
@@ -16,8 +16,9 @@ class CustomVideoCard extends HTMLElement {
16
  overflow: hidden;
17
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
18
  transition: transform 0.2s ease, box-shadow 0.2s ease;
 
19
  }
20
- .video-card:hover {
21
  transform: translateY(-4px);
22
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
23
  z-index: 10;
@@ -66,14 +67,27 @@ class CustomVideoCard extends HTMLElement {
66
  -webkit-box-orient: vertical;
67
  overflow: hidden;
68
  }
69
-
70
  .video-stats {
71
  display: flex;
72
  align-items: center;
73
  color: #6b7280;
74
  font-size: 0.875rem;
 
 
 
 
 
 
75
  }
76
- </style>
 
 
 
 
 
 
 
 
77
 
78
  <div class="video-card">
79
  <div class="video-thumbnail">
@@ -95,13 +109,36 @@ class CustomVideoCard extends HTMLElement {
95
  feather.replace();
96
  </script>
97
  `;
98
-
99
- const playButton = this.shadowRoot.getElementById('play-button');
100
- playButton.addEventListener('click', () => {
101
- const videoPlayer = document.querySelector('custom-video-player');
102
- if (videoPlayer) {
103
- videoPlayer.playVideo(videoUrl, parseInt(likes));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
104
  }
 
 
 
105
  });
106
  }
107
  }
 
16
  overflow: hidden;
17
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
18
  transition: transform 0.2s ease, box-shadow 0.2s ease;
19
+ cursor: pointer;
20
  }
21
+ .video-card:hover {
22
  transform: translateY(-4px);
23
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
24
  z-index: 10;
 
67
  -webkit-box-orient: vertical;
68
  overflow: hidden;
69
  }
 
70
  .video-stats {
71
  display: flex;
72
  align-items: center;
73
  color: #6b7280;
74
  font-size: 0.875rem;
75
+ cursor: pointer;
76
+ transition: color 0.2s;
77
+ pointer-events: auto;
78
+ }
79
+ .video-stats:hover {
80
+ color: #ef4444;
81
  }
82
+ .video-stats i {
83
+ transition: all 0.2s;
84
+ }
85
+ .video-stats[data-liked] i,
86
+ .video-stats.liked i {
87
+ color: #ef4444;
88
+ fill: #ef4444;
89
+ }
90
+ </style>
91
 
92
  <div class="video-card">
93
  <div class="video-thumbnail">
 
109
  feather.replace();
110
  </script>
111
  `;
112
+ const videoCard = this.shadowRoot.querySelector('.video-card');
113
+ videoCard.addEventListener('click', (e) => {
114
+ // Don't trigger if clicking on like button
115
+ if (!e.target.closest('.video-stats')) {
116
+ const videoPlayer = document.querySelector('custom-video-player');
117
+ if (videoPlayer) {
118
+ videoPlayer.playVideo(videoUrl, parseInt(likes));
119
+ }
120
+ }
121
+ });
122
+
123
+ // Handle like button click
124
+ const likeButton = this.shadowRoot.querySelector('.video-stats');
125
+ likeButton.addEventListener('click', (e) => {
126
+ e.stopPropagation();
127
+ let currentLikes = parseInt(likes);
128
+ const isLiked = likeButton.hasAttribute('data-liked');
129
+
130
+ if (isLiked) {
131
+ likeButton.removeAttribute('data-liked');
132
+ currentLikes--;
133
+ likeButton.querySelector('i').classList.remove('liked');
134
+ } else {
135
+ likeButton.setAttribute('data-liked', '');
136
+ currentLikes++;
137
+ likeButton.querySelector('i').classList.add('liked');
138
  }
139
+
140
+ likes = currentLikes.toString();
141
+ likeButton.querySelector('span').textContent = currentLikes.toLocaleString();
142
  });
143
  }
144
  }
script.js CHANGED
@@ -102,7 +102,6 @@ videoGrid.appendChild(videoCard);
102
  loadingSpinner.classList.add('hidden');
103
  return;
104
  }
105
-
106
  videos.forEach(video => {
107
  const videoCard = document.createElement('custom-video-card');
108
  videoCard.setAttribute('video-id', video.id);
@@ -111,11 +110,11 @@ videoGrid.appendChild(videoCard);
111
  videoCard.setAttribute('video-url', video.videoUrl);
112
  videoCard.setAttribute('likes', video.likes);
113
  videoCard.setAttribute('orientation', video.orientation);
 
114
 
115
  videoGrid.appendChild(videoCard);
116
  });
117
-
118
- currentPage++;
119
  isLoading = false;
120
  loadingSpinner.classList.add('hidden');
121
  }, 500);
 
102
  loadingSpinner.classList.add('hidden');
103
  return;
104
  }
 
105
  videos.forEach(video => {
106
  const videoCard = document.createElement('custom-video-card');
107
  videoCard.setAttribute('video-id', video.id);
 
110
  videoCard.setAttribute('video-url', video.videoUrl);
111
  videoCard.setAttribute('likes', video.likes);
112
  videoCard.setAttribute('orientation', video.orientation);
113
+ videoCard.setAttribute('data-likes', video.likes);
114
 
115
  videoGrid.appendChild(videoCard);
116
  });
117
+ currentPage++;
 
118
  isLoading = false;
119
  loadingSpinner.classList.add('hidden');
120
  }, 500);
style.css CHANGED
@@ -36,7 +36,6 @@
36
  .video-thumbnail:hover img {
37
  transform: scale(1.03);
38
  }
39
-
40
  .play-button {
41
  position: absolute;
42
  top: 50%;
@@ -49,7 +48,8 @@
49
  display: flex;
50
  align-items: center;
51
  justify-content: center;
52
- cursor: pointer;
 
53
  }
54
  .video-player-modal {
55
  position: fixed;
 
36
  .video-thumbnail:hover img {
37
  transform: scale(1.03);
38
  }
 
39
  .play-button {
40
  position: absolute;
41
  top: 50%;
 
48
  display: flex;
49
  align-items: center;
50
  justify-content: center;
51
+ z-index: 2;
52
+ pointer-events: none;
53
  }
54
  .video-player-modal {
55
  position: fixed;