I have a div and I want to apply animation to it.
When Clicked on hamburger icon
When I click on the hamburger menu, it should appear from left to right and it does correctly.
Here it appears like this, with left to right animation
When clicked on left icon
Now When after it appears to the screen, when I click to the leftIcon, it should disappear from right to left.
However, I manage to make the first animation appearing from left to right but I don't know how to add another animation to the same div when the left Icon is pressed.
Code
import React, { useState } from "react";
import { FaBars, FaArrowLeft } from "react-icons/fa";
import "./Sidebar.css";
function Sidebar() {
const [sidebar, setSidebar] = useState(false);
const showHideSidebar = () => {
return setSidebar(!sidebar);
};
return (
<div className="side__bar">
<div className="top__side__bar">
<div className="the__icon" onClick={showHideSidebar}>
<FaBars></FaBars>
</div>
<div className="the__bar__title">DASA</div>
</div>
{sidebar ? (
<div>
<TheSideBar></TheSideBar>
</div>
) : (
<></>
)}
</div>
);
function TheSideBar() {
return (
<div className="the__side__bar">
<div className="left__side__bar">
<div className="the__bar__title">DASA</div>
<div className="the__icon">
<FaArrowLeft onClick={showHideSidebar}></FaArrowLeft>
</div>
</div>
</div>
);
}
}
export default Sidebar;
css
.the__side__bar {
height: 100vh;
-webkit-box-shadow: 0 0 10px rgb(187, 183, 183);
box-shadow: 0 0 10px rgb(187, 183, 183);
width: 300px;
background-color: white;
position: absolute;
animation: mymove 1s;
animation-direction: alternate;
top: 0;
left: 0;
}
#keyframes mymove {
from {
left: -300px;
}
to {
left: 0px;
}
}
How to do that?
You can Add Class with body then you can control sidebar part using css.
const openMenu = () => {
document.body.classList.toggle('sidebar-open');
};
const closeMenu = () => {
document.body.classList.toggle('sidebar-open');
};
CSS
.sidebar {
position: fixed;
width: 300px;
background-color: white;
left: -100%;
top: 0px;
bottom: 0px;
transition: 0.3s ease-in-out 0s;
overflow: auto;
z-index: 9999;
}
.sidebar-open .sidebar {left: 0px;}
When you click on the menu menu items only change the css class.
function toggleMenu() {
$('.spanPos1').toggleClass('rotA45Top');
$('.spanPos3').toggleClass('rotA45Bottom');
$('.sideMenu').toggleClass('showMenu');
$('.btnMenu').toggleClass('btnMenu_Move');
}
* {
padding: 0;
margin: 0;
}
.header {
width: 100%;
background-color: #DDD;
padding: 10px;
}
.sideMenu {
height: 100vh;
-webkit-box-shadow: 0 0 10px rgb(187, 183, 183);
box-shadow: 0 0 10px rgb(187, 183, 183);
width: 300px;
background-color: white;
position: absolute;
transition: all .5s;
top: 0;
left: -300px;
}
.spanLine {
height: 3px;
background-color: #000;
width: 30px;
position: absolute;
transition: all .5s;
}
.spanPos1 {
top: 0px;
left: 0px;
}
.spanPos2 {
top: 10px;
left: 0px;
}
.spanPos3 {
top: 20px;
left: 0px;
}
.btnMenu {
position: relative;
width: 30px;
height: 24px;
background: transparent;
border: none;
transition: all .5s;
}
.rotA45Top {
margin-top: 3px;
transform: rotate(-45deg);
width: 20px;
left: -5px;
}
.rotA45Bottom {
margin-top: -3px;
transform: rotate(45deg);
width: 20px;
left: -5px;
}
.showMenu {
left: 0;
}
.btnMenu_Move {
z-index: 2;
margin-left: 250px;
}
<div class="header">
<div class="btnMenu" onclick="toggleMenu()">
<span class="spanLine spanPos1"></span>
<span class="spanLine spanPos2"></span>
<span class="spanLine spanPos3"></span>
</div>
</div>
<div class="sideMenu"></div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
Related
I have to create a progress bar that has to be fully responsive. In order to be responsive I don't want the progress bar class to have a fixed width, but when I put auto in width, line of progress bar is detached from the star also if I give to them auto width
Fixed width: look good
Width auto
First how can I fix this issue, and perhaps someone can help me achieve this progress bar to be responsive on mobile also so that the line of progress bar will be vertical.
.progress-bar {
width: 750px;
display: flex;
margin: 40px 0;
}
.progress-bar .step {
text-align: center;
width: 100%;
}
.progress-bar .step .bullet {
position: relative;
height: 25px;
width: 25px;
display: inline-block;
}
.progress-bar .step:last-child .bullet:before,
.progress-bar .step:last-child .bullet::after {
display: none;
}
.progress-bar .step .bullet:before,
.progress-bar .step .bullet::after {
position: absolute;
content: "";
height: 3px;
right: -136px;
bottom: 11px;
width: 142px;
background: #C1C1C1;
}
.active-bullet {
z-index: 1;
}
.active-check {
z-index: 2;
}
<div class="progress-bar">
<div class="step">
<div class="bullet active-bullet">
<img src="star-pb-active.svg">
</div>
<div class="check active-check" style="
border-bottom: 2px solid black;
padding: 2px;
DISPLAY: table-cell;
LEFT: 40px;
POSITION: relative;
">Order placed</div>
</div>
<div class="step">
<div class="bullet">
<img src="star-pb.svg">
</div>
<div class="check">Jewerly Creation</div>
</div>
<div class="step">
<div class="bullet">
<img src="star-pb.svg">
</div>
<div class="check">Packing & Quality Control</div>
</div>
<div class="step">
<div class="bullet">
<img src="star-pb.svg">
</div>
<div class="check">Shipped</div>
</div>
<div class="step">
<div class="bullet">
<img src="star-pb.svg">
</div>
<div class="check">Estimated Delivery</div>
</div>
</div>
You should try taking a look at the flex-grow property from Flexbox.
By giving display: flex to the parent, and flex-grow: 1 to the children, you should be able to make every step be the same size and take all the width of their container.
It works the way you want, in fixed or auto width.
.progress-bar {
width: auto;
display: flex;
margin: 40px 0;
}
.progress-bar .step {
text-align: center;
position: relative;
isolation: isolate;
width: 100%;
}
.progress-bar .step::after {
content: "";
position: absolute;
z-index: -1;
height: 3px;
top: 12px; /* 1/2 of .bullet's height */
width: 100%;
background: #C1C1C1;
}
.progress-bar .step:last-child::after {
display: none;
}
.progress-bar .step .bullet {
position: relative;
height: 25px;
width: 25px;
display: inline-block;
}
.active-bullet {
z-index: 1;
}
.active-check {
z-index: 2;
}
Added pseudo element on the parent of .bullet.
Also you don't need ::before, one of those pseudo elements was enough.
try below code, your code some confusion.
use flex in css
below sample add one button which goes your activity to next step
it is fully responsive - on desktop this code horizontal and on mobile this code show vertical progressbar.
just use small js, css and for tick icon font awesome js.
if any query comment it.
let step = 'step1';
const step1 = document.getElementById('step1');
const step2 = document.getElementById('step2');
const step3 = document.getElementById('step3');
const step4 = document.getElementById('step4');
function next() {
if (step === 'step1') {
step = 'step2';
step1.classList.remove("is-active");
step1.classList.add("is-complete");
step2.classList.add("is-active");
} else if (step === 'step2') {
step = 'step3';
step2.classList.remove("is-active");
step2.classList.add("is-complete");
step3.classList.add("is-active");
} else if (step === 'step3') {
step = 'step4d';
step3.classList.remove("is-active");
step3.classList.add("is-complete");
step4.classList.add("is-active");
} else if (step === 'step4d') {
step = 'complete';
step4.classList.remove("is-active");
step4.classList.add("is-complete");
} else if (step === 'complete') {
step = 'step1';
step4.classList.remove("is-complete");
step3.classList.remove("is-complete");
step2.classList.remove("is-complete");
step1.classList.remove("is-complete");
step1.classList.add("is-active");
}
}
.progress-bar {
position: relative;
display: flex;
}
.progress-bar .progress-track {
position: absolute;
top: 5px;
width: 100%;
height: 5px;
background-color: #dfe3e4;
z-index: -1;
}
.progress-bar .progress-step {
position: relative;
width: 100%;
font-size: 12px;
text-align: center;
}
.progress-bar .progress-step:last-child:after {
display: none;
}
.progress-bar .progress-step:before {
content: "\f00c";
display: flex;
margin: 0 auto;
margin-bottom: 10px;
width: 10px;
height: 10px;
background: #fff;
border: 4px solid #dfe3e4;
border-radius: 100%;
color: transparent;
}
.progress-bar .progress-step:after {
content: "";
position: absolute;
top: 6px;
left: 50%;
width: 0%;
transition: width 1s ease-in;
height: 5px;
background: #dfe3e4;
z-index: -1;
}
#media screen and (max-width:700px) {
.progress-bar {
position: relative;
display: inline-block;
}
.progress-bar .progress-track {
position: absolute;
top: -10px;
width: 100%;
height: 5px;
background-color: #dfe3e4;
z-index: -1;
transform: rotate(90deg);
}
.progress-bar .progress-step {
position: relative;
width: 100%;
font-size: 12px;
text-align: center;
}
.progress-bar .progress-step:last-child:after {
display: none;
}
.progrestext
{
left: 44px;
position: absolute;
top: 0px;
}
.progress-bar .progress-step:after {
content: "";
position: absolute;
top: 20px;
left: 0%;
width: 0%;
transition: width 1s ease-in;
height: 5px;
background: #dfe3e4;
z-index: -1;
transform: rotate(90deg);
}
}
.progress-bar .progress-step.is-active {
color: #2183dd;
}
.progress-bar .progress-step.is-active:before {
border: 4px solid #777;
animation: pulse 2s infinite;
}
.progress-bar .progress-step.is-complete {
color: #009900;
}
.progress-bar .progress-step.is-complete:before {
font-family: FontAwesome;
font-size: 10px;
color: #fff;
background: #009900;
border: 4px solid transparent;
}
.progress-bar .progress-step.is-complete:after {
background: #2183dd;
animation: nextStep 1s;
animation-fill-mode: forwards;
}
#keyframes pulse {
0% {
box-shadow: 0 0 0 0 rgba(33, 131, 221, 0.8);
}
70% {
box-shadow: 0 0 0 10px rgba(33, 131, 221, 0);
}
100% {
box-shadow: 0 0 0 0 rgba(33, 131, 221, 0);
}
}
#keyframes nextStep {
0% {
width: 0%;
}
100% {
width: 100%;
}
}
.container {
margin: 50px 100px;
}
button {
position: absolute;
right: 50px;
bottom: 20px;
cursor: pointer;
}
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://use.fontawesome.com/c47bc38e87.js"></script>
<div class="container">
<div class="progress-bar">
<div class="progress-track"></div>
<div id="step1" class="progress-step">
<div class="progrestext">placed</div>
</div>
<div id="step2" class="progress-step">
<div class="progrestext">Creation</div>
</div>
<div id="step3" class="progress-step">
<div class="progrestext">Packing</div>
</div>
<div id="step4" class="progress-step">
<div class="progrestext">Delivered</div>
</div>
</div>
<button onClick=next()>Next Step</button>
</div>
I have seen some site using an effect for line of text loading. I have searched a lot but unable to find what is called.
Effect:
Does any plugin or css file for this effect like bootstrap.
I know this question is kind of silly but i have no idea where to ask this question i have search about where to ask question Html/CSS.
This is close to something you want. It's done only with CSS/HTML and you can easily customize it for your taste
https://jsfiddle.net/hau122w8/
<div class="timeline-item">
<div class="animated-background">
<div class="background-masker content-first"></div>
<div class="background-masker content-top"></div>
<div class="background-masker content-first-end"></div>
<div class="background-masker content-second-line"></div>
<div class="background-masker content-second-end"></div>
<div class="background-masker content-third-line"></div>
<div class="background-masker content-third-end"></div>
</div>
</div>
.timeline-item {
background-color: #fff;
border: 1px solid;
border-color: #ddd;
border-radius: 3px;
padding: 12px;
margin: 0 auto;
}
#keyframes placeHolderShimmer {
0% {
background-position: 0 0;
}
100% {
background-position: 10000px 0;
}
}
.animated-background {
animation-duration: 10s;
animation-fill-mode: forwards;
animation-iteration-count: infinite;
animation-timing-function: linear;
animation-name: placeHolderShimmer;
background: #f6f7f8;
background: linear-gradient(to right, #eeeeee 8%, #aacfde 18%, #eeeeee 33%);
height: 96px;
position: relative;
}
.background-masker {
background: #fff;
position: absolute;
}
/* Every thing below this is just positioning */
.background-masker.content-top,
.background-masker.content-second-line,
.background-masker.content-third-line,
.background-masker.content-second-end,
.background-masker.content-third-end,
.background-masker.content-first-end {
top: 40px;
left: 0;
right: 0;
height: 6px;
}
.background-masker.content-first {
height: 10px;
top: 15px;
left: 0;
right: 0;
}
.background-masker.content-top {
height: 20px;
}
.background-masker.content-first-end,
.background-masker.content-second-end,
.background-masker.content-third-end {
width: auto;
left: 380px;
right: 0;
top: 60px;
height: 8px;
}
.background-masker.content-second-line {
top: 68px;
}
.background-masker.content-second-end {
left: 420px;
top: 74px;
}
.background-masker.content-third-line {
top: 82px;
}
.background-masker.content-third-end {
left: 300px;
top: 88px;
}
I am building this simple form (took the code from here https://codepen.io/JeromeRenders/pen/EPNxPv ) but the bullet points end up being duplicated on my page. How come? Here following is the html for the form and the css I am using. Thank you. I also added JS because that is what is creating the li list.
body fieldset {
box-shadow: 0 8px 10px #29a329;
}
body.error {
background: #f04000;
}
body.error fieldset {
box-shadow: 0 8px 10px #bd3200;
}
ul.items {
position: absolute;
width: 30px;
height: auto;
top: 50%;
left: -60px;
transform: translateY(-50%);
}
ul.items li {
width: 8px;
height: 8px;
margin: 10px 0;
background: white;
border-radius: 50%;
opacity: 0.4;
cursor: pointer;
}
ul.items li.active {
opacity: 1;
}
form {
position: relative;
width: 300px;
height: 60px;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
form fieldset {
position: absolute;
width: 300px;
height: 60px;
background: white;
border-radius: 3px;
opacity: 0;
transform: scale(0.2);
transition: all 0.4s ease-in-out;
}
form fieldset input,
form fieldset p {
display: inline-block;
width: 200px;
margin-left: 50px;
color: #333333;
font-size: 16px;
letter-spacing: 1px;
}
form fieldset p {
margin-top: 22px;
text-align: center;
}
form fieldset input {
height: 40px;
margin-top: 8px;
border: none;
outline: none;
}
body.error fieldset {
transform-origin: 50% 100%;
animation: error 0.3s ease-out;
}
<form>
<ul class="items"></ul>
<fieldset class="username enable">
<div class="icon left"><i class="user"></i></div>
<input type="text" name="username" placeholder="Username" />
<div class="icon right button"><i class="arrow"></i></div>
</fieldset>
<fieldset class="email">
<div class="icon left"><i class="letter"></i></div>
<input type="mail" name="email" placeholder="Email" />
<div class="icon right button"><i class="arrow"></i></div>
</fieldset>
<fieldset class="thanks">
<div class="icon left"></div>
<p>Thanks for your time</p>
<div class="icon right"></div>
</fieldset>
</form>
JS
function init() {
// Generate li foreach fieldset
for (var i = 0; i < count; i++) {
var ul = document.querySelector('ul.items'),
li = document.createElement("li");
ul.appendChild(li);
}
// Add class active on first li
ul.firstChild.classList.add('active');
}
Here is an image of what I get:
Duplicated bullet points
Below code useful for that:
css:
body {
background: #33cc33;
font-family: sans-serif;
}
body fieldset {
box-shadow: 0 8px 10px #29a329;
}
body.error {
background: #f04000;
}
body.error fieldset {
box-shadow: 0 8px 10px #bd3200;
}
h1, h2 {
position: absolute;
left: 50%;
transform: translateX(-50%);
font-family: sans-serif;
text-transform: uppercase;
letter-spacing: 2px;
}
h1 {
top: 24px;
color: white;
font-size: 12px;
}
h2 {
top: 44px;
color: white;
font-size: 10px;
opacity: 0.7;
}
ul.items {
position: absolute;
width: 30px;
height: auto;
top: 50%;
left: -60px;
transform: translateY(-50%);
}
ul.items li {
width: 8px;
height: 8px;
margin: 10px 0;
background: white;
border-radius: 50%;
opacity: 0.4;
cursor: pointer;
}
ul.items li.active {
opacity: 1;
}
form {
position: absolute;
width: 300px;
height: 60px;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
form fieldset {
position: absolute;
width: 300px;
height: 60px;
background: white;
border-radius: 3px;
opacity: 0;
transform: scale(0.2);
transition: all 0.4s ease-in-out;
}
form fieldset input, form fieldset p {
display: inline-block;
width: 200px;
margin-left: 50px;
color: #333333;
font-size: 16px;
letter-spacing: 1px;
}
form fieldset p {
margin-top: 22px;
text-align: center;
}
form fieldset input {
height: 40px;
margin-top: 8px;
border: none;
outline: none;
}
form fieldset .icon {
position: absolute;
width: 30px;
height: 30px;
top: 15px;
transition: all 0.4s ease;
}
form fieldset .icon i {
position: absolute;
display: block;
}
form fieldset .icon i::before, form fieldset .icon i::after {
position: absolute;
content: "";
}
form fieldset .icon.left {
left: 10px;
}
form fieldset .icon.right {
right: 10px;
cursor: pointer;
}
form fieldset .icon.button:hover {
background: #f2f2f2;
border-radius: 3px;
transition: all 0.4s ease;
}
form fieldset.enable {
z-index: 1;
opacity: 1;
transition: all 0.5s ease-out 0.2s;
transform: scale(1);
animation: enable 0.5s ease-out 0.2s;
}
form fieldset.disable {
opacity: 0;
transition: all 0.3s ease-in;
transform: translateY(120px) scale(0.9);
}
body.error fieldset {
transform-origin: 50% 100%;
animation: error 0.3s ease-out;
}
#keyframes enable {
0% {
opacity: 0;
transform: scale(0.2);
}
60% {
transform: scale(1.1);
}
100% {
opacity: 1;
transform: scale(1);
}
}
#keyframes error {
0%, 50%, 100% {
transform: rotate(0deg);
}
25% {
transform: rotate(-3deg);
}
75% {
transform: rotate(3deg);
}
}
/**
* Icons in CSS, long as f****
*/
.icon .arrow {
width: 2px;
height: 17px;
top: 5px;
left: 14px;
background: #333333;
}
.icon .arrow::before {
width: 6px;
height: 6px;
bottom: -1px;
left: -3px;
border-color: #333333;
border-right: 2px solid;
border-bottom: 2px solid;
transform: rotate(45deg);
}
.icon .user {
width: 20px;
height: 10px;
bottom: 5px;
left: 5px;
box-shadow: 0 0 0 2px #333333 inset;
border-radius: 6px 6px 3px 3px;
}
.icon .user::before {
width: 10px;
height: 10px;
top: -9px;
left: 5px;
box-shadow: 0 0 0 2px #333333 inset;
border-radius: 50%;
}
.icon .letter {
width: 20px;
height: 12px;
top: 9px;
left: 5px;
box-shadow: 0 0 0 2px #333333 inset;
border-radius: 3px;
}
.icon .letter::before, .icon .letter::after {
width: 11px;
height: 2px;
top: 4px;
background: #333333;
}
.icon .letter::before {
left: 0;
transform: rotate(30deg);
}
.icon .letter::after {
right: 0;
transform: rotate(-30deg);
}
.icon .lock {
width: 20px;
height: 16px;
top: 9px;
left: 5px;
box-shadow: 0 0 0 2px #333333 inset;
border-radius: 3px;
}
.icon .lock::before {
width: 8px;
height: 8px;
top: -4px;
left: 4px;
border: 2px solid transparent;
border-top: 2px solid #333333;
border-right: 2px solid #333333;
border-radius: 50%;
transform: rotate(-45deg);
}
.icon .lock::after {
width: 6px;
height: 7px;
top: 4px;
left: 7px;
box-shadow: 0 0 0 2px #333333 inset;
}
.icon .heart {
width: 10px;
height: 10px;
top: 11px;
left: 7px;
background: #ff5233;
transform: rotate(45deg);
}
.icon .heart::before, .icon .heart::after {
width: 10px;
height: 10px;
border-radius: 50%;
background: #ff5233;
}
.icon .heart::before {
left: -6px;
}
.icon .heart::after {
top: -6px;
}
HTML:
<form>
<ul class="items"><li class="active"></li><li></li><li></li><li></li></ul>
<fieldset class="username enable">
<div class="icon left"><i class="user"></i></div>
<input type="text" name="username" placeholder="Username"/>
<div class="icon right button"><i class="arrow"></i></div>
</fieldset>
<fieldset class="email">
<div class="icon left"><i class="letter"></i></div>
<input type="mail" name="email" placeholder="Email"/>
<div class="icon right button"><i class="arrow"></i></div>
</fieldset>
<fieldset class="password">
<div class="icon left"><i class="lock"></i></div>
<input type="password" name="password" placeholder="Password"/>
<div class="icon right button"><i class="arrow"></i></div>
</fieldset>
<fieldset class="thanks">
<div class="icon left"><i class="heart"></i></div>
<p>Thanks for your time</p>
<div class="icon right"><i class="heart"></i></div>
</fieldset>
</form>
JS:
function init() {
// Generate li foreach fieldset
for (var i = 0; i < count; i++) {if (window.CP.shouldStopExecution(1)){break;}
var ul = document.querySelector('ul.items'),
li = document.createElement("li");
ul.appendChild(li);
}
window.CP.exitedLoop(1);
// Add class active on first li
ul.firstChild.classList.add('active');
}
function next(target) {
var input = target.previousElementSibling;
// Check if input is empty
if (input.value === '') {
body.classList.add('error');
} else {
body.classList.remove('error');
var enable = document.querySelector('form fieldset.enable'),
nextEnable = enable.nextElementSibling;
enable.classList.remove('enable');
enable.classList.add('disable');
nextEnable.classList.add('enable');
// Switch active class on left list
var active = document.querySelector('ul.items li.active'),
nextActive = active.nextElementSibling;
active.classList.remove('active');
nextActive.classList.add('active');
}
}
function keyDown(event) {
var key = event.keyCode,
target = document.querySelector('fieldset.enable .button');
if (key == 13 || key == 9) next(target);
}
var body = document.querySelector('body'),
form = document.querySelector('form'),
count = form.querySelectorAll('fieldset').length;
window.onload = init;
document.body.onmouseup = function (event) {
var target = event.target || event.toElement;
if (target.classList.contains("button")) next(target);
};
document.addEventListener("keydown", keyDown, false);
I am trying to implement a video inside a bare CSS modal window as instructed here and it works great so far. The only problem I get is that video autostarts before modal window is even opened (I have to keep the video "autostart" option). Also video doesn't stop when modal window is closed.
Are there any CSS/HTML solutions for this? If there aren't any CSS/HTML solutions to this you can help me with javascript solutions.
body{
margin: 0;
padding-left: 10%;
padding-right: 10%;
padding-top: 2%;
padding-bottom: 1%;
}
.boxspace {
overflow: hidden;
}
.box {
float: left;
position: relative;
width: 16.6666%;
padding-bottom: 16.6666%;
}
.boxInner {
position: absolute;
left: 2%;
right: 2%;
top: 2%;
bottom: 2%;
overflow: hidden;
border: thin solid #969696;
border-radius: 4%;
}
.boxInner img {
width: 100%;
}
.boxInner .titleBox {
position: absolute;
bottom: 0;
left: 0;
right: 0;
margin-bottom: -42%;
background: #000000;
background: rgba(0, 0, 0, 0.8);
color: #FFFFFF;
padding-top: 2%;
padding-bottom: 2%;
padding-left: 2%;
padding-right: 2%;
text-align: center;
font-size: 1.2vw;
-webkit-transition: all 0.3s ease-out;
-moz-transition: all 0.3s ease-out;
-o-transition: all 0.3s ease-out;
transition: all 0.3s ease-out;
}
.boxInner .titleBox header{
color: #FFFFFF;
font-size: 1.4vw;
}
.boxInner .titleBox p{
color: #FFFFFF;
font-size: 1.0vw;
}
body.no-touch .boxInner:hover .titleBox, body.touch .boxInner.touchFocus .titleBox {
margin-bottom: 0px;
}
.modalVideo {
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
background: rgba(0,0,0,0.8);
z-index: 99999;
opacity:0;
-webkit-transition: opacity 400ms ease-in;
-moz-transition: opacity 400ms ease-in;
transition: opacity 400ms ease-in;
pointer-events: none;
}
.modalVideo:target {
opacity:1;
pointer-events: auto;
}
.modalVideo > div {
position: relative;
margin-top: 2vw;
margin-left: 20vw;
margin-right: 20vw;
padding-top: 1vw;
padding-bottom: 1vw;
padding-left:1.05vw;
padding-right:1.05vw;
border-radius: 1vw;
background: #ffffff;
font-size: 1.1vw;
}
.modalVideo video {
width: 100%;
}
.modalProgram {
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
background: rgba(0,0,0,0.8);
z-index: 99999;
opacity:0;
-webkit-transition: opacity 400ms ease-in;
-moz-transition: opacity 400ms ease-in;
transition: opacity 400ms ease-in;
pointer-events: none;
}
.modalProgram:target {
opacity:1;
pointer-events: auto;
}
.modalProgram > div {
position: relative;
margin-top: 2vw;
margin-left: 10vw;
margin-right: 10vw;
padding-top: 1vw;
padding-bottom: 1vw;
padding-left:2vw;
padding-right:2vw;
border-radius: 1vw;
background: #ffffff;
font-size: 1.1vw;
}
.close {
background: #FF0000;
color: #FFFFFF;
position: absolute;
top: 4vw;
right: -4.2vw;
text-align: center;
padding-left:0.75vw;
padding-right:0.75vw;
padding-bottom:0.25vw;
padding-top:0.25vw;
text-decoration: none;
border-top-left-radius: 0vw;
border-bottom-left-radius: 0vw;
border-top-right-radius: 1vw;
border-bottom-right-radius: 1vw;
}
.close:hover {
background: #464646;
}
<body class="no-touch">
<div class="boxspace">
<!-- tiles: -->
<div class="box">
<div class="boxInner">
<img src="http://dominicm.com/wp-content/uploads/2016/01/steam-arch-linux.png" />
<div class="titleBox">
<header>
Linux/C/ARM
</header>
<p>
video<br>
program<br>
prijavnica
</p>
</div>
</div>
</div>
</div>
<!-- end of tiles and wrap -->
<!--Linux/C/ARM - program-->
<div id="linux-c-arm_program" class="modalProgram">
<div>
close
<h3>HEADER</h3>
<p>
Paragraph
</p>
</div>
</div>
<!--Linux/C/ARM - video-->
<div id="linux-c-arm_video" class="modalVideo">
<div>
close
<video controls autoplay>
<source src="http://www.sample-videos.com/video/mp4/720/big_buck_bunny_720p_1mb.mp4" type="video/mp4">
</video>
</div>
</div>
<!-- end "no-touch" parameter for body-->
<script type="text/javascript">
$(function(){
// See if this is a touch device
if ('ontouchstart' in window){
// Set the correct [touchscreen] body class
$('body').removeClass('no-touch').addClass('touch');
// Add the touch toggle to show text when tapped
$('div.boxInner img').click(function(){
$(this).closest('.boxInner').toggleClass('touchFocus');
});
}
});
</script>
</body>
No this can't be done by HTML or CSS.
But you could easily do it with JavaScript and since you already have some jQuery code I'd recommend doing it also with jQuery because in this case you could easily achieve this by adding the following part to your script
jQuery
var $video = $(".modalVideo video")[0];
$video.autoplay = false;
$("a[href='#linux-c-arm_video']").click(function(){
$video.play();
});
$(".close").click(function(){
$video.pause();
});
$(function() {
// See if this is a touch device
if ('ontouchstart' in window) {
// Set the correct [touchscreen] body class
$('body').removeClass('no-touch').addClass('touch');
// Add the touch toggle to show text when tapped
$('div.boxInner img').click(function() {
$(this).closest('.boxInner').toggleClass('touchFocus');
});
}
});
var $video = $(".modalVideo video")[0];
$video.autoplay = false;
$("a[href='#linux-c-arm_video']").click(function() {
$video.play();
});
$(".close").click(function() {
$video.pause();
$video.currentTime = 0;
});
body {
margin: 0;
padding-left: 10%;
padding-right: 10%;
padding-top: 2%;
padding-bottom: 1%;
}
.boxspace {
overflow: hidden;
}
.box {
float: left;
position: relative;
width: 16.6666%;
padding-bottom: 16.6666%;
}
.boxInner {
position: absolute;
left: 2%;
right: 2%;
top: 2%;
bottom: 2%;
overflow: hidden;
border: thin solid #969696;
border-radius: 4%;
}
.boxInner img {
width: 100%;
}
.boxInner .titleBox {
position: absolute;
bottom: 0;
left: 0;
right: 0;
margin-bottom: -42%;
background: #000000;
background: rgba(0, 0, 0, 0.8);
color: #FFFFFF;
padding-top: 2%;
padding-bottom: 2%;
padding-left: 2%;
padding-right: 2%;
text-align: center;
font-size: 1.2vw;
-webkit-transition: all 0.3s ease-out;
-moz-transition: all 0.3s ease-out;
-o-transition: all 0.3s ease-out;
transition: all 0.3s ease-out;
}
.boxInner .titleBox header {
color: #FFFFFF;
font-size: 1.4vw;
}
.boxInner .titleBox p {
color: #FFFFFF;
font-size: 1.0vw;
}
body.no-touch .boxInner:hover .titleBox,
body.touch .boxInner.touchFocus .titleBox {
margin-bottom: 0px;
}
.modalVideo {
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
background: rgba(0, 0, 0, 0.8);
z-index: 99999;
opacity: 0;
-webkit-transition: opacity 400ms ease-in;
-moz-transition: opacity 400ms ease-in;
transition: opacity 400ms ease-in;
pointer-events: none;
}
.modalVideo:target {
opacity: 1;
pointer-events: auto;
}
.modalVideo > div {
position: relative;
margin-top: 2vw;
margin-left: 20vw;
margin-right: 20vw;
padding-top: 1vw;
padding-bottom: 1vw;
padding-left: 1.05vw;
padding-right: 1.05vw;
border-radius: 1vw;
background: #ffffff;
font-size: 1.1vw;
}
.modalVideo video {
width: 100%;
}
.modalProgram {
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
background: rgba(0, 0, 0, 0.8);
z-index: 99999;
opacity: 0;
-webkit-transition: opacity 400ms ease-in;
-moz-transition: opacity 400ms ease-in;
transition: opacity 400ms ease-in;
pointer-events: none;
}
.modalProgram:target {
opacity: 1;
pointer-events: auto;
}
.modalProgram > div {
position: relative;
margin-top: 2vw;
margin-left: 10vw;
margin-right: 10vw;
padding-top: 1vw;
padding-bottom: 1vw;
padding-left: 2vw;
padding-right: 2vw;
border-radius: 1vw;
background: #ffffff;
font-size: 1.1vw;
}
.close {
background: #FF0000;
color: #FFFFFF;
position: absolute;
top: 4vw;
right: -4.2vw;
text-align: center;
padding-left: 0.75vw;
padding-right: 0.75vw;
padding-bottom: 0.25vw;
padding-top: 0.25vw;
text-decoration: none;
border-top-left-radius: 0vw;
border-bottom-left-radius: 0vw;
border-top-right-radius: 1vw;
border-bottom-right-radius: 1vw;
}
.close:hover {
background: #464646;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<body class="no-touch">
<div class="boxspace">
<!-- tiles: -->
<div class="box">
<div class="boxInner">
<img src="http://dominicm.com/wp-content/uploads/2016/01/steam-arch-linux.png" />
<div class="titleBox">
<header>
Linux/C/ARM
</header>
<p>
video
<br>
program
<br>prijavnica
</p>
</div>
</div>
</div>
</div>
<!-- end of tiles and wrap -->
<!--Linux/C/ARM - program-->
<div id="linux-c-arm_program" class="modalProgram">
<div>
close
<h3>HEADER</h3>
<p>
Paragraph
</p>
</div>
</div>
<!--Linux/C/ARM - video-->
<div id="linux-c-arm_video" class="modalVideo">
<div>
close
<video controls autoplay>
<source src="http://www.sample-videos.com/video/mp4/720/big_buck_bunny_720p_1mb.mp4" type="video/mp4">
</video>
</div>
</div>
</body>
More videos
If you want the ability to have multiple videos which are called dynamically on click by a specific id you have to make following changes
At first I would recommend to exclude the video manipulation play(), pause() to a function called playVideo() for example.
Function
function playVideo(id) {
var $video = $(id + " video")[0];
$video.autoplay = false;
$video.play();
$(".close").click(function() {
$video.pause();
$video.currentTime = 0;
});
}
Important to notice is that with this suggestion the function needs a parameter id. This will be the id of the link you clicked on. This works since the href of the link has the same id as the container of the video.
And finally to get the id only of the links a video should be displayed you have to add this to your code.
$(".box a[href*='video']").click(function() {
var id = $(this).attr("href");
playVideo(id);
});
$(function() {
// See if this is a touch device
if ('ontouchstart' in window) {
// Set the correct [touchscreen] body class
$('body').removeClass('no-touch').addClass('touch');
// Add the touch toggle to show text when tapped
$('div.boxInner img').click(function() {
$(this).closest('.boxInner').toggleClass('touchFocus');
});
}
});
$(".box a[href*='video']").click(function() {
var id = $(this).attr("href");
playVideo(id);
});
function playVideo(id) {
var $video = $(id + " video")[0];
$video.autoplay = false;
$video.play();
$(".close").click(function() {
$video.pause();
$video.currentTime = 0;
});
}
body {
margin: 0;
padding-left: 10%;
padding-right: 10%;
padding-top: 2%;
padding-bottom: 1%;
}
.boxspace {
overflow: hidden;
}
.box {
float: left;
position: relative;
width: 16.6666%;
padding-bottom: 16.6666%;
}
.boxInner {
position: absolute;
left: 2%;
right: 2%;
top: 2%;
bottom: 2%;
overflow: hidden;
border: thin solid #969696;
border-radius: 4%;
}
.boxInner img {
width: 100%;
}
.boxInner .titleBox {
position: absolute;
bottom: 0;
left: 0;
right: 0;
margin-bottom: -42%;
background: #000000;
background: rgba(0, 0, 0, 0.8);
color: #FFFFFF;
padding-top: 2%;
padding-bottom: 2%;
padding-left: 2%;
padding-right: 2%;
text-align: center;
font-size: 1.2vw;
-webkit-transition: all 0.3s ease-out;
-moz-transition: all 0.3s ease-out;
-o-transition: all 0.3s ease-out;
transition: all 0.3s ease-out;
}
.boxInner .titleBox header {
color: #FFFFFF;
font-size: 1.4vw;
}
.boxInner .titleBox p {
color: #FFFFFF;
font-size: 1.0vw;
}
body.no-touch .boxInner:hover .titleBox,
body.touch .boxInner.touchFocus .titleBox {
margin-bottom: 0px;
}
.modalVideo {
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
background: rgba(0, 0, 0, 0.8);
z-index: 99999;
opacity: 0;
-webkit-transition: opacity 400ms ease-in;
-moz-transition: opacity 400ms ease-in;
transition: opacity 400ms ease-in;
pointer-events: none;
}
.modalVideo:target {
opacity: 1;
pointer-events: auto;
}
.modalVideo > div {
position: relative;
margin-top: 2vw;
margin-left: 20vw;
margin-right: 20vw;
padding-top: 1vw;
padding-bottom: 1vw;
padding-left: 1.05vw;
padding-right: 1.05vw;
border-radius: 1vw;
background: #ffffff;
font-size: 1.1vw;
}
.modalVideo video {
width: 100%;
}
.modalProgram {
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
background: rgba(0, 0, 0, 0.8);
z-index: 99999;
opacity: 0;
-webkit-transition: opacity 400ms ease-in;
-moz-transition: opacity 400ms ease-in;
transition: opacity 400ms ease-in;
pointer-events: none;
}
.modalProgram:target {
opacity: 1;
pointer-events: auto;
}
.modalProgram > div {
position: relative;
margin-top: 2vw;
margin-left: 10vw;
margin-right: 10vw;
padding-top: 1vw;
padding-bottom: 1vw;
padding-left: 2vw;
padding-right: 2vw;
border-radius: 1vw;
background: #ffffff;
font-size: 1.1vw;
}
.close {
background: #FF0000;
color: #FFFFFF;
position: absolute;
top: 4vw;
right: -4.2vw;
text-align: center;
padding-left: 0.75vw;
padding-right: 0.75vw;
padding-bottom: 0.25vw;
padding-top: 0.25vw;
text-decoration: none;
border-top-left-radius: 0vw;
border-bottom-left-radius: 0vw;
border-top-right-radius: 1vw;
border-bottom-right-radius: 1vw;
}
.close:hover {
background: #464646;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<body class="no-touch">
<div class="boxspace">
<!-- tiles: -->
<div class="box">
<div class="boxInner">
<img src="http://dominicm.com/wp-content/uploads/2016/01/steam-arch-linux.png" />
<div class="titleBox">
<header>
Linux/C/ARM
</header>
<p>
video
<br>
program
<br>prijavnica
</p>
</div>
</div>
</div>
<div class="box">
<div class="boxInner">
<img src="http://dominicm.com/wp-content/uploads/2016/01/steam-arch-linux.png" />
<div class="titleBox">
<header>
Linux/Eagle/ARM
</header>
<p>
video
<br>
program
<br>prijavnica
</p>
</div>
</div>
</div>
</div>
<!-- end of tiles and wrap -->
<!--Linux/C/ARM - program-->
<div id="linux-c-arm_program" class="modalProgram">
<div>
close
<h3>HEADER</h3>
<p>
Paragraph
</p>
</div>
</div>
<!--Linux/C/ARM - video-->
<div id="linux-c-arm_video" class="modalVideo">
<div>
close
<video controls autoplay>
<source src="http://www.sample-videos.com/video/mp4/720/big_buck_bunny_720p_1mb.mp4" type="video/mp4">
</video>
</div>
</div>
<div id="linux-eagle_video" class="modalVideo">
<div>
close
<video controls autoplay>
<source src="http://www.sample-videos.com/video/mp4/720/big_buck_bunny_720p_1mb.mp4" type="video/mp4">
</video>
</div>
</div>
</body>
As far as I know there is no way to control the HTML video player with CSS.
And with HTML you cannot tell the video to start/stop when the modal is opened/closed, this is what javascript is for.
To controll the Video with js you could use plain javascript on modal open:
document.getElementById('videoId').play();
HTML Changes
Remove the autoplay attribute from the video elements—you don't actually want it to play when the page loads, you want it to play when the modal window opens.
jQuery changes
Change your jQuery code to the following:
$(function(){
// See if this is a touch device
if ('ontouchstart' in window){
// Set the correct [touchscreen] body class
$('body').removeClass('no-touch').addClass('touch');
// Add the touch toggle to show text when tapped
$('div.boxInner img').click(function(){
$(this).closest('.boxInner').toggleClass('touchFocus');
});
}
/////////////////////////
// Changes start here
/////////////////////////
// Play clicked video
var playClickedVideo = function () {
var videoId = $(this).attr('href');
var video = $(videoId + ' video')[0];
video.play();
};
$('.titleBox a').click(playClickedVideo);
// Pause video when the close button is clicked
var stopVideos = function () {
$('video').each(function (i, video) {
video.pause();
video.currentTime = 0; // To rewind (optional)
});
};
$('.close').click(stopVideos);
});
I have a CodePen demo here: http://codepen.io/tinacious/pen/gLvwyy
I had to modify some of your CSS to see the links so I can click them, so only copy the jQuery.
I have create a pop up using only CSS and HTML it works fine as i need and here is code
.wrap {
padding: 40px;
text-align: center;
}
hr {
clear: both;
margin-top: 40px;
margin-bottom: 40px;
border: 0;
border-top: 1px solid #aaaaaa;
}
h1 {
font-size: 30px;
margin-bottom: 40px;
}
p {
margin-bottom: 20px;
}
.btn {
background: #428bca;
border: #357ebd solid 1px;
border-radius: 3px;
color: #fff;
display: inline-block;
font-size: 14px;
padding: 8px 15px;
text-decoration: none;
text-align: center;
min-width: 60px;
position: relative;
transition: color .1s ease;
}
.btn:hover {
background: #357ebd;
}
.btn.btn-big {
font-size: 18px;
padding: 15px 20px;
min-width: 100px;
}
.btn-close {
color: #aaaaaa;
font-size: 30px;
text-decoration: none;
position: absolute;
right: 5px;
top: 0;
}
.btn-close:hover {
color: #919191;
}
.modal:before {
content: "";
display: none;
background: rgba(0, 0, 0, 0.6);
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
z-index: 10;
}
.modal:target:before {
display: block;
}
.modal:target .modal-dialog {
-webkit-transform: translate(0, 0);
-ms-transform: translate(0, 0);
transform: translate(0, 0);
top: 20%;
}
.modal-dialog {
background: #fefefe;
border: #333333 solid 1px;
border-radius: 5px;
margin-left: -200px;
position: fixed;
left: 50%;
top: -100%;
z-index: 11;
width: 360px;
-webkit-transform: translate(0, -500%);
-ms-transform: translate(0, -500%);
transform: translate(0, -500%);
-webkit-transition: -webkit-transform 0.3s ease-out;
-moz-transition: -moz-transform 0.3s ease-out;
-o-transition: -o-transform 0.3s ease-out;
transition: transform 0.3s ease-out;
}
.modal-body {
padding: 20px;
}
.modal-header,
.modal-footer {
padding: 10px 20px;
}
.modal-header {
border-bottom: #eeeeee solid 1px;
}
.modal-header h2 {
font-size: 20px;
}
.modal-footer {
border-top: #eeeeee solid 1px;
text-align: right;
}
<div class="wrap">
pop up!
</div>
<!-- Modal -->
<div class="modal" id="modal-one" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-header">
<h2>Modal in CSS?</h2>
Ă—
</div>
<div class="modal-body">
<p>One modal example here! :D</p>
</div>
<div class="modal-footer">
Nice!
</div>
</div>
</div>
Jsfiddle
My problem is when i click pop up entire page scroll down to bottom and pop up appears
since i have lot of content in my page
i need to open pop up on same place i don't want the page to scroll down can some one help whats wrong
NOTE when you try with the above code you can only find scroll little bit
but in my page it scroll to bottom of page
I don't know if I understand it correctly but try to add sth like that:
body.unscrollable {
overflow:hidden;
}
and add class .unscrollable when modal is open.
It will disable scrolling on website body.