can someone help me to do this hover effect
it is a normal circle
and when passing over it I would like it to look that way and even for the circle to rotate
Thanks in advance
If I understand you correctly, here is one way you could make this work.
There are 3 elements to this; the image, the circle and the gap.
The circle is a div with a border-radius to round it out, and a border with the color of your choice.
The gap is a div that is the full height of the wrapper and the width of the intended gap. The div is given the same color as the background (white in this case - change to whatever you want). Then we apply a transform of -30deg to get the angle in your example.
The image is a div with a border-radius and is positioned in the middle of the wrapper.
The css then makes use of keyframes to add an animation to the gap div to make it rotate when you hover over the wrapper. This gives the illusion of the circle rotating.
.wrapper {
position: relative;
height: 350px;
width: 350px;
}
.wrapper .circle {
position: absolute;
height: 340px;
width: 340px;
border: 5px solid #00C17F;
border-radius: 50%;
}
.wrapper .gap {
position: absolute;
width: 100px;
height: 350px;
left: 125px;
background: white;
-ms-transform: rotate(-30deg);
-moz-transform: rotate(-30deg);
-webkit-transform: rotate(-30deg);
-o-transform: rotate(-30deg);
transform: rotate(-30deg);
}
.wrapper:hover .gap {
display: block;
-webkit-animation: rotateCircle 20s linear infinite;
-moz-animation: rotateCircle 20s linear infinite;
-ms-animation: rotateCircle 20s linear infinite;
-o-animation: rotateCircle 20s linear infinite;
animation: rotateCircle 20s linear infinite;
}
.wrapper .image {
position: absolute;
background-image: url("https://upload.wikimedia.org/wikipedia/commons/f/f2/Light_Work_%28Unsplash%29.jpg");
background-size: cover;
background-position: right;
border-radius: 50%;
top: 10%;
left: 10%;
height: 80%;
width: 80%;
}
#keyframes rotateCircle {
from {
-ms-transform: rotate(-30deg);
-moz-transform: rotate(-30deg);
-webkit-transform: rotate(-30deg);
-o-transform: rotate(-30deg);
transform: rotate(-30deg);
}
to {
-ms-transform: rotate(330deg);
-moz-transform: rotate(330deg);
-webkit-transform: rotate(330deg);
-o-transform: rotate(330deg);
transform: rotate(330deg);
}
}
<div class="wrapper">
<div class="circle"></div>
<div class="gap"></div>
<div class="image"></div>
</div>
You can have just one HTML element. But you need 3 layers:
holds the green circle
holds the image
creates the gaps by overwriting part of the circle
Layer 3 can also be made to rotate on hover.
CSS allows you to attach before and after pseudo elements to elements such as divs (not to normal img elements though, hence we use a div).
This way we have our 3 layers. We use the div itself to display the green circle and above it (in z-index terms) we place a pseudo element which creates the gaps by having a conic gradient background image. This only turns up when the user hovers. The other pseudo element holds the image with z-index set so it is above the others and doesn't get affected by the rotating conic gradient.
Note that all units used here are relative so the code is responsive.
.circle {
--gap: 30deg; /* set this to what you want the gap to be */
--border: 2px; /* set this to what you want the width of the green in the border to be can be in vmin for example for full responsiveness */
position: relative;
border: solid green var(--border);
border-radius: 50%;
width: 50vmin;
height: 50vmin;
margin: 0;
padding: 0;
box-sizing: border-box;
}
.circle::before, .circle::after {
content: '';
border-radius: 50%;
position: absolute;
margin: 0;
padding: 0;
}
.circle::after {
/* position and center the image */
left: 50%;
top: 50%;
transform: translateX(-50%) translateY(-50%);
width: 70%;
height: 70%;
background-image: url(https://picsum.photos/id/0/400/400);
background-size: cover;
border-radius: 50%;
border-style: solid;
z-index: 2;
}
.circle:hover::before {
width: calc(100% + (3 * var(--border)));/* make it slightly bigger to make sure a 'stray' screen pixel does not get left out when the system converts part CSS px to screen pixels */
height: calc(100% + (3 * var(--border)));
top: calc(-1.5 * var(--border));
left: calc(-1.5 * var(--border));
z-index: 1;
background-image: conic-gradient(white 0deg, white var(--gap), transparent var(--gap), transparent 180deg, white 180deg, white calc(180deg + var(--gap)), transparent calc(180deg + var(--gap)), transparent 360deg);
animation: rotate 2s infinite linear;
}
#keyframes rotate {
to {
transform: rotate(360deg);
}
}
<div class="circle"></div>
Related
.rotate {
display: block;
width: 64px;
height: 64px;
border: 2px black dashed;
animation: rotate 40s linear infinite;
border-radius: 50%;
transform: scale(1.8);
position: relative;
top: 50px;
left: 50px;
}
#keyframes rotate {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
<div class="rotate"></div>
if you take a look at the fiddle, the "transform: scale(1.8);" didn't work. Is there any other alternatives to make the border bigger?
There you go. The transform isn't working when you're trying to scale in the initial rotate class is because, its gradually changing because of the rotating animation. You have to fix/scale the width or height initially and your border size then apply the animation on it as shown.
.rotate {
display: block;
width: 115px;
height: 115px;
border: 4px black dashed;
animation: rotate 40s linear infinite;
border-radius: 50%;
position: relative;
top: 50px;
left: 50px;
}
#keyframes rotate {
0% {
transform: rotate(0deg);}
100% {
transform: rotate(360deg);
}
}
<div class="rotate"></div>
Not that hard really. Increase the height and width manually and increase the border-width.
.rotate {
display: block;
width: 115px;
height: 115px;
border: 4px black dashed;
animation: rotate 40s linear infinite;
border-radius: 50%;
position: relative;
top: 50px;
left: 50px;
}
#keyframes rotate {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
<div class="rotate"></div>
I am trying to make a CSS animation (i can't use javascript) with these steps:
Have a div of which you can't know in advance its position or size (in the fiddle i have set the size for testing)
The div gets resized (width 100% height 50 pixels) and moves to the top of the page while its content disappears
The div turns into a circle and moves to the center of the page
This is what i have attempted so far:
https://jsfiddle.net/v3bt1mar/5/
.turning {
width: 80%;
height: 120px;
background-color: #00FF00;
}
.turning:active {
background: red;
animation: 10.5s;
display: block !important;
position: fixed;
content: "";
overflow: hidden;
animation: resizeList 10.5s forwards;
}
.turning:active * {
animation: fadeContent 1s forwards;
}
#keyframes fadeContent {
0% {
opacity: 1;
}
50% {
opacity: 0;
}
100% {
opacity: 0;
}
}
#keyframes resizeList {
25% {
width: 100%;
height: 50px;
top: 10px;
left: 0%;
// transform: translate(0%, 0%) rotateY(0deg);
border-radius: 0%;
}
100% {
border-radius: 50%;
top: calc(50% - 50px);
left: calc(50% - 50px)";
// transform: translate(~"calc(50vw - 50px)", ~"calc(50vh - 50px)") rotateY(180deg);
transform: rotateY(180deg);
width: 100px;
height: 100px;
}
}
But it's still far from what i am expecting.
On Mozilla it doesn't move vertically, on Chrome it does move but not smoothly (just at every keyframe, apparently)
Then i don't know why it moves back to the left rather than to the center of the page
On top of that it works differently on Mozilla and Chrome (on Mozilla it doesn't move to the top, on Chrome it does but not smoothly)
If you add position:absolute; to .turning and remove the rotate transformation in the keyframe, the animation does what you are describing: https://jsfiddle.net/v3bt1mar/7/
Change:
100% {
border-radius: 50%;
top: calc(50% - 50px);
left: calc(50% - 50px)";
// transform: translate(~"calc(50vw - 50px)", ~"calc(50vh - 50px)") rotateY(180deg);
transform: rotateY(180deg);
width: 100px;
height: 100px;
}
To:
100% {
border-radius: 50%;
top: calc(50% - 50px);
left: 50%;
// transform: translate(~"calc(50vw - 50px)", ~"calc(50vh - 50px)") rotateY(180deg);
transform: rotateY(180deg);
width: 100px;
height: 100px;
}
This will keep image at center. Also try adding keyframes for 50% and 75% transition. That should smooth out the transition a bit.
The actual issue was that it was copied from a less file and it contained single line comments which are not allowed into normal CSS. On top of that i had left calc as a string so that LESS won't sum the values while parsing
With a few adjustments taken from the other answers i managed to fix the animation the way i wanted (the rotate was intended, i just didn't think it was worth mentioning)
https://jsfiddle.net/v3bt1mar/12/
.turning {
width: 80%;
height: 120px;
background-color: #00FF00;
}
.turning:active {
background: red;
display: block !important;
position:fixed;
overflow: hidden;
animation: resizeList 1s forwards;
top:calc(50% - 50px);
left: 0;
}
.turning:active * {
animation: fadeContent 1s forwards;
}
#keyframes fadeContent {
0% {
opacity: 1;
}
50% {
opacity: 0;
}
100% {
opacity: 0;
}
}
#keyframes resizeList {
25% {
width: 100%;
height: 50px;
top: 10px;
left: 0%;
border-radius: 0%;
transform: rotateY(0deg);
}
100% {
border-radius: 50%;
top: calc(50% - 50px);
left: calc(50% - 50px);
transform: rotateY(180deg);
width: 100px;
height: 100px;
}
}
I have a circle that expands using CSS keyframes, with fixed positioning. The trouble is, as the circle changes size, the centre of the circle moves (whilst the top left corner remains fixed). How do I ensure the centre is fixed during the animation? Is there a way to specify the "origin" of the div so that's it's not the top left?
<div id="circle"></div>
and
#circle {
position: fixed;
background: #07F;
border-radius: 50%;
animation: expand linear 3s infinite;
top: 10px;
left: 10px;
}
#keyframes expand {
0% {
width: 100px;
height: 100px;
}
100% {
width: 500px;
height: 500px;
}
}
See this JSFiddle
Another option, what you can do is use transform - scale property to increase dimensions and then transform-origin to keep it centered:
#circle {
position: fixed;
background: #07F;
border-radius: 50%;
animation: expand linear 3s infinite alternate;
top: 10px;
left: 10px;
transform-origin: center;
width: 100px;
height: 100px;
}
#keyframes expand {
0% {
transform: scale(1);
}
100% {
transform: scale(5);
}
}
<div id="circle"></div>
try this:
#circle {
position: fixed;
background: #07F;
border-radius: 50%;
animation: expand linear 3s infinite alternate;
top: calc(10px + 50px); /* 10px + (half of the initial height) */
left: calc(10px + 50px); /* 10px + (half of the initial width) */
transform: translate(-50%, -50%)
}
#keyframes expand {
0% {
width: 100px;
height: 100px;
}
100% {
width: 500px;
height: 500px;
}
}
<div id="circle"></div>
I have created an animation where a background image moves from left to the right. I want this animation to go diagonal so I've turned the div 45 degrees using: -webkit-transform: rotate(45deg);
The result looks like this fiddle
As you can see, the div is turned (red border), but I want the div not to rotate. So how can I keep the diagonal animation without rotating the div?
Thanks
ps for demo purposes I've only used the -webkit- prefix
ps2 I can only modify one div with the css, so adding another div is
not possible
You can use pseudo elements to accomplish what you want:
html:
<div id='test'></div>
css:
#test:before
{
content: "";
position: absolute;
width: 200%;
height: 200%;
top: -50%;
left: -50%;
z-index: -1;
background: url(background.png) 0 0 repeat;
-webkit-transform: rotate(30deg);
-moz-transform: rotate(30deg);
-ms-transform: rotate(30deg);
-o-transform: rotate(30deg);
transform: rotate(30deg);
background-image: url("http://www.easyvectors.com/assets/images/vectors/afbig/green-left-double-arrows-set-clip-art.jpg");
background-repeat: repeat;
-moz-animation: swim 2s linear 0s infinite;
-webkit-animation: swim 2s linear 0s infinite;
-webkit-transform: rotate(45deg);
}
#test {
position: relative;
overflow: hidden;
width: 300px;
height:300px;
border: 3px solid red;
}
#-webkit-keyframes swim {
from { background-position: 200% 0, 0 0; }
to { background-position: 100% 0, 0 0; }
}
Fiddle
Check out this great article by Craig Buckler for more information.
My CodePen: http://codepen.io/leongaban/pen/wJAip
The orange gear is 80x80 and so is the white # logo.
I added the blue background so you can see that for some reason the orange gear looks like it is spinning off center.
Here is the image lined up in photoshop:
html:
<div id="spinner">
<div id="logo">
<img src="http://leongaban.com/_codepen/whoat/loader-logo.png"/>
</div>
<div id="gear" class="spin">
<img src="http://leongaban.com/_codepen/whoat/loader-gear.png"/>
</div>
</div>
CSS:
div#spinner {
position: absolute;
width: 80px;
height: 80px;
top: 35%;
left: 50%;
margin-left: -40px;
background: blue;
}
div#logo {
position: absolute;
top: 0;
left: 0;
width: 80px;
height: 80px;
z-index: 3;
}
#logo img {
width: 100%;
height:100%;
}
div#gear {
position: absolute;
top: 0;
left: 0;
-webkit-transition: -webkit-transform 0.1s;
transition: transform 0.1s;
-webkit-transform: translateX(100%) translateY(-100%) rotate(45deg);
transform: translateX(100%) translateY(-100%) rotate(45deg);
pointer-events: none;
z-index: 2;
}
.spin {
-webkit-animation: rotation 4.5s linear infinite;
animation: rotation 4.5s linear infinite;
-webkit-transform: translateX(100%) translateY(-100%) rotate(45deg);
transform: translateX(100%) translateY(-100%) rotate(45deg);
}
Make the image in the #gear div block level.
#gear img{
display:block;
}
http://codepen.io/anon/pen/rjfbl
For whatever reason your gear element is getting a height of 84px. This will cause it to spin off-axis. As an experiment you might wish to try setting height and on #gear to something very small (e.g. 0px) and watching it; it will be as though it's rotating around a point at the top of its bounding box.
Set the width and height of your gear explicitly to 80x, or 100%, and it will work.
div#gear {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
-webkit-transition: -webkit-transform 0.1s;
transition: transform 0.1s;
pointer-events: none;
z-index: 2;
}
Codepen (yours with the two added lines, width and height): http://codepen.io/anon/pen/LuBvI