added the video feature
This commit is contained in:
Binary file not shown.
BIN
static/uploads/Ibex_450.jpg
Normal file
BIN
static/uploads/Ibex_450.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 148 KiB |
BIN
static/uploads/big_buck_bunny_720p_1mb.mp4
Normal file
BIN
static/uploads/big_buck_bunny_720p_1mb.mp4
Normal file
Binary file not shown.
@@ -11,12 +11,12 @@
|
|||||||
align-items: center;
|
align-items: center;
|
||||||
background-color: black;
|
background-color: black;
|
||||||
}
|
}
|
||||||
img {
|
img, video {
|
||||||
max-width: 100%;
|
max-width: 100%;
|
||||||
max-height: 100%;
|
max-height: 100%;
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
img.active {
|
.active {
|
||||||
display: block;
|
display: block;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
@@ -24,26 +24,43 @@
|
|||||||
<body>
|
<body>
|
||||||
<div id="content">
|
<div id="content">
|
||||||
{% for item in content %}
|
{% for item in content %}
|
||||||
<img src="{{ url_for('static', filename='uploads/' ~ item.file_name) }}" alt="Content Image" data-duration="{{ item.duration }}">
|
{% if item.file_name.endswith('.mp4') %}
|
||||||
|
<video class="content-item" data-duration="{{ item.duration }}" controls>
|
||||||
|
<source src="{{ url_for('static', filename='uploads/' ~ item.file_name) }}" type="video/mp4">
|
||||||
|
Your browser does not support the video tag.
|
||||||
|
</video>
|
||||||
|
{% else %}
|
||||||
|
<img src="{{ url_for('static', filename='uploads/' ~ item.file_name) }}" alt="Content Image" class="content-item" data-duration="{{ item.duration }}">
|
||||||
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
<script>
|
<script>
|
||||||
const images = document.querySelectorAll('#content img');
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
let index = 0;
|
const items = document.querySelectorAll('.content-item');
|
||||||
|
let currentIndex = 0;
|
||||||
|
|
||||||
function showNextImage() {
|
function showNextItem() {
|
||||||
images.forEach((img, i) => {
|
items.forEach(item => item.classList.remove('active'));
|
||||||
img.classList.toggle('active', i === index);
|
const currentItem = items[currentIndex];
|
||||||
});
|
currentItem.classList.add('active');
|
||||||
const duration = images[index].getAttribute('data-duration') * 1000;
|
|
||||||
index = (index + 1) % images.length;
|
|
||||||
setTimeout(showNextImage, duration);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (images.length > 0) {
|
const duration = parseInt(currentItem.getAttribute('data-duration'), 10) * 1000;
|
||||||
images[0].classList.add('active');
|
if (currentItem.tagName === 'VIDEO') {
|
||||||
showNextImage();
|
currentItem.play();
|
||||||
}
|
currentItem.onended = () => {
|
||||||
|
currentIndex = (currentIndex + 1) % items.length;
|
||||||
|
showNextItem();
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
setTimeout(() => {
|
||||||
|
currentIndex = (currentIndex + 1) % items.length;
|
||||||
|
showNextItem();
|
||||||
|
}, duration);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
showNextItem();
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
@@ -11,12 +11,12 @@
|
|||||||
align-items: center;
|
align-items: center;
|
||||||
background-color: black;
|
background-color: black;
|
||||||
}
|
}
|
||||||
img {
|
img, video {
|
||||||
max-width: 100%;
|
max-width: 100%;
|
||||||
max-height: 100%;
|
max-height: 100%;
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
img.active {
|
.active {
|
||||||
display: block;
|
display: block;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
@@ -24,26 +24,43 @@
|
|||||||
<body>
|
<body>
|
||||||
<div id="content">
|
<div id="content">
|
||||||
{% for item in content %}
|
{% for item in content %}
|
||||||
<img src="{{ url_for('static', filename='uploads/' ~ item.file_name) }}" alt="Content Image" data-duration="{{ item.duration }}">
|
{% if item.file_name.endswith('.mp4') %}
|
||||||
|
<video class="content-item" data-duration="{{ item.duration }}" controls>
|
||||||
|
<source src="{{ url_for('static', filename='uploads/' ~ item.file_name) }}" type="video/mp4">
|
||||||
|
Your browser does not support the video tag.
|
||||||
|
</video>
|
||||||
|
{% else %}
|
||||||
|
<img src="{{ url_for('static', filename='uploads/' ~ item.file_name) }}" alt="Content Image" class="content-item" data-duration="{{ item.duration }}">
|
||||||
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
<script>
|
<script>
|
||||||
const images = document.querySelectorAll('#content img');
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
let index = 0;
|
const items = document.querySelectorAll('.content-item');
|
||||||
|
let currentIndex = 0;
|
||||||
|
|
||||||
function showNextImage() {
|
function showNextItem() {
|
||||||
images.forEach((img, i) => {
|
items.forEach(item => item.classList.remove('active'));
|
||||||
img.classList.toggle('active', i === index);
|
const currentItem = items[currentIndex];
|
||||||
});
|
currentItem.classList.add('active');
|
||||||
const duration = images[index].getAttribute('data-duration') * 1000;
|
|
||||||
index = (index + 1) % images.length;
|
|
||||||
setTimeout(showNextImage, duration);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (images.length > 0) {
|
const duration = parseInt(currentItem.getAttribute('data-duration'), 10) * 1000;
|
||||||
images[0].classList.add('active');
|
if (currentItem.tagName === 'VIDEO') {
|
||||||
showNextImage();
|
currentItem.play();
|
||||||
}
|
currentItem.onended = () => {
|
||||||
|
currentIndex = (currentIndex + 1) % items.length;
|
||||||
|
showNextItem();
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
setTimeout(() => {
|
||||||
|
currentIndex = (currentIndex + 1) % items.length;
|
||||||
|
showNextItem();
|
||||||
|
}, duration);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
showNextItem();
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
Reference in New Issue
Block a user