I am trying to achieve the effect for text background as image. Image should be with parallax effect.
I tried below code but not able to work like how I want. Please suggest the best solution with CSS / JS whichever is better for this case.
Is there any alternatives avail to do this or any tricks I even tried masking, but not achieved goal.
Code Below
let mouseX, mouseY, trackX, trackY;
document.addEventListener("wheel", function (e) {
mouseX = e.pageX;
mouseY = e.pageY;
trackX = (4 * mouseX / 170) + 40;
trackY = (4 * mouseY / 170) + 50;
document.querySelector(".title").style.backgroundPosition = `${trackX}% ${trackY}%`
});
* {
padding: 0;
margin: 0;
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 200vmin;
font-size: 100%;
font-family: 'Anton', sans-serif;
}
body {
background: #1e5abc;
}
.hero {
background: linear-gradient(rgb(235, 236, 231), rgb(255, 255, 255));
height: 100vh;
width: 100%;
display: flex;
flex-wrap: wrap;
position: relative;
clip-path: polygon(0% 0%, 100% 0%, 100% 85%, 50% 100%, 0% 85%, 0% 0%);
}
.container {
flex: 1 1 50%;
display: flex;
justify-content: center;
align-items: center;
}
.right-side-container {
flex: 1 1 50%;
clip-path: url(#clipPath);
}
.title {
background: url("https://images.unsplash.com/photo-1470813740244-df37b8c1edcb?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=2b76b1e6da83c1a0f59eebaa481e12aa&auto=format&fit=crop&w=751&q=80") center no-repeat;
background-position: 40% 50%;
-webkit-background-clip: text;
color: transparent;
text-transform: uppercase;
letter-spacing: 0.1em;
line-height: 1.3em;
text-anchor: middle;
alignment-baseline: hanging;
font-size: calc(12px + 6.2vw);
text-align: center;
}
.subtitle {
text-align: center;
letter-spacing: 0.35em;
font-size: 1.5vw;
color: #2b2b2b;
}
img {
height: 100%;
width: 100%;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="hero">
<div class="container">
<div class="header-container">
<br><br><br>
<br><br><br>
<div class="title">
I'm Travis.<br>
Developer.
</div>
<div class="subtitle">
<p>Frontend - backend - everything</p>
</div>
</div>
</div>
<div class="right-side-container">
</div>
</div>
2
Answers
put this line in css
Please let me know this is what you are looking for