Got this script and it works fine, the problem is that it show´s the video on the playlist, ive tried to visibility:hidden; and display:none; and it doesnt work, anyone knows how to hide this?
var video_player = document.getElementById("video_player");
video = video_player.getElementsByTagName("video")[0],
video_links = video_player.getElementsByTagName("figcaption")[0],
source = video.getElementsByTagName("source"),
link_list = [],
vidDir = "http://demosthenes.info/assets/videos/",
currentVid = 0,
allLnks = video_links.children,
lnkNum = allLnks.length;
video.removeAttribute("controls");
video.removeAttribute("poster");
(function() {
function playVid(index) {
video_links.children[index].classList.add("currentvid");
source[1].src = vidDir + link_list[index] + ".webm";
source[0].src = vidDir + link_list[index] + ".mp4";
currentVid = index;
video.load();
video.play();
}
for (var i = 0; i < lnkNum; i++) {
var filename = allLnks[i].href;
link_list[i] = filename.match(/([^\/]+)(?=\.\w+$)/)[0];
(function(index) {
allLnks[i].onclick = function(i) {
i.preventDefault();
for (var i = 0; i < lnkNum; i++) {
allLnks[i].classList.remove("currentvid");
}
playVid(index);
}
})(i);
}
video.addEventListener('ended', function() {
allLnks[currentVid].classList.remove("currentvid");
if ((currentVid + 1) >= lnkNum) {
nextVid = 0
} else {
nextVid = currentVid + 1
}
playVid(nextVid);
})
video.addEventListener('mouseenter', function() {
video.setAttribute("controls", "true");
})
video.addEventListener('mouseleave', function() {
video.removeAttribute("controls");
})
var indexOf = function(needle) {
if (typeof Array.prototype.indexOf === 'function') {
indexOf = Array.prototype.indexOf;
} else {
indexOf = function(needle) {
var i = -1,
index = -1;
for (i = 0; i < this.length; i++) {
if (this[i] === needle) {
index = i;
break;
}
}
return index;
};
}
return indexOf.call(this, needle);
};
var focusedLink = document.activeElement;
index = indexOf.call(allLnks, focusedLink);
document.addEventListener('keydown', function(e) {
if (index) {
var focusedElement = document.activeElement;
if (e.keyCode == 40 || e.keyCode == 39) { // down or right cursor
var nextNode = focusedElement.nextElementSibling;
if (nextNode) {
nextNode.focus();
} else {
video_links.firstElementChild.focus();
}
}
if (e.keyCode == 38 || e.keyCode == 37) { // up or left cursor
var previousNode = focusedElement.previousElementSibling;
if (previousNode) {
previousNode.focus();
} else {
video_links.lastElementChild.focus();
}
}
}
});
})();
#video_player {
display: table;
line-height: 0;
max-width: 100%;
margin: 0 auto;
}
#video_container {
position: relative;
}
#video_player div,
#video_player figcaption {
display: table-cell;
vertical-align: top;
}
#video_container video {
position: absolute;
display: block;
width: 100%;
height: 100%;
top: 0;
}
#video_player figcaption {
width: 25%;
}
#video_player figcaption a {
display: block;
}
#video_player figcaption a {
opacity: .3;
transition: 1s opacity;
}
#video_player figcaption a img,
figure video {
width: 100%;
height: 100%;
}
#video_player figcaption a.currentvid,
#video_player figcaption a:hover,
#video_player figcaption a:focus {
opacity: 1;
}
<figure id="video_player">
<div id="video_container">
<video controls poster="vid-glacier.jpg" autostart>
<source src="http://thenewcode.com/assets/videos/glacier.webm" type="video/webm" autostart>
<source src="http://thenewcode.com/assets/videos/glacier.mp4" type="video/mp4" autostart>
</video>
</div>
<figcaption>
<a href="http://thenewcode.com/assets/videos/lake.mp4" class="currentvid">
<img src="http://demosthenes.info/assets/images/vid-glacier.jpg" alt="Athabasca Glacier">
</a>
<a href="http://thenewcode.com/assets/videos/mountain.mp4">
<img src="http://demosthenes.info/assets/images/vid-glacier.jpg" alt="Athabasca Glacier">
</a>
<a href="http://thenewcode.com/assets/videos/glacier.mp4">
<img src="http://demosthenes.info/assets/images/vid-glacier.jpg" alt="Athabasca Glacier">
</a>
</figcaption>
</figure>
Thanks in advance
Okay, this CSS should work for you. I've marked all the important items. But before we get to that, lets look at what was wrong. This is what you had:
#video_container video {position: absolute; top: 0;}
#video_player figcaption {width: 25%;}
The position, and its top, code were overriding all forms of hiding the playlist. Even if #video_player figcaption was set to display: none; or visibility: hidden; this had no effect on hiding the playlist because of width: 25%;. The width was overriding the display/visibility, which we all know that display: none; should override everything. But the width was still visible because position: absolute; from #video_container video said "I don't care what everything else says, you're staying put". These things have been fixed. The correct CSS to use is below.
#video_player {display: table;
margin: auto;
background: #000000;
width: 500px; /*The space you want occupied.*/
}
#video_container {position: relative;}
#video_player div, #video_player figcaption {display: table-cell; vertical-align: top;}
#video_container video {display: block;
width: 100%; /*How big you want the video to be.*/
height: ---; /*Whatever you want*/
/*width: 350px;*/ /*Use with visible playlist.*/
/*height: 100%;*/ /*Use with visible playlist.*/
}
#video_player figcaption {display: none; /*Hides the playlist from view.*/
}
#video_player figcaption a {display: block; opacity: .3; transition: 1s opacity;}
#video_player figcaption a img {width: 100%;}
#video_player figcaption a.currentvid, #video_player figcaption a:hover, #video_player figcaption a:focus {opacity: 1;}
New Post: To hide the current video, look at #video_player figcaption a.currentvid ... a:focus. Change opacity: 1; to opacity: 0;, add visibility: hidden; (which will hide the area, but not remove the space that it occupies), or add display: none; (which is the best solution). If you want to have the playlist appear on several pages, then make sure to place class="currentvid" in the correct <a> each time.
Old Post: You need to add display: none; or display: none !important; to #video_container. The problem is that you might. To have display: none; work correctly, move #video_container below #video_container video. If you want everything to stay where it is, then use display: none !important;` which will override everything else and hide your video.
#video_container {
position: relative;
display: none !important;
}
Related
this code changes the background of the div every time a button is pressed but the new background is supposed to fade in so I set an animation. If you press red, and then another color, it makes the transition the first time, but not from the second on. The background will just appear without animation.
function changit(color) {
document.getElementById('cont').classList = color;
}
#keyframes appear {
0% {opacity:0;}
100% {opacity:1;}
}
#cont {
position: relative;
width: 100px;
height: 100px;
display: block;
}
#cont::before {
width: 93%;
height: 100%;
position: sticky;
content: "";
display: block;
}
.red::before, .blue::before, .black::before { transition: opacity 2s ease;animation:appear 2s; }
.red::before {
background: url(https://cdn.sstatic.net/Img/teams/teams-illo-free-sidebar-promo.svg) no-repeat;
}
.blue::before {
background: url(https://www.gravatar.com/avatar/24780fb6df85a943c7aea0402c843737?s=64&d=identicon&r=PG) no-repeat;
}
.black::before {
background:url(https://cdn.sstatic.net/Sites/stackoverflow/Img/subcommunities/intel.svg?v=0371bf2f3b96) no-repeat;
}
<div id="cont">
</div>
<button onclick="changit('red');">make red</button>
<button onclick="changit('blue');">make blue</button>
<button onclick="changit('black');">make black</button>
isnt the animation supposed to play again if the element changes class? How can I reset the animation to start again every time the element changes class to achieve this effect?
The animation property value actually never changes, with all the classes it's always the same and there is no point in time where it's unset, so it won't fire again.
You need to force the CSS engine sees that it did change. For this you can remove the class altogether force what is called a "reflow", which is when the CSS engine recalculates all the element's boxes in the page, and then only, set the class back:
function changit(color) {
const elem = document.getElementById('cont');
elem.classList = "";
elem.offsetWidth; // force reflow
elem.classList = color;
}
function changit(color) {
const elem = document.getElementById('cont');
elem.classList = "";
elem.offsetWidth; // force reflow
elem.classList = color;
}
#keyframes appear {
0% {opacity:0;}
100% {opacity:1;}
}
#cont {
position: relative;
width: 100px;
height: 100px;
display: block;
}
#cont::before {
width: 93%;
height: 100%;
position: sticky;
content: "";
display: block;
}
.red::before, .blue::before, .black::before { transition: opacity 2s ease;animation:appear 2s; }
.red::before {
background: url(https://cdn.sstatic.net/Img/teams/teams-illo-free-sidebar-promo.svg) no-repeat;
}
.blue::before {
background: url(https://www.gravatar.com/avatar/24780fb6df85a943c7aea0402c843737?s=64&d=identicon&r=PG) no-repeat;
}
.black::before {
background:url(https://cdn.sstatic.net/Sites/stackoverflow/Img/subcommunities/intel.svg?v=0371bf2f3b96) no-repeat;
}
<div id="cont">
</div>
<button onclick="changit('red');">make red</button>
<button onclick="changit('blue');">make blue</button>
<button onclick="changit('black');">make black</button>
Or, since you're using JS anyway, use the WebAnimations API:
function changit(color) {
const elem = document.getElementById('cont');
elem.classList = color;
elem.animate(
[ { opacity: 0 }, { opacity: 1 } ],
{ duration: 2000, repeat: 1 }
);
}
function changit(color) {
const elem = document.getElementById('cont');
elem.classList = color;
elem.animate(
[ { opacity: 0 }, { opacity: 1 } ],
{ duration: 2000, repeat: 1 }
);
}
#cont {
position: relative;
width: 100px;
height: 100px;
display: block;
}
#cont::before {
width: 93%;
height: 100%;
position: sticky;
content: "";
display: block;
}
.red::before {
background: url(https://cdn.sstatic.net/Img/teams/teams-illo-free-sidebar-promo.svg) no-repeat;
}
.blue::before {
background: url(https://www.gravatar.com/avatar/24780fb6df85a943c7aea0402c843737?s=64&d=identicon&r=PG) no-repeat;
}
.black::before {
background:url(https://cdn.sstatic.net/Sites/stackoverflow/Img/subcommunities/intel.svg?v=0371bf2f3b96) no-repeat;
}
<div id="cont">
</div>
<button onclick="changit('red');">make red</button>
<button onclick="changit('blue');">make blue</button>
<button onclick="changit('black');">make black</button>
I would like my scroll to work like this when the user scrolls. e.g to start to fill up instead of moving.
Is it possible to make the scroll-thumb grow or to style the scrollbar-track-piece different before and after the thumb?
Here is a small example how to implement this loader
window.addEventListener("scroll", (e) => {
var html = document.documentElement;
let step = 100 / (html.scrollHeight - window.innerHeight);
let loader = document.getElementById("scrollprogress");
loader.style.width = (step * html.scrollTop) + "%";
})
#scrollprogress {
height: 5px;
position: fixed;
left: 0;
top: 0;
background: orange;
}
.backgr {
position: fixed;
left: 0;
top: 0;
width: 100vw;
height: 5px;
background: lightgrey;
z-index: -1;
}
.box {
height: 3000px;
}
<div id="scrollprogress"></div>
<div class="backgr"></div>
<div class="box"></div>
You can approximate this using negative box shadow:
body::-webkit-scrollbar {
width: 1em;
}
body::-webkit-scrollbar-thumb {
background-color: orange;
box-shadow:-1000vmax -1000vmax 0px 1000vmax orange;
}
body {
width:300vw;
height:300vh;
background:linear-gradient(60deg,red,blue,orange);
margin:0;
}
html {
background:#fff;
}
I want an overlay of the whole screen except the form so people can focus on it.
This solution would be ideal, but the form won't change back.
body {
opacity: .4
}
.form:focus {
opacity: 1 /* crap, doesn't work */
}
This doesn't really work
some-element {
background: rgba(0, 0, 0, .4)
}
You can use a bit of javascript to select and interact with the parent of your inputs, as well as the overlay. You can toggle active class so you can manage your CSS with actual CSS, which I find cleaner.
$(document).ready(function() {
var overlay = $('#overlay');
$('input').focusin(function(){
$(this).parent().addClass('active');
overlay.addClass('active');
});
$('input').focusout(function(){
$(this).parent().removeClass('active');
overlay.removeClass('active');
});
});
form {
position: relative;
background-color: white;
padding: 20px;
}
form.active {
z-index: 100;
}
#overlay {
position: absolute;
top: 0; left: 0;
width: 100%;
height: 100%;
display: none;
z-index: 0;
background-color: rgba(0,0,0,0.5);
}
#overlay.active {
display: block;
z-index: 10;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<body>
<form>
<input type="text" name="" value="">
</form>
<div id="overlay"></div>
</body>
Not sure whether it is chrome specific bug or what, but when I am transitioning child element on a parent that has overflow hidden with border radius, the overflow is visible, while the transition is in place.
var wrapper = document.getElementsByClassName('wrapper')[0],
img = document.getElementsByTagName('img')[0];
/*
Click anywhere in the bordered area to toggle img
*/
wrapper.addEventListener('click', function() {
if (!img.className) {
img.className = 'hidden';
} else {
img.className = '';
}
}, false);
.wrapper {
overflow: hidden;
border-radius: 60px;
border: 1px solid salmon;
}
img {
width: 100%;
height: auto;
opacity: 1;
transition: opacity 1s ease;
}
.hidden {
opacity: 0;
}
<div class="wrapper">
<img src="http://static.planetminecraft.com/files/resource_media/screenshot/1211/y-you-no-work_1687402.jpg">
</div>
Here's a fiddle demonstrating the issue https://jsfiddle.net/827vuyqb/2/
Any solutions, workarounds for this?
Just position the wrapper element, and give it a z-index:
var wrapper = document.getElementsByClassName('wrapper')[0],
img = document.getElementsByTagName('img')[0];
/*
Click anywhere in the bordered area to toggle img
*/
wrapper.addEventListener('click', function() {
if (!img.className) {
img.className = 'hidden';
} else {
img.className = '';
}
}, false);
.wrapper {
overflow: hidden;
border-radius: 60px;
border: 1px solid salmon;
/*Position and z-index*/
position: relative;
z-index: 1;
}
img {
width: 100%;
height: auto;
opacity: 1;
transition: opacity 1s ease;
}
.hidden {
opacity: 0;
}
<div class="wrapper">
<img src="http://static.planetminecraft.com/files/resource_media/screenshot/1211/y-you-no-work_1687402.jpg">
</div>
I have a container div with an image inside of it. When a user clicks the image, I want it to grow to fill the viewport width. This works for me, but I want it to animate smoothly as it grows, which does not.
How can I make the image grow smoothly from the centre of the page, rather than growing in situ until it touches the right edge of the viewport, and then jumping to the left and continuing until it fills the viewport?
Here's an example
(you can try it on codepen):
HTML:
<div>
<img id="expandableImage" src="https://placekitten.com/g/500/200">
</div>
CSS:
div {
width: 50%;
margin: 0 auto;
}
img {
width: 100%;
cursor: pointer;
position: relative;
}
.fullsize {
animation-duration: 1s;
animation-name: zoom-in;
animation-fill-mode: forwards;
}
.smallsize {
animation-duration: 1s;
animation-name: zoom-out;
}
#keyframes zoom-in {
to {
width: 100vw;
position: relative;
left: calc(-50vw + 50%);
}
}
#keyframes zoom-out {
to {
width: 100%;
}
from {
width: 100vw;
position: relative;
left: calc(-50vw + 50%);
}
}
JS:
document.getElementById( "expandableImage" ).addEventListener( "click", zoom );
function zoom() {
if (this.className.indexOf("fullsize") > -1) {
this.className = this.className.replace(" fullsize", "");
this.className = this.className + " smallsize";
} else {
this.className = this.className.replace(" smallsize", "");
this.className = this.className + " fullsize";
}
}
You don't need #keyframes for that, only with transition is enough.
http://jsfiddle.net/xnmojeyn/
document.getElementById("expandableImage").addEventListener("click", zoom);
function zoom() {
if (this.className.indexOf("fullsize") > -1) {
this.className = this.className.replace(" fullsize", "");
this.className = this.className + " smallsize";
} else {
this.className = this.className.replace(" smallsize", "");
this.className = this.className + " fullsize";
}
}
body, p {
margin: 0;
}
div {
width: 50vw;
height: 100vh;
margin: 0 auto;
background-color: lightblue;
}
img {
width: 100%;
cursor: pointer;
}
.fullsize {
transition: all 1s;
margin-left: -25vw;
width: 100vw;
}
.smallsize {
transition: all 1s;
width: 100%;
}
<div>
<p>asdf</p>
<img id="expandableImage" src="https://placekitten.com/g/500/200" />
<p>Why it doesn't work</p>
</div>
Is this what you are looking for?
http://codepen.io/anon/pen/ZGLKwB
img {
width: 100%;
cursor: pointer;
position: relative;
transform:translateX(-50%);
left:50%;
}
Issue with calc
#keyframes zoom-in {
to {
width: 100vw;
position: relative;
left: calc(-50% + 50%);
}
}
#keyframes zoom-out {
to {
width: 100%;
}
from {
width: 100vw;
position: relative;
left: calc(-50% + 50%);
}
}
http://jsbin.com/paxuketigu/2/
another example with float:left
http://jsbin.com/paxuketigu/3/