How to set the states in react before again using it? - html

import { useState } from 'react'
import './Events.css'
export default function Events() {
const [position, setImgPos] = useState('0')
const [display, setDisplay] = useState('')
const [left, setLeft] = useState('-100%')
const stylesImg = {
left: position
};
const stylesTitle = {
display: display,
};
const stylesDesc = {
left: left
};
return (
<div className='events-box'>
<div className='event'
onMouseLeave={() => {
setImgPos('0');
setTimeout(() => {
setDisplay('');
}, 500)
setLeft('-100%')
}} >
<img style={stylesImg}
onMouseEnter={() => {
setImgPos('60vw');
setDisplay('none');
setLeft('0')
}}
src="https://www.w3schools.com/css/img_forest.jpg"
/>
<p style={stylesTitle} className='event-title'>RoboWars</p>
<p style={stylesDesc} className='event-desc'>Lorem ipsum dolor sit amet consectetur adipisicing elit. Praesentium minus neque mollitia voluptates aliquid voluptas cupiditate! Aliquam modi sint nulla eos excepturi ab repellat accusamus id eius facere, soluta minus.</p>
</div>
<div className='event'
onMouseLeave={() => {
setImgPos('0');
setTimeout(() => {
setDisplay('');
}, 500)
setLeft('-100%')
}} >
<img style={stylesImg}
onMouseEnter={() => {
setImgPos('60vw');
setDisplay('none');
setLeft('0')
}}
src="https://www.w3schools.com/css/img_forest.jpg"
/>
<p style={stylesTitle} className='event-title'>RoboWars</p>
<p style={stylesDesc} className='event-desc'>Lorem ipsum dolor sit amet consectetur adipisicing elit. Praesentium minus neque mollitia voluptates aliquid voluptas cupiditate! Aliquam modi sint nulla eos excepturi ab repellat accusamus id eius facere, soluta minus.</p>
</div>
</div>
)
}
.events-box {
margin-top: 20px;
}
.event {
background-color: #3B3B3B;
display: flex;
align-items: center;
}
img {
width: 40vw;
height: 40vh;
position: relative;
transition: 1s;
}
.event-title {
margin: auto;
color: #fff;
font-size: 2em;
position: relative;
}
.event-desc {
position: fixed;
font-size: 1em;
color: white;
width: 60vw;
padding: 20px;
margin: auto;
transition: 1s;
}
I have made to div for sliding the image and showing some text when we move the mouse in and out.
The problem is that when I slide on one div, the changes happen on the other div too.
Here, when i hovered over the first div, the 2nd div also shifted, but I don't want that to happen:

Just use different state, check this:
export default function Feed() {
const [position, setImgPos] = useState('0')
const [display, setDisplay] = useState('')
const [left, setLeft] = useState('-100%')
const [position2, setImgPos2] = useState('0')
const [display2, setDisplay2] = useState('')
const [left2, setLeft2] = useState('-100%')
const stylesImg = {
left: position
};
const stylesTitle = {
display: display,
};
const stylesDesc = {
left: left
};
const stylesImg2 = {
left: position2
};
const stylesTitle2 = {
display: display2,
};
const stylesDesc2 = {
left: left2
};
return (
<div className='events-box'>
<div className='event'
onMouseLeave={() => {
setImgPos('0');
setTimeout(() => {
setDisplay('');
}, 500)
setLeft('-100%')
}} >
<img style={stylesImg}
onMouseEnter={() => {
setImgPos('60vw');
setDisplay('none');
setLeft('0')
}}
src="https://www.w3schools.com/css/img_forest.jpg"
/>
<p style={stylesTitle} className='event-title'>RoboWars</p>
<p style={stylesDesc} className='event-desc'>Lorem ipsum dolor sit amet consectetur adipisicing elit. Praesentium minus neque mollitia voluptates aliquid voluptas cupiditate! Aliquam modi sint nulla eos excepturi ab repellat accusamus id eius facere, soluta minus.</p>
</div>
<div className='event'
onMouseLeave={() => {
setImgPos2('0');
setTimeout(() => {
setDisplay2('');
}, 500)
setLeft2('-100%')
}} >
<img style={stylesImg2}
onMouseEnter={() => {
setImgPos2('60vw');
setDisplay2('none');
setLeft2('0')
}}
src="https://www.w3schools.com/css/img_forest.jpg"
/>
<p style={stylesTitle2} className='event-title'>RoboWars</p>
<p style={stylesDesc2} className='event-desc'>Lorem ipsum dolor sit amet consectetur adipisicing elit. Praesentium minus neque mollitia voluptates aliquid voluptas cupiditate! Aliquam modi sint nulla eos excepturi ab repellat accusamus id eius facere, soluta minus.</p>
</div>
</div>
)
}
Or you can only play with css, just make 1 state for example using boolean "isActive" state, when isActive then add new class. Below full code:
import { useState } from "react";
import styles from './feed.module.css';
const content = [
{
image: "https://www.w3schools.com/css/img_forest.jpg",
title: "RoboWars",
desc: "Lorem ipsum dolor sit amet consectetur adipisicing elit."
},
{
image: "https://www.w3schools.com/css/img_forest.jpg",
title: "RoboWars 2",
desc: "Another Lorem ipsum dolor sit amet consectetur adipisicing elit."
}
]
export default function Feed() {
const [isActive, setIsActive] = useState(-1);
return (
<div className='events-box'>
{content.map((build, i) => {
return (<div className='event'>
<img className={isActive===i ? styles.activeImg : styles.stylesImg}
onMouseEnter={() => setIsActive(i)}
src={build.image}
/>
<p className={`${isActive===i ? styles.activeTitle : styles.stylesTitle} ${styles.eventTitle}`}>{build.title}</p>
<p className={`${isActive===i ? styles.activeDesc : styles.stylesDesc} ${styles.eventDesc}`}>{build.desc}</p>
</div>);
})}
</div>
)
}
and add this to your css files:
.stylesImg {
left: 0;
}
.stylesTitle {
display: '';
}
.stylesDesc {
left: -100%;
}
.activeImg {
left: 60vw;
}
.activeTitle {
display: none;
}
.activeDesc {
left: 0;
}

What you should do is to create a component for each of your sliders wit their own states.
Therefore you encapsulate the states of every logical component in the app.

Related

How to remove background color when clicked on active class

filterSelection("all")
function filterSelection(c) {
var x, i;
x = document.getElementsByClassName("filterDiv");
if (c == "all") c = "";
for (i = 0; i < x.length; i++) {
w3RemoveClass(x[i], "show");
if (x[i].className.indexOf(c) > -1) w3AddClass(x[i], "show");
}
}
function w3AddClass(element, name) {
var i, arr1, arr2;
arr1 = element.className.split(" ");
arr2 = name.split(" ");
for (i = 0; i < arr2.length; i++) {
if (arr1.indexOf(arr2[i]) == -1) {element.className += " " + arr2[i];}
}
}
function w3RemoveClass(element, name) {
var i, arr1, arr2;
arr1 = element.className.split(" ");
arr2 = name.split(" ");
for (i = 0; i < arr2.length; i++) {
while (arr1.indexOf(arr2[i]) > -1) {
arr1.splice(arr1.indexOf(arr2[i]), 1);
}
}
element.className = arr1.join(" ");
}
// Add active class to the current button (highlight it)
var btnContainer = document.getElementById("myBtnContainer");
var btns = btnContainer.getElementsByClassName("btn");
for (var i = 0; i < btns.length; i++) {
btns[i].addEventListener("click", function(){
var current = document.getElementsByClassName("active");
current[0].className = current[0].className.replace(" active", "");
this.className += " active";
});
}
.filterDiv {
float: left;
margin: 2px;
display: none;
}
.btn
{
list-style: none;
display: inline-block;
}
.show {
display: block;
}
.container {
margin-top: 20px;
overflow: hidden;
}
/* Style the buttons */
.btn {
border: none;
outline: none;
padding: 12px 16px;
cursor: pointer;
}
/* animation duration */
#para
{
animation-duration: 2s;
}
#myBtnContainer
{
display: flex;
overflow-x: auto;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
<title>Document</title>
</head>
<body>
<h2>Sample</h2>
<div id="myBtnContainer">
<li class="btn active" onclick="filterSelection('all')"> Show all</li>
<li class="btn" onclick="filterSelection('sam')"> sam</li>
<li class="btn" onclick="filterSelection('jhon')"> jhon</li>
<li class="btn" onclick="filterSelection('rog')"> rog</li>
<li class="btn" onclick="filterSelection('stv')"> stv</li>
<li class="btn" onclick="filterSelection('scott')"> scott</li>
</div>
<div class="container">
<div class="filterDiv all w3-container w3-animate-bottom" id="para">
<h4>what is food</h4>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Cum omnis architecto laborum nam t</p>
<h4>lorem ipsum</h4>
<p> lorem ipsum
</p>
<h4>lorem ipsum</h4>
<p class="text"> Lorem ipsum dolor sit amet, consectetur adipisicing elit. Cum omnis architecto laborum nam t</p>
</div>
<div class="filterDiv sam w3-container w3-animate-bottom" id="para">
<h4>lorem ipsum</h4>
<p> Lorem ipsum dolor sit amet, consectetur adipisicing elit. Cum omnis architecto laborum nam t</p>
<h4 >What is the Cricket Live Scores API?</h4>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Cum omnis architecto laborum nam t
</p>
</div>
<div class="filterDiv jhon w3-container w3-animate-bottom" id="para">
<h4>lorem ipsum</h4>
<p> Lorem ipsum dolor sit amet, consectetur adipisicing elit. Cum omnis architecto laborum nam t</p>
<h4>lorem ipsum</h4>
<p> Lorem ipsum dolor sit amet, consectetur adipisicing elit. Cum omnis architecto laborum nam t</p>
</div>
<div class="filterDiv rog w3-container w3-animate-bottom" id="para">
<h4>lorem ipsum</h4>
<p> Lorem ipsum dolor sit amet, consectetur adipisicing elit. Cum omnis architecto laborum nam t</p>
</div>
<div class="filterDiv stv w3-container w3-animate-bottom" id="para">
<h4>lorem ipsum</a></h4>
<p class="text">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Cum omnis architecto laborum nam t</p>
</div>
</div>
</body>
</html>
The above screenshot is from my phone.
The question is how do I remove the blue colour appearing on background on click of all list tags? I did not add it in my css.
I tried using focus, active in my css, that did not work.
I want to implement this as showed in the following image.
I came across data filtering while I was going through w3schools. I saw some really nice examples online, and I wanted to try one, but I'm stuck at this example because I cannot understand where the blue colour in the image is coming from.
Here is an example of how to use dataset attributes along with JS to change a percentage of movement in the ROOT element to move your HR below the list-item buttons.
You set the HR below the LI elements in your HTML so you can use CSS to target the HR with the unique selector for each button by targeting the HR along with the general sibling selector ~. Set the HR element to absolute and style the width and background color, then you can position it using the left property on hover of each button element .show-all:hover ~ hr.
Now we set the hr's original to a CSS variable
:root {
--active: 24px;
}
Then in the hr element we set the original left property to that variable
left: var(--active);
Then in the JS function that sets your active class you can add the following line: document.documentElement.style.setProperty('--active, this.dataset.active), since we have the percentage of offset set in the data.active attribute, it will now set the clicked buttons percentage of offset to the HR's active variable in the pages style for the HTML element.
I also added a justify-content: space-around to space the buttons out equally, otherwise youb would have to use more code to shorten/enlarge the HR element on hover...
NOTE: there is some kind of padding or margin glich going on with the clicking of your last buttons, I do apologize, but I did not have time to work that part out, but this gives you a good idea of how to achieve the method of active you are looking for.
filterSelection("all")
function filterSelection(c) {
var x, i;
x = document.getElementsByClassName("filterDiv");
if (c == "all") c = "";
for (i = 0; i < x.length; i++) {
w3RemoveClass(x[i], "show");
if (x[i].className.indexOf(c) > -1) w3AddClass(x[i], "show");
}
}
function w3AddClass(element, name) {
var i, arr1, arr2;
arr1 = element.className.split(" ");
arr2 = name.split(" ");
for (i = 0; i < arr2.length; i++) {
if (arr1.indexOf(arr2[i]) == -1) {
element.className += " " + arr2[i];
}
}
}
function w3RemoveClass(element, name) {
var i, arr1, arr2;
arr1 = element.className.split(" ");
arr2 = name.split(" ");
for (i = 0; i < arr2.length; i++) {
while (arr1.indexOf(arr2[i]) > -1) {
arr1.splice(arr1.indexOf(arr2[i]), 1);
}
}
element.className = arr1.join(" ");
}
// Add active class to the current button (highlight it)
var btnContainer = document.getElementById("myBtnContainer");
var btns = btnContainer.getElementsByClassName("btn");
for (var i = 0; i < btns.length; i++) {
btns[i].addEventListener("click", function() {
var current = document.getElementsByClassName("active");
current[0].className = current[0].className.replace(" active", "");
this.className += " active";
console.log(this.dataset.active)
document.documentElement.style.setProperty('--active', this.dataset.active )
});
}
:root {
--active: 24px;
}
.filterDiv {
float: left;
margin: 2px;
display: none;
}
.btn {
list-style: none;
display: inline-block;
}
.show {
display: block;
}
.container {
margin-top: 20px;
overflow: hidden;
}
/* Style the buttons */
.btn {
border: none;
outline: none;
padding: 12px 16px;
cursor: pointer;
}
hr {
width: 0.25em;
left: var(--active);
width: 12%;
background-color: purple;
position: absolute;
top: .8rem;
transition: left .3s ease-in-out;
}
.show-all:hover ~ hr {
left: 24px;
}
.sam:hover ~ hr {
left: 24%;
}
.jhon:hover ~ hr {
left: 40%;
}
.rog:hover ~ hr {
left: 56%;
}
.stv:hover ~ hr {
left: 70%;
}
.scott:hover ~ hr {
left: 85%;
}
/* animation duration */
#para {
animation-duration: 2s;
}
#myBtnContainer {
display: flex;
justify-content: space-around;
overflow-x: none;
position: relative;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
<title>Document</title>
</head>
<body>
<h2>Sample</h2>
<div id="myBtnContainer">
<li class="btn show-all active" data-active="24px" onclick="filterSelection('all')"> Show all</li>
<li class="btn sam" data-active="24%" onclick="filterSelection('sam')"> sam</li>
<li class="btn jhon" data-active="40%" onclick="filterSelection('jhon')"> jhon</li>
<li class="btn rog" data-active="56%" onclick="filterSelection('rog')"> rog</li>
<li class="btn stv" data-active="70%" onclick="filterSelection('stv')"> stv</li>
<li class="btn scott" data-active="85%" onclick="filterSelection('scott')"> scott</li>
<hr />
</div>
<div class="container">
<div class="filterDiv all w3-container w3-animate-bottom" id="para">
<h4>what is food</h4>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Cum omnis architecto laborum nam t</p>
<h4>lorem ipsum</h4>
<p> lorem ipsum
</p>
<h4>lorem ipsum</h4>
<p class="text"> Lorem ipsum dolor sit amet, consectetur adipisicing elit. Cum omnis architecto laborum nam t</p>
</div>
<div class="filterDiv sam w3-container w3-animate-bottom" id="para">
<h4>lorem ipsum</h4>
<p> Lorem ipsum dolor sit amet, consectetur adipisicing elit. Cum omnis architecto laborum nam t</p>
<h4>What is the Cricket Live Scores API?</h4>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Cum omnis architecto laborum nam t
</p>
</div>
<div class="filterDiv jhon w3-container w3-animate-bottom" id="para">
<h4>lorem ipsum</h4>
<p> Lorem ipsum dolor sit amet, consectetur adipisicing elit. Cum omnis architecto laborum nam t</p>
<h4>lorem ipsum</h4>
<p> Lorem ipsum dolor sit amet, consectetur adipisicing elit. Cum omnis architecto laborum nam t</p>
</div>
<div class="filterDiv rog w3-container w3-animate-bottom" id="para">
<h4>lorem ipsum</h4>
<p> Lorem ipsum dolor sit amet, consectetur adipisicing elit. Cum omnis architecto laborum nam t</p>
</div>
<div class="filterDiv stv w3-container w3-animate-bottom" id="para">
<h4>lorem ipsum
</h4>
<p class="text">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Cum omnis architecto laborum nam t</p>
</div>
</div>
</body>
</html>

CSS Grid will not format correctly no matter what

I am following a series of Traversy Media videos for creating a portfolio website. I have a foundational knowledge of HTML/CSS. We have to create a grid and no matter what I do, I cannot get the grid to show up in my browser (Chrome). The grid will be for the About info on the about page. Also the footer isn't showing up for some reason. Any help would be greatly appreciated.
Here is the about.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://kit.fontawesome.com/31d2c226f4.js" crossorigin="anonymous"></script>
<link rel="stylesheet" href="css/main.css">
<title>About Me</title>
</head>
<body>
<div class="overlay"></div>
<header>
<div class="menu-btn">
<div class="btn-line"></div>
<div class="btn-line"></div>
<div class="btn-line"></div>
</div>
<nav class="menu">
<div class="menu-branding">
<div class="portrait"></div>
</div>
<ul class="menu-nav">
<li class="nav-item">
<a href="/" class="nav-link">
Home
</a>
</li>
<li class="nav-item current">
<a href="about.html" class="nav-link">
About Moi
</a>
</li>
<li class="nav-item">
<a href="work.html" class="nav-link">
My Work
</a>
</li>
<li class="nav-item">
<a href="Contact.html" class="nav-link">
How to Reach Me
</a>
</li>
</ul>
</nav>
</header>
<main id="about">
<h1 class="lg-heading">
About
<span class="text-secondary">Me</span>
</h1>
<h2 class="sm-heading">
Let me tell you a few things...
</h2>
<div class="about-info">
<!-- <img src="img/portrait.jpeg" alt="Alex Gool" class="bio-image"> -->
<div class="bio">
<h3 class="text-secondary">BIO</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Exercitationem dolore at, quasi natus veritatis, amet cum voluptates, iste fugit atque autem laboriosam. Provident officia modi inventore fugit recusandae vitae nisi.</p>
</div>
<div class="job job-1">
<h3>123 Webshop</h3>
<h6>Full Stack Developer</h6>
<p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Nisi ipsum aperiam inventore. Inventore illo accusamus debitis facilis, quisquam velit aliquam?</p>
</div>
<div class="job job-2">
<h3>Designers ABC</h3>
<h6>Front End Developer</h6>
<p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Nisi ipsum aperiam inventore. Inventore illo accusamus debitis facilis, quisquam velit aliquam?</p>
</div>
<div class="job job-3">
<h3>Webworks</h3>
<h6>Graphic Designer</h6>
<p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Nisi ipsum aperiam inventore. Inventore illo accusamus debitis facilis, quisquam velit aliquam?</p>
</div>
</div>
</main>
<footer id="main-footer">
Copyright © 2021
</footer>
<script src="js/main.js"></script>
</body>
</html>
And here is the main SCSS file
// Move variable and functions to _config.scss file. This helps tidy up the main.scss file and makes the code more readable. Use #import then the file name (NOT WITH THE .scss EXTENSION).
#import "config";
#import "menu";
// Ensures inside padding will not affect height/width of box, it will just be in the box itself.
* {
box-sizing: border-box;
}
body {
#include background;
background: $primary-color;
color: set-text-color($primary-color);
height: 100%;
margin: 0;
font-family: "Segoe UI", "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
line-height: 1.5;
}
// Headings
h1,
h2,
h3 {
margin: 0;
font-weight: 400;
&.lg-heading {
font-size: 6rem;
}
&.sm-heading {
margin-bottom: 2rem;
padding: 0.2rem 1rem;
// Background to heading information will be lighter.
// Wrap in RGBA function, 0.5 is the opacity.
background: rgba(lighten($primary-color, 2), 0.5);
}
}
a {
color: #fff;
text-decoration: none;
}
// Header (icon) is fixed so it stays at top right when user scrolls through the webpage.
header {
position: fixed;
z-index: 2;
width: 100%;
}
.text-secondary {
color: $secondary-color;
}
// Nesting the .icons class so that only the icons in the main tag will be affected. This is specific to SASS.
main {
padding: 4rem;
// height: 100%;
min-height: calc(100vh - 60px);
.icons {
margin-top: 1rem;
color: set-text-color($primary-color);
// Inside the div class "icons", each icon is wrapped in a link.
a {
padding: 0.4rem;
// Putting the & in things is specific to SASS, this is not a feature of normal CSS.
&:hover {
color: $secondary-color;
#include easeOut();
}
}
}
&#home {
// This makes it so that there will never be scroll bars.
overflow: hidden;
h1 {
// This brings my name down closer to the middle of the page.
margin-top: 20vh;
}
}
}
.about-info {
display: grid !important;
grid-template-columns: 1fr 1fr 1fr !important;
grid-template-rows: auto !important;
grid-template-areas:
"bioimage bio bio"
" job1 job2 job3" !important;
.bio-image {
grid-area: bioimage;
margin: auto;
border-radius: 50%;
border: $secondary-color 3px solid;
}
.bio {
grid-area: bio;
font-size: 1.5rem;
}
.job-1 {
grid-area: job1;
}
.job-2 {
grid-area: job2;
}
.job-3 {
grid-area: job3;
}
.job {
background: lighten($primary-color: 5);
padding: 0.5rem;
border-bottom: $secondary-color 5px solid;
}
}
#main-footer {
text-align: center;
padding: 1rem;
background: darken($primary-color: 10);
color: set-text-color($primary-color);
height: 60px;
}
#import "mobile";
I took this snippet from the code you linked and rewrote it without SCSS so it can compile below. It seems to me like display: grid is working just fine. If you open the chrome dev tools and inspect, you will see a "grid" label on the .about-info element.
.about-info {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
grid-template-rows: auto;
grid-template-areas: "bioimage bio bio" " job1 job2 job3" !important;
}
.about-info .job-1 {
grid-area: job1;
}
.about-info .job-2 {
grid-area: job2;
}
.about-info .job-3 {
grid-area: job3;
}
.about-info .bio {
grid-area: bio;
font-size: 1.5rem;
}
.about-info .bio-image {
grid-area: bioimage;
margin: auto;
border-radius: 50%;
border: $secondary-color 3px solid;
}
.about-info .job {
background: lighten($primary-color: 5);
padding: 0.5rem;
border-bottom: $secondary-color 5px solid;
}
<div class="about-info">
<div class="bio">
<h3 class="text-secondary">BIO</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Exercitationem dolore at, quasi natus veritatis, amet cum voluptates, iste fugit atque autem laboriosam. Provident officia modi inventore fugit recusandae vitae nisi.</p>
</div>
<div class="job job-1">
<h3>123 Webshop</h3>
<h6>Full Stack Developer</h6>
<p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Nisi ipsum aperiam inventore. Inventore illo accusamus debitis facilis, quisquam velit aliquam?</p>
</div>
<div class="job job-2">
<h3>Designers ABC</h3>
<h6>Front End Developer</h6>
<p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Nisi ipsum aperiam inventore. Inventore illo accusamus debitis facilis, quisquam velit aliquam?</p>
</div>
<div class="job job-3">
<h3>Webworks</h3>
<h6>Graphic Designer</h6>
<p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Nisi ipsum aperiam inventore. Inventore illo accusamus debitis facilis, quisquam velit aliquam?</p>
</div>
</div>

How to change image in card on hover dynamically in Vue js?

I am trying to add 2 images in the card on hover in Vue.
When I hover over the card I want a different image and if I remove hovering it should different.
Here is my HTML:
<div class="services">
<h1>Our Services</h1>
<div class="container">
<div
v-for="service in services"
:key="service.title"
#mouseover="isMouseOver = !isMouseOver"
class="card"
:style="
isMouseOver
? 'background-image:' + service.icon + ';'
: 'background-image:' + service.iconGlow + ';'
"
>
<div class="face face1">
<div class="content">
<h3>{{ service.title }}</h3>
</div>
</div>
<div class="face face2">
<div class="content">
<p>
{{ service.description }}
</p>
Read More
</div>
</div>
</div>
</div>
</div>
Here is my script code:
<script>
export default {
data() {
return {
isMouseOver: true,
services: [
{
icon: require("#/assets/icons/services/webIcon.svg"),
iconGlow: require("#/assets/icons/services/WebLogoGlow.svg"),
title: "Web Development",
description:
"lorem ipsum lorem ipsum Lorem ipsum dolor sit amet consectetur adipisicing elit. Quas cum cumque minus iste veritatis provident at.",
},
{
icon: require("#/assets/icons/services/AppIcon.svg"),
iconGlow: require("#/assets/icons/services/AppIconGlow.svg"),
title: "Mobile Application Development",
description:
"lorem ipsum lorem ipsum Lorem ipsum dolor sit amet consectetur adipisicing elit. Quas cum cumque minus iste veritatis provident at.",
},
{
icon: require("#/assets/icons/services/Cross.svg"),
iconGlow: require("#/assets/icons/services/CrossLogo2.svg"),
title: "Computer Application Development",
description:
"lorem ipsum lorem ipsum Lorem ipsum dolor sit amet consectetur adipisicing elit. Quas cum cumque minus iste veritatis provident at.",
},
],
};
},
};
</script>
Here is my CSS:
.container .card .face.face1 {
position: relative;
background: #333;
/* display: flex; */
justify-content: center;
align-items: center;
z-index: 1;
transform: translateY(100px);
/* background-image: url("../assets/icons/services/WebLogoGlow.svg"); */
background-size: 30%;
background-repeat: no-repeat;
background-position: center;
}
.container .card:hover .face.face1 {
background: #9376cf;
transform: translateY(0);
/* background-image: url("../assets/icons/services/webIcon.svg"); */
background-size: 30%;
background-repeat: no-repeat;
background-position: center;
}
I want these background images in CSS to be dynamic. How can I do that?

How to prevent pointer-event outside of iframe with svg clip-path? (Safari browser)

I have made a parallax effect on iframe, which is position: fixed. The iframe is inside a container which has clipped with SVG <clipPath/>.
It works on Chrome, Firefox and Safari browser. But in Safari it works partially. Visiblity works but not the events. the events are still available out side cliped box. So if I click outside iframe it fired iframe click event.
N.B: Because of this approach I want to inject fullscreen ads/video iframes inside page/blog. Where I haven't access to change the page layouts or styling.
Here is my snippet.
document.getElementById("outBtn").addEventListener("click", function() {
alert('clicked outside iframe')
});
(function() {
var splitBoard = document.querySelector('.splitboard');
if (!splitBoard) return;
setTimeout(function() {
var iframeElm = splitBoard.querySelector('iframe');
if (iframeElm) {
var isSafari = navigator.userAgent.indexOf('safari') > -1 && navigator.userAgent.indexOf('chrome') == -1;
if (isSafari) {
function onMouseMove(event) {
var viewportOffset = splitBoard.getBoundingClientRect();
if (!(event.clientY > viewportOffset.top + 15 && event.clientY < viewportOffset.bottom - 15)) {
onMouseleave();
}
}
function onMouseenter(event) {
splitBoard.classList.add('active');
iframeElm.style.pointerEvents = null;
splitBoard.addEventListener('mousemove', onMouseMove, false);
}
splitBoard.addEventListener('mouseover', onMouseenter);
function onMouseleave(event) {
splitBoard.classList.remove('active');
iframeElm.style.pointerEvents = 'none';
splitBoard.removeEventListener('mousemove', onMouseMove);
}
splitBoard.addEventListener('mouseleave', onMouseleave);
}
}
}, 2000);
})();
.wrapper {
width: 500px;
margin: 0 auto;
}
#outBtn {
margin: 10px auto;
display: block;
}
.splitboard {
position: relative;
z-index: 1;
overflow: hidden;
width: 100vw;
margin-left: calc(((100% - 100vw) / 2) - 8px);
-webkit-clip-path: url(#clipSplitBox);
clip-path: url(#clipSplitBox);
}
.splitboard-content {
position: relative;
width: 100%;
height: 100vh;
}
.splitboard-content iframe {
position: fixed;
top: 0;
left: 0;
width: inherit;
height: inherit;
border: none;
}
.splitboard-content iframe {
pointer-events: none;
}
.splitboard-content.active iframe,
.splitboard-content:hover iframe {
pointer-events: all;
}
<div class="wrapper">
<h3>Scroll the page</h3>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Veniam dicta, sit sunt, consectetur beatae, eligendi quaerat cum ipsa laborum officia consequuntur facere ullam veritatis fugiat ipsam doloremque perspiciatis sapiente rem?</p>
<p>Lorem ipsum dolor sit, amet consectetur adipisicing elit. Soluta voluptatem a, ipsa beatae perferendis accusantium labore dolorum distinctio aut dolor, suscipit vel culpa mollitia ratione atque iure hic illo esse.</p>
<div class="splitboard">
<div class="splitboard-content">
<iframe style="background:black" border="0" scrolling="no" srcdoc='<img src="http://themesity.com/wp-content/uploads/templates/dexter/img/background/bg1.jpg" width="100%"><h2 style="color:#fff; position:absolute; top:50%; left:50%; padding:10px; background:rgba(0,0,0,0.5); margin: -20px 0 0 -105px">Click on the image</h2>'></iframe>
</div>
</div>
<svg class="clip-svg" height="0" width="0">
<defs>
<clipPath id="clipSplitBox" clipPathUnits="objectBoundingBox">
<polygon points="0 0.99, 0 0.01, 1 0.01, 1 0.99"></polygon>
</clipPath>
</defs>
</svg>
<button id="outBtn">CLICK HERE</button>
<p>Lorem ipsum dolor sit, amet consectetur adipisicing elit. Expedita suscipit rem modi eveniet ullam quis neque culpa vel, id a asperiores velit quam? Aut deleniti enim ab corporis nam modi!</p>
<p>Lorem ipsum dolor sit, amet consectetur adipisicing elit. Ipsum ipsam excepturi, porro blanditiis libero, expedita iste voluptatibus commodi consequatur deserunt enim quas autem nesciunt recusandae sapiente totam neque mollitia quia.</p>
</div>
Click here to see the full Page result in CodePan
edit JS solution
I have come to with Javascript solution. Hope anybody can give me any other non JS solutions.
Here is my code.
CSS
.splitboard-content iframe {
pointer-events: none;
}
.splitboard-content.active iframe,
.splitboard-content:hover iframe {
pointer-events: all;
}
JS
(function(){
var splitBoard = document.querySelector('.splitboard');
if(!splitBoard) return;
setTimeout(function() {
var iframeElm = splitBoard.querySelector('iframe');
if (iframeElm) {
var isSafari = navigator.userAgent.indexOf('safari') > -1 && navigator.userAgent.indexOf('chrome') == -1;
if (isSafari) {
function onMouseMove(event) {
var viewportOffset = splitBoard.getBoundingClientRect();
if (!(event.clientY > viewportOffset.top + 15 && event.clientY < viewportOffset.bottom - 15)) {
onMouseleave();
}
}
function onMouseenter(event) {
splitBoard.classList.add('active');
iframeElm.style.pointerEvents = null;
splitBoard.addEventListener('mousemove', onMouseMove, false);
}
splitBoard.addEventListener('mouseover', onMouseenter);
function onMouseleave(event) {
splitBoard.classList.remove('active');
iframeElm.style.pointerEvents = 'none';
splitBoard.removeEventListener('mousemove', onMouseMove);
}
splitBoard.addEventListener('mouseleave', onMouseleave);
}
}
}, 2000);
})();

How to center alight content in a div with knowing the height of both parent & child

I have product items to display like this
Now the challenge for me here is vertically middle aligning the text in first & third column, whereas the text in the middle column can increase or decrease reasonably, but i have to keep the content in the left & right column always vertically middle aligned.
e.g here is the code
<div class="product">
<div class="title">My Test Title</div>
<div class="price">
From<br/>
$2500
</div>
<div class="description">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Et blanditiis, quibusdam commodi beatae, dolorum reiciendis, ex veniam esse recusandae iusto sapiente labore quisquam illo deserunt odio non magni velit! Sed.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Et blanditiis, quibusdam commodi beatae, dolorum reiciendis, ex veniam esse recusandae iusto sapiente labore quisquam illo deserunt odio non magni velit! Sed.</p>
</div>
</div>
// AND THE CSS is
.product {
border: 1px solid #CCC;
}
.product > div {
padding : 10px;
border: 1px solid #CCC;
}
.title
{
width : 120px;
float:left;
}
.price {
width:120px;
float:right;
text-align:right;
}
.description {
overflow:hidden;
}
Here is the fiddle : https://jsfiddle.net/exleedo/rexwya5e/
Is there a way to do that without using as display:table-cell; or using javscript to find the height of the parent ?
The reason with using table-cell is because table-cell won't take width anymore from css, and using JS to calculate the height of the parent is not very great I think.
I think I am gonna go with display:table-cell; because that seems the most appropriate one for me. The reason I didn't go with this before is that I was trying to assign width to the table-column div, which is not correct. Now I have add a div inside table-column and assign width there which solves my concern.
e.g here is the code :
<div class="table product">
<div class="table-column">
<div class="title">
The Title
</div></div>
<div class="table-column">
<div class="description">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Porro fugit vero non dolorum, nisi modi veritatis ipsum magni, praesentium blanditiis vel error, odit dolores atque culpa, ratione tempore iusto neque. </p>
</div>
</div>
<div class="table-column">
<div class="price">
Price
</div>
</div>
</div>
// And the CSS
/* Start : CSS Table*/
.table .table-column {
display: table-cell;
vertical-align: middle;
padding-right: 10px;
}
.table .table-column.align-top {
vertical-align: top;
}
.table .table-column.align-bottom {
vertical-align: bottom;
}
.table .table-column.padding-left-10px {
padding-left: 10px;
}
.table .table-column.padding-right-15px {
padding-right: 15px;
}
.table .table-column.padding-right-20px {
padding-right: 20px;
}
.table .table-column.padding-right-40px {
padding-right: 40px;
}
.table .table-column.no-paddings {
padding: 0px;
}
.table .table-column.full {
width: 100%;
}
/* End : CSS Table*/
.product {
border: 1px solid #CCC;
}
.product > div {
padding : 10px;
border: 1px solid #CCC;
}
.title
{
width : 120px;
float:left;
}
.price {
width:120px;
float:right;
text-align:right;
}
.description {
overflow:hidden;
}
Check it in this fiddle : https://jsfiddle.net/exleedo/zL9arsj7/1/