2
I have this code, it shows 1 video when clicking on a table.
Is it possible to change the color of the element that was clicked in the same way as with links? but with CSS?
Example: video 1 color red, after being clicked this option turn gray.
<div class="videoGallery">
<ul>
<li>01 </li>
<li><span class="ytVideo" data-videoid="UGPuEDyAsU8">Opção 1</span> </li>
<li><span class="uolVideo" data-videoid="16060482">Opção 2</span></li>
<li><span class="close">Fechar</span></li>
</ul>
</div>
<div class="videoGallery">
<ul>
<li> 02</li>
<li><span class="ytVideo" data-videoid="nuzDvYdC_Ak">Opção 1</span></li>
<li><span class="uolVideo" data-videoid="16041619">Opção 2</span></li>
<li><span class="close">Fechar</span></li>
</ul>
</div>
<div class="videoGallery">
<ul>
<li> 03</li>
<li><span class="ytVideo" data-videoid="pFUMPnqnN2E">Opção 1</span> </li>
<li><span class="uolVideo" data-videoid="16026675">Opção 2</span></li>
<li><span class="close">Fechar</span></li>
</ul>
</div>
<style>
.videoGallery {margin-bottom:5px;}
.videoGallery ul {
list-style: none;
margin: 0;
padding: 0;
font-family: sans-serif;
}
.meuVideo {
display: inline-block;
background-color: Black;
color: #fff;
padding: 0px 3px;
border: 0px solid steelblue;
}
.videoGallery li {
display: inline-block;
background-color: #A52A2A;
color: #fff;
padding: 4px 10px;
border: 1px solid Black;
}
.videoGallery li:first-child,
.videoGallery li:last-child {background-color:initial; color:#0000; background-color: Black;}
.videoGallery span {cursor: pointer;}
i.nowPlaying {
font-size: 13px;
background: Black;
margin-left: 15px;
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<script type="text/javascript">
var ytVideo = $('.videoGallery .ytVideo');
var dailyMvideo = $('.videoGallery .dailyMvideo');
var uolVideo = $('.videoGallery .uolVideo');
var html5bgvideo = $('.videoGallery .html5bgvideo');
var liHeight = $('.videoGallery li').height();
// Youtube Video
ytVideo.click(function(){
var videoID = $(this).attr('data-videoID');
var videos = $('<div class="meuVideo"> <iframe width="560" height="315" src="https://www.youtube.com/embed/'+ videoID +'?autoplay=1" frameborder="0" allowfullscreen></iframe> </div>');
$('.meuVideo, .nowPlaying').remove();
$(this).parents().eq(2).append(videos);
$('<i class="nowPlaying">▼ Reproduzindo ...</i>').insertAfter(this);
});
// UOL Video
uolVideo.click(function(){
var videoID = $(this).attr('data-videoID');
var videos = $('<div class="meuVideo"> <video width="100%" controls="controls" autoplay="true" src="http://video25.mais.uol.com.br/'+ videoID +'.mp4?r=http://player.mais.uol.com.br" type="video/mp4"" frameborder="0" allowfullscreen></video> </div>');
$('.meuVideo, .nowPlaying').remove();
$(this).parents().eq(2).append(videos);
$('<i class="nowPlaying">▼ Reproduzindo ...</i>').insertAfter(this);
});
// Fechar Videos
$('.close').click(function(){
$('.meuVideo, .nowPlaying').remove();
});
</script>
Thanks Sergio, but this option you showed, it is recorded in the browser ? like when we already clicked on some link and we already know that we visited them because it is of another color?
– Endou
@Endou is recorded until he navigates to another page, then he forgets. If you want it to remember the user you have to leave a cookie, localstorage or talk to the server if the user is logged in.
– Sergio
There would be no way to use Css :visited or :target ?
– Endou
@You want the browser to know that the click happened even after returning to the page?
– Sergio
Yes, that’s what I need.
– Endou
@How do you generate this HTML? is on the server with some loop from organized data?
– Sergio
It is an HTML page, simple done on 1 Wordpress site.
– Endou
The most appropriate option would be the browser to save the data, as it does on an html page with links.
– Endou
@Endou edited with a solution that "has memory"
– Sergio
Thanks Sergio, I’ll do some tests here, now it’s great
– Endou
Sergio, you could take a look here https://jsfiddle.net/r4L6f3p2/1/ I couldn’t make it work. I don’t know where the bug is, but the code is the same as yours, but it’s not working
– Endou
@Endou in my cache/localStorage had links that don’t exist yet. I added an extra check: https://jsfiddle.net/r4L6f3p2/2/
– Sergio