How can i create this animation on this website:
https://www.beepi.com/
When you hover on the blue and green circle makes that animation, i want to do the same with this design:
What should i use and do it? Any tutorials, guides, something ? That i can see and be capable to implement it on my site.
I tried to make that effect. Here's what I've done:DEMO JsFiddle.
function js1(x) {
x.style.animation = "anime 5s";
}
function js2(x) {
x.style.animation = "anime1 5s";
}
#first {
position: absolute;
float: left;
width: 100px;
height: 100px;
background-color: black;
top: 200px
}
#sec {
position: relative;
float: right;
width: 100px;
height: 100px;
background-color: black;
top: 200px
}
#Keyframes anime {
from {
left: 0;
}
to {
left: -400px;
}
}
#Keyframes anime1 {
from {
left: 0;
}
to {
left: 400px;
}
}
<div id="first" onmouseenter="js1(this)"></div>
<div id="sec" onmouseenter="js2(this)"></div>
Fell free to use the code. Now You must only resolve the problem with scroll(the page must go left-I don't know how to do that but I'll try).
I used javascript and onmouseenter to create the hover part. You can read about onmouseenter here and about #Keyframes here.
Related
Codepen link: https://codepen.io/lolcatBH/pen/OJbgLyd
I have the following html:
<div id="page">
<div class="overlay"></div>
<div class="click">SHOW POPUP</div>
<div class="popup">
<h1>Korean language</h1>
<button class ="close">X</button>
<div class="desc">Korean (North Korean: 조선말/朝鮮말, chosŏnmal; South Korean: 한국어/韓國語, hangugeo) is an East Asian language spoken by about 77 million people.</div>
</div>
</div>
And CSS:
#page {
position: absolute;
top: 50%;
left: 25%;
}
.popup {
width: 300px;
height: 300px;
border: 1px solid black;
z-index: 1;
position: absolute;
top: -10%;
transform: scale(0);
padding: 20px;
}
#page .overlay {
position: fixed;
top: 0px;
left: 0px;
width: 100vw;
height: 100vh;
background: rgba(0,0,0,0.7);
z-index: 1;
display: none;
}
#page.active .overlay {
display: block;
}
.popup.active {
transform: scale(1);
background-color: white;
}
.close {
position: absolute;
right: 0%;
top: 0%;
color: white;
background: black;
border-radius: 50%;
}
.click {
border: 1px solid black;
padding: 20px;
font-size: 20px;
text-align: center;
z-index: 0;
cursor: pointer;
}
h1, desc {
text-align: center;
}
JS:
const click = document.querySelector('.click');
const x = document.querySelector('.close');
const page = document.querySelector('#page');
const popup = document.querySelector('.popup');
const showPopup = () => {
page.classList.toggle('active');
popup.classList.add('active');
}
const hidePopup = () => {
page.classList.toggle('active');
popup.classList.remove('active');
}
click.addEventListener('click', showPopup);
x.addEventListener('click', hidePopup);
At first, what I tried to do is instead of creating a separate overlay div, I was going to put a background color on the #page element. However, in effect, the background only applies to the button element (.click). I don't actually understand why in this case, since the background-color doesn't seem to affect the .popup element.
Imgur: https://imgur.com/a/UEgXSlY
So my question is, why does the #page element not cover all of its children's width and height? In this case, I thought it would have cover the whole page. I've also tried putting width: 100vw and height:100vh but it in turn only applied the dimensions to the button.
Imgur: https://imgur.com/a/QOMlnTs
The reason is that most of your elements have position set to absolute or fixed, which makes them completely (fixed) or partly (absolute) independent from their parent, i.e. there is no space of its own reserved for them, therefore they typically overlap other elements.
So the parent doesn't span or cover them, but only those elements which don't have a set position or which have position: relative or static.
I have an idea for an Ajax-loader.
This is what I have accomplished so far:
body {
background-color: lightGrey;
counter-reset: h1-counter;
}
.wrap {
max-width: 200px;
height: 50px;
margin: 50px auto;
position: relative;
overflow: hidden;
}
.wrap div {
background: linear-gradient(#0032f0, white, #0032f0);
position: absolute;
width: 100%;
height: 100%;
z-index: 1000;
opacity: .8;
}
.wrap div.dark-bar {
position: absolute;
width: 10%;
height: 100%;
animation: moveDarkBar 3s linear infinite;
z-index: 1;
}
#keyframes moveDarkBar {
from {
left: -20%;
}
to {
left: 120%;
}
}
<div class="wrap">
<div></div>
<div class="dark-bar"></div>
</div>
I want the moving indicator (.dark-bar) to be "melted" with foreground-div. Currently there is a hard line which is visually distinguishable.
Is there a way to get the moving indicator (.dark-bar) to be blurred on the left-, right edge?
You could make use of CSS filter to add blur to top layer which is animated as below,
filter - The filter property provides graphical effects like blurring,
sharpening, or color shifting an element. Filters are commonly used to
adjust the rendering of images, backgrounds, and borders.
Do include vendor prefixes for other browsers such as -webkit-,-o-,-moz-,-ms- to filter.
body {
background-color: lightGrey;
counter-reset: h1-counter;
}
.wrap {
max-width: 200px;
height: 50px;
margin: 50px auto;
position: relative;
overflow: hidden;
}
.wrap div {
background: linear-gradient(#0032f0, white, #0032f0);
position: absolute;
width: 100%;
height: 100%;
z-index: 1000;
opacity: .8;
}
.wrap div.dark-bar {
position: absolute;
width: 10%;
height: 100%;
animation: moveDarkBar 3s linear infinite;
z-index: 1;
-webkit-filter:blur(2px); /*Add this*/
}
#keyframes moveDarkBar {
from {
left: -20%;
}
to {
left: 120%;
}
}
<div class="wrap">
<div></div>
<div class="dark-bar"></div>
</div>
Try using the box-shadow property and set the vertical and horizontal axis values to 0. Something like this:
div {
box-shadow: 0 0 10px black;
}
This might be a similar effect for the one you want.
Please consider following example.
Div which is the shape of ball does move but its sudden movement rather I want it to transition diagonally across the page to the bottom right corner. Why isn't that happening? What did I miss?
.one {
background: green;
height: 100px;
width: 100px;
position: absolute;
border-radius: 100px;
transition: all 1s ease;
}
.one:hover {
background: red;
bottom: 0px;
right: 0px;
}
<div class="one"></div>
For transition to happen, you need values on both the parent and hover element selectior.
Here i just added proper values to both the selectors , and by subtracting their heights easily.
.one {
background: green;
height: 100px;
width: 100px;
position: absolute;
border-radius: 100px;
transition: all 1s ease;
top: 0%;
left: 0%;
}
.one:hover {
background: red;
top: calc(100% - 100px);
left: calc(100% - 100px);
}
<div class="one"></div>
These will work with most modern browsers . Also you can use pollyfill to make it work with backward browsers
For transition to happen, you need values on both the selectors.
Here in your case, the parent selector did not have any values of bottom or of left, but if you look at my code, both the parent and hover selectors have top and left value.
We just need to specify value so browser knows that where to start from
you can try by giving these to hover state
top:100%;
left:100%;
margin-top:-100px;
margin-left:-100px;
check the codepen here http://codepen.io/raomarif/pen/RGNpNm?editors=1100
Just to give you an more complex example which does the transition on hover but continues it no matter where the mouse is + is reversible.
var toggleClass = true;
var totalSeconds = 0;
var transitionTime = 1000; /* In milliseconds */
function mouseOver(element) {
if (totalSeconds === 0) {
var myTimer = setInterval(function() {
countTime()
}, 100);
}
function countTime() {
++totalSeconds;
console.log(totalSeconds);
if (totalSeconds >= (transitionTime / 100)) {
stopTime();
totalSeconds = 0;
toggleClass = true;
} else {
toggleClass = false;
}
}
if (toggleClass) {
element.classList.toggle('moved');
}
function stopTime() {
clearInterval(myTimer);
}
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
}
.one {
position: absolute;
background: green;
height: 100px;
width: 100px;
top: 0;
left: 0;
border-radius: 100px;
transition: all 1000ms ease-in-out;
}
.one.moved {
top: 100%;
left: 100%;
margin-top: -100px;
margin-left: -100px;
transition: all 1000ms ease-in-out;
}
<div class="one" onmouseover="mouseOver(this)"></div>
This example requires Javascript. There's some checks to see if the transition is complete so hovering the circle again won't reverse the transition etc.
JSFiddle to play around with
I have 3 overlapping html divs, one next to another, colored: red, green and blue. All elements have opacity 0.5. First two divs (red and green) I want to summate color (creates something between red and green) - standard behaviour, without changes here.
My problem is how to prevent summating colors only between green and blue divs?
It would be great if we could do this without additional elements.
html:
<div id="d0"></div>
<div id="d1"></div>
<div id="d2"></div>
css:
div {
position: absolute;
opacity: 0.5;
}
#d0 {
top: 60px;
height: 100px;
left: 50px;
width: 100px;
background-color: red;
}
#d1 {
height: 150px;
left: 130px;
top: 50px;
width: 200px;
background-color: green;
}
#d2 {
height: 100px;
left: 300px;
top: 80px;
width: 120px;
background-color: blue;
}
EDIT:
I forgot about: http://plnkr.co/edit/5MIduRMFo0dZ54xqzpAa?p=preview
It should look likt this (fourth element is to show that blue also has opacity):
If you want to keep opacity of all divs to be still 0.5. Then here is your pure CSS solution. No additional elements added.
Here is a fiddle for that.
http://jsfiddle.net/tdh7ks2x/2/
**HTML**
<div id="d0"></div>
<div id="d1"></div>
<div id="d2"></div>
<div id="d4"></div>
**CSS**
#d2 {
opacity: 1;
height: 100px;
width: 120px;
left: 300px;
top: 80px;
}
#d2:before,
#d2:after{
content: "";
position :absolute;
left: 0;
top: 0;
height: 100px;
background-color: blue;
}
#d2:before{
width: 30px;
z-index: 2;
opacity: 0.99999999;
background-color: #7F7FFF;
}
#d2:after{
width: 120px;
z-index: 1;
opacity: 0.5;
}
#d4 {
width: 200px;
height: 80px;
left: 400px;
top: 90px;
background-color: red;
}
Just added this CSS instead of #d2, rest all your CSS is fine. Let me know if this resolves your issue.
Pick the color of the div with opacity and use it in the ":before" div.
You can use z-index property to bring a div to front or back. Higher the value of z-index to move it to the top and decrease it to move it back.
Moreover you have used opacity:0.5 due to which you will see the back colors at the intersection. You must increase the opacity to see the exact colors there
div {
position: absolute;
opacity: 0.5;
}
#d0 {
top: 60px;
height: 100px;
left: 50px;
width: 100px;
background-color: red;
z-index:2
}
#d1 {
height: 150px;
left: 130px;
top: 50px;
width: 200px;
background-color: green;
}
#d2 {
height: 100px;
left: 300px;
top: 80px;
width: 120px;
background-color: blue;
}
<div id="d0"></div>
<div id="d1"></div>
<div id="d2"></div>
css:
Basically, this problems occurs due to overlapping transparent colors. Example is rgba(255,255,255,0.3) overlapping with rgba(255,255,255,0.3) to form a brighter color.
If your design can do without transparent colors, you can easily solve this by converting your transparent colors (rgba) to fully opaque ones (hex) for related elements.
You will need the background color to help compute a fully opaque hex from rgba or just use a color picker browser extension after rendering.
Im having some trouble getting an image back to the front.
So basically this is my code segment:
<itemimg>
<img src="images/table1.jpg" />
<img src="images/table1-side.jpg">
</itemimg>
The second a href which links table1-side.jpg is overlapping thetable1.jpgbut i want it the other way around.table1.jpg` should be on top.
The css that affects this part is here:
itemimg {
display: block;
width: 200px;
height: 200px;
}
itemimg img:nth-child(1) {
z-index: 9999;
}
itemimg img:nth-child(2) {
z-index: 0;
}
itemimg img {
position: absolute;
border-top-left-radius: 5px;
border-top-right-radius: 5px;
width: 200px;
height: 200px;
}
itemimg a {
display: block;
position: absolute;
cursor: zoom-in;
}
I tried (as you can see), to send the second image to the back with z-index but it isnt doing it. I even tried messing with the position property on the itemimg img to see if it will re-arrange them. I even switched them around in the HTML so one is on top and it does work BUT i am using Lightbox and when i arrange the HTML to where the table1.jpg is on top, the navigation in Lightbox is backwards (as in i have to press the left arrow to go backwards instead of forwards to see the images). <- i know this might be confusing but take a look at it for yourself here. Click on the table to bring up Lightbox and you have to navigate backwards in the slideshow NOT forwards, which is what i dont want. So i figured if i can get the table1.jpg
on top, it will go forwards as i want it to and thats what im having trouble with.
Really need help here, Thanks in advance!
SOLUTION:
For people who wanted to know the solution. Depending on your scenario the below answers work great. I, however wanted to avoid using inline css and classes so i implemented my images into an ul and set the 2nd li's z-index to -1 as such:
HTML
<itemimg>
<ul>
<li><img src="images/table1.jpg" /></li>
<li><img src="images/table1-side.jpg" /></li>
</ul>
</itemimg>
CSS
itemimg {
display: block;
width: 200px;
height: 200px;
}
itemimg ul {
position: absolute;
list-style: none;
padding: 0;
margin: 0;
}
itemimg li {
width: 200px;
height: 200px;
position: absolute;
}
itemimg ul li:nth-child(2) {
z-index: -1;
}
itemimg img {
position: absolute;
border-top-left-radius: 5px;
border-top-right-radius: 5px;
width: 200px;
height: 200px;
}
itemimg a {
display: block;
position: inherit;
cursor: zoom-in;
}
My website is updated with the end result so go and take a look!
The problem lies on the 2nd z-index. Make it -1 like this:
itemimg {
display: block;
width: 200px;
height: 200px;
}
itemimg img:nth-child(1) {
z-index: 9999;
}
itemimg img:nth-child(2) {
z-index: -1; //make this -1
}
itemimg img {
position: absolute;
border-top-left-radius: 5px;
border-top-right-radius: 5px;
width: 200px;
height: 200px;
}
itemimg a {
display: block;
position: absolute;
cursor: zoom-in;
}
The z-index for both images is 9999.
Solution 1:
Hard code one of them in the HTML.
<itemimg>
<img src="images/table1.jpg" style="z-index:10000"/>
<img src="images/table1-side.jpg">
Solution 2:
Give the front image a id and name it something like "frontImage" then add
.frontImage {
z-index:10000;
}