What is the best way to pull videos or images that are categorized?
Is it possible to write in values into an array ie: landscape, technology, abstract, etc.. And then when the user selects an input they are given the items that fall into the category or would I need to use PHP or JSON to write something like this effectively?
What I am trying to do is have a page that will randomize images/videos from an array. The user when visiting the page will be able to select a category from a dropdown and the randomizer will only randomize images with that category tag and display them one at a time.
If no category is selected then it will randomize from the total amount of videos.
the code I currently have is set for videos but images/videos is the same concept
<head>
<title>Randomizer</title>
</head>
<body>
<section>
<div class="desktop">
<video loop autoplay>
<source src="" type="">
<source src="" type="">
Your browser does not support the <code>video</code> element.
</video>
</div>
</section>
</body>
</html>
JavaScript
var videos = [
[{type:'mp4', 'src':'/videos/1.webm'}, {type:'webm', 'src':'/videos/1.mp4'}],
[{type:'mp4', 'src':'/videos/2.webm'}, {type:'webm', 'src':'/videos/2.mp4'}],
[{type:'mp4', 'src':'/videos/3.webm'}, {type:'webm', 'src':'/videos/3.mp4'}],
[{type:'mp4', 'src':'/videos/4.webm'}, {type:'webm', 'src':'/videos/4.mp4'}],
[{type:'mp4', 'src':'/videos/5.webm'}, {type:'webm', 'src':'/videos/5.mp4'}],
];
$(function() {
$('section').on('click', 'div', function(e) {
var number = Math.floor(Math.random()*videos.length);
$(this).find('source').each(function(index){
videoSrc = videos[number][index].src;
$(this).attr('src', videoSrc);
$('video').load();
$('video').play();
});
});
});
$(document).ready(function() {
var number = Math.floor(Math.random()*videos.length);
$(this).find('source').each(function(index){
videoSrc = videos[number][index].src;
$(this).attr('src', videoSrc);
$('video').load();
$('video').play();
});
}
);
Any help or insight is much appreciated! Thanks everyone!