Skip to content

Commit c011220

Browse files
committedNov 11, 2024·
Improve showing video in product card
1 parent 41e6de7 commit c011220

File tree

6 files changed

+91
-38
lines changed

6 files changed

+91
-38
lines changed
 

‎bakeup/static/css/project.css

+27-8
Original file line numberDiff line numberDiff line change
@@ -12819,6 +12819,7 @@ input.form-control.product-quantity::-webkit-outer-spin-button, input.form-contr
1281912819
}
1282012820
.figure.has-video {
1282112821
overflow: hidden;
12822+
position: relative;
1282212823
}
1282312824
.figure.has-video:hover {
1282412825
cursor: pointer;
@@ -12828,18 +12829,36 @@ input.form-control.product-quantity::-webkit-outer-spin-button, input.form-contr
1282812829
text-shadow: 0 0 5px rgba(0, 0, 0, 0.5);
1282912830
pointer-events: none;
1283012831
}
12831-
.figure.has-video img {
12832+
@media (max-width: 768px) {
12833+
.figure.has-video .fa-circle-play {
12834+
font-size: 3rem !important;
12835+
}
12836+
}
12837+
.figure.has-video .ratio {
12838+
z-index: -1;
1283212839
position: absolute;
12833-
z-index: 2;
1283412840
top: 50%;
1283512841
left: 50%;
1283612842
-webkit-transform: translate(-50%, -50%);
1283712843
transform: translate(-50%, -50%);
12844+
max-height: 100%;
1283812845
}
12839-
.figure.has-video video {
12840-
z-index: 1;
12846+
.figure.has-video .video-container {
12847+
display: none;
1284112848
}
12842-
.figure.has-video .btn-mute {
12849+
.figure.has-video .video-container video {
12850+
height: 100%;
12851+
width: auto;
12852+
-o-object-fit: cover;
12853+
object-fit: cover;
12854+
position: absolute;
12855+
top: 0;
12856+
left: 50%;
12857+
-webkit-transform: translateX(-50%);
12858+
transform: translateX(-50%);
12859+
}
12860+
.figure.has-video .video-container .btn-mute {
12861+
display: none;
1284312862
z-index: 1;
1284412863
position: absolute;
1284512864
bottom: 2px;
@@ -12848,13 +12867,13 @@ input.form-control.product-quantity::-webkit-outer-spin-button, input.form-contr
1284812867
text-shadow: 0 0 5px rgba(0, 0, 0, 0.5);
1284912868
border: 0;
1285012869
}
12851-
.figure.has-video .btn-mute.active {
12870+
.figure.has-video .video-container .btn-mute.active {
1285212871
color: #fff;
1285312872
}
12854-
.figure.has-video .btn-mute .fa-volume-high {
12873+
.figure.has-video .video-container .btn-mute .fa-volume-high {
1285512874
display: block;
1285612875
}
12857-
.figure.has-video .btn-mute .fa-volume-xmark {
12876+
.figure.has-video .video-container .btn-mute .fa-volume-xmark {
1285812877
display: none;
1285912878
}
1286012879

‎bakeup/static/css/project.min.css

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎bakeup/static/js/project.js

+29-17
Original file line numberDiff line numberDiff line change
@@ -602,43 +602,55 @@ $(function(){
602602
});
603603
$('.product-card .figure.has-video img').click(function(){
604604
var figure = $(this).parents('.figure');
605-
$(figure).find('img').hide();
606605
var play_button = $(figure).find('.fa-circle-play');
607-
var video = $(figure).find('video');
606+
var video = $(figure).find('.video-container');
607+
var mute_btn = $(figure).find('.btn-mute');
608608

609609
if (video.length) {
610-
video = video.get(0);
611-
video.play();
612-
video.addEventListener('play', function() {
610+
mute_btn.show();
611+
$(figure).find('.product-tags').hide();
612+
video.css('height',figure.outerHeight() + "px");
613+
video.show();
614+
var video_element = video.find('video').get(0);
615+
video_element.play();
616+
$(figure).find('img').hide();
617+
video_element.addEventListener('play', function() {
613618
$(this).find('.fa-circle-play').hide();
614619
});
615620

616621
// Event listener for 'pause' to show the button
617-
video.addEventListener('pause', function() {
622+
video_element.addEventListener('pause', function() {
618623
play_button.show();
619624
});
625+
// Event listener for 'ended' to show the button
626+
video_element.addEventListener('ended', function() {
627+
play_button.show();
628+
$(figure).find('img').show();
629+
$(figure).find('.product-tags').show();
630+
video.hide();
631+
});
620632

621633
// Initial icon setup to play or pause
622-
video.addEventListener('playing', () => {
634+
video_element.addEventListener('playing', () => {
623635
play_button.hide();
624636
});
625-
$(video).add(play_button).click(function() {
626-
if (video.paused) {
627-
video.play();
637+
$(video_element).add(play_button).click(function() {
638+
if (video_element.paused) {
639+
video_element.play();
628640
play_button.hide();
629641
} else {
630-
video.pause();
642+
video_element.pause();
631643
play_button.show();
632644
}
633645
});
634646
$(figure).find('.btn-mute').click(function() {
635-
video.muted = !video.muted;
636-
if (video.muted) {
637-
$(figure).find('.fa-volume-xmark').show();
638-
$(figure).find('.fa-volume-high').hide();
647+
video_element.muted = !video_element.muted;
648+
if (video_element.muted) {
649+
mute_btn.find('.fa-volume-xmark').show();
650+
mute_btn.find('.fa-volume-high').hide();
639651
} else {
640-
$(figure).find('.fa-volume-xmark').hide();
641-
$(figure).find('.fa-volume-high').show();
652+
mute_btn.find('.fa-volume-xmark').hide();
653+
mute_btn.find('.fa-volume-high').show();
642654
}
643655
})
644656
}

‎bakeup/static/js/project.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎bakeup/static/sass/project.scss

+27-5
Original file line numberDiff line numberDiff line change
@@ -140,19 +140,40 @@ input.form-control.product-quantity {
140140
z-index: 3;
141141
text-shadow: 0 0 5px rgba(0, 0, 0, 0.5);
142142
pointer-events: none;
143+
@media (max-width: 768px) {
144+
font-size: 3rem!important;
145+
}
143146
}
144147
img {
148+
// position: absolute;
149+
// z-index: 2;
150+
// top: 50%;
151+
// left: 50%;
152+
// transform: translate(-50%, -50%);
153+
}
154+
overflow: hidden;
155+
position: relative;
156+
.ratio {
157+
z-index: -1;
145158
position: absolute;
146-
z-index: 2;
147159
top: 50%;
148160
left: 50%;
149161
transform: translate(-50%, -50%);
162+
max-height: 100%;
150163
}
151-
overflow: hidden;
152-
video {
153-
z-index: 1;
154-
}
164+
.video-container {
165+
display: none;
166+
video {
167+
height: 100%;
168+
width: auto;
169+
object-fit: cover;
170+
position: absolute;
171+
top: 0;
172+
left: 50%;
173+
transform: translateX(-50%);
174+
}
155175
.btn-mute {
176+
display: none;
156177
z-index: 1;
157178
position: absolute;
158179
bottom: 2px;
@@ -176,6 +197,7 @@ input.form-control.product-quantity {
176197
// left: 50%;
177198
// color: $black;
178199
// }
200+
}
179201
}
180202
}
181203

‎bakeup/templates/shop/includes/product_card_header.html

+6-6
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,20 @@
1111
<img src="{{ im.url }}" width="{{ im.width }}" height="{{ im.height }}" class="card-img-top img-fluid img-hover" alt="product image">
1212
{% endthumbnail %}
1313
{% endif %}
14-
<div class="position-absolute bottom-20 start-20 z-3">
14+
<div class="position-absolute bottom-20 start-20 z-3 product-tags">
1515
{% for tag in product.tags.all %}<span class="badge rounded-pill bg-dark me-1"><i class="fas fa-tag"></i> {{ tag }}</span>{% endfor %}
1616
</div>
1717
{% if product.video_file %}
1818
<i class="fa-regular fa-circle-play position-absolute z-3 top-50 start-50 translate-middle text-white fs-1"></i>
19-
<div class="ratio ratio-16x9">
19+
<div class="video-container position-relative">
2020
<video>
2121
<source src="{{ product.video_file.url }}" type="video/mp4">
2222
Your browser does not support the video tag.
2323
</video>
24+
<button id="btn-mute" class="btn btn-text btn-mute">
25+
<i class="fa-solid fa-fw fa-volume-xmark"></i>
26+
<i class="fa-solid fa-fw fa-volume-high"></i>
27+
</button>
2428
</div>
25-
<button id="btn-mute" class="btn btn-text btn-mute">
26-
<i class="fa-solid fa-fw fa-volume-xmark"></i>
27-
<i class="fa-solid fa-fw fa-volume-high"></i>
28-
</button>
2929
{% endif %}
3030
</div>

0 commit comments

Comments
 (0)
Please sign in to comment.