How to remove blur effect after scale transition? - css

Have a box with some text inside. When I hover it, I want to scale / zoom it bigger with an animation. When the animation ends, the blurred effect is removed from the container. Is there anyway to remove the blur effect after the transition ?
The Code (http://codepen.io/ptongalex/pen/dNZdmV):
.box {
border: solid red 2px;
width: 100px;
position:relative;
text-align:center;
left: 50%;
top:200px;
}
.box:hover {
-webkit-filter: blur(0);
-webkit-transform: translateZ(0);
transform: scale(3);
transition: transform 1s;
}
<div class='box'>
<h1>Text</h1>
</div>

One solution could be to start you box as big and then have it scaled down to your desired size. When you then hover the box you scale it up to 1. This way you prevent the box and its content from being pixelated/blurry when scaling:
.box {
border: solid red 6px;
width: 300px;
position:relative;
text-align:center;
font-size: 54px;
transform: scale(0.33);
margin: 0 auto;
transition: transform 1s;
}
.box:hover {
transform: scale(1);
}
<div class='box'>
<h1>Text</h1>
</div>

This should work.
filter: none;
-webkit-filter: blur(0);
-moz-filter: blur(0);
-ms-filter: blur(0);
filter:progid:DXImageTransform.Microsoft.Blur(PixelRadius='0');
But in some cases the element will be blurred during animation if you use transition.

Related

Can i apply filter: inver(1) with transform-origin in CSS?

I am trying to animate image by filter: invert(1) going from right side to the left side.
filter: invert(1);
transform-origin: right;
Seems to not be working. Is there any easy way to do it?
That's because you aren't changing the image with a transform, you're changing it with a filter. The transform-origin property will not affect a filter in any way, only transforms. If I were you I would try something like my example below. Hover the image to see the effect.
.image-container {
position: relative;
overflow: hidden;
}
.image-container:before {
content: '';
background: white;
position: absolute;
height: 100%;
width: 100%;
mix-blend-mode: difference;
transform: translateX(100%);
transition: 1s ease;
}
.image-container:hover:before {
transform: translateX(0);
}
<div class="image-container">
<img src="https://picsum.photos/id/10/400/300" alt="" />
</div>

Transform-origin issue

I'm trying to rotate object using: transform: rotate(90deg); and applying transform-origin: right bottom;. But there I get different transformation behavior depending on where I place transform-origin: either to parent element or to :hover state.
Why does those differences happens?
div {
width: 100px;
height: 100px;
transition: all 1s ease-in;
}
.main:hover {
transform: rotate(90deg);
transform-origin: right bottom;
}
.main2 {
transform-origin: right bottom;
}
.main2:hover {
transform: rotate(90deg);
}
/*********BG colors*******/
.main, .main2 {
background: green;
}
.wrapper {
background: red;
float: left;
margin-right: 20px;
}
<div class="wrapper">
<div class="main">Transform-origin on :hover state</div>
</div>
<div class="wrapper transform">
<div class="main2">Transform-origin on parent element</div>
</div>
With .main2, you're initializing transform-origin to right bottom, but with .main, you're setting the origin on :hover. Because of this, CSS is trying to tween between the default origin (the center of the element) and right bottom - creating this odd effect.

Transform rotate not working properly in chrome

The following code renders a perfect rotating circle in safari, but not in chrome.
<style>
.circle{
height:1000px;
width:1000px;
background-color:#000;
border-radius: 50%;
}
#-webkit-keyframes rotating {
from{
-webkit-transform: rotate(0deg);
}
to{
-webkit-transform: rotate(360deg);
}
}
.rotating {
-webkit-animation: rotating 2s linear infinite;
-webkit-transform-origin: center;
}
</style>
<div class="circle rotating">
</div>
http://jsfiddle.net/p4ban9cs/
It does not renders perfectly, the problem is visible when rotating a big circle, it's like a wiggling circle on chrome.
thank you for help.
Adding an outer element as a wrapper and apply same styling to it, to mask the inner circle rotation as seen in this Fiddle
<div class="overlay">
<div class="circle rotating">Test</div>
</div>
.overlay{
height:1000px;
width:1000px;
box-shadow:0 0 0 10px #000 ;
background:black;
border-radius: 50%;
}

CSS (or not) animated image it becomes transparent onmouseover and then becomes untransparent again

heyo fellows gotta question, i have to make a picture that gets a bit transparent (like opacity 0,4), then it size increases like 2x and becomes untransparent again (opacity 1)
and the text all that time doesnt change its position.
img {
opacity: 1;
width: 250;
}
img:hover {
opacity: 0.4;
filter: alpha(opacity=40);
width: 500px;
transition-property: width;
transition-duration: 4s;
}
i've made a css code only for size increasing and transparency, however no idea how to make it opacity 1 again after my 4sec animation and no idea how to make the text stay in the very same position after image size increases.
Here is one solution but without more information it's hard to give you the best possible answer. You can only apply effect on hover with css, which means that picture will go back to normal once the picture is not hovered anymore. If you want a solution that will go back to normal automatically after 4s then you should use javascript.
.wrapper {
width: 100%;
}
figure {
display: inline-block;
width: 120px; /* It has to be bigger than twice the size of your picture if you don't want the text to move */
}
img {
width: 50px;
height: auto;
-webkit-transition: width, 0, 4s;
transition: width, 0, 4s;
}
img:hover {
width: 100px; /* twice the original size */
opacity: .4;
}
.text {
display: inline-block; /* so that your text is aligned with picture */
vertical-align: top; /* so that your text doesn't move */
}
<div class="wrapper">
<figure>
<img src="http://lorempixel.com/100/100">
</figure>
<div class="text">
Some text...
</div>
</div>
Hi I did not understand your problem properly. But here I think you wanted something like this.
HTML
<img src="http://t3.gstatic.com/images?q=tbn:ANd9GcTCrT41Zwh43blojDO5tgu1qnsCXbz1Eu6dBiHipmGKjw-oAr7s8Q" alt>
CSS
#keyframes lI{
0%{opacity:1; transform: scale(1);}
50%{opacity:0.4; transform: scale(1.3);}
100%{opacity:1; transform: scale(1.3);}
}
#-webkit-keyframes lI{
0%{opacity:1; -webkit-transform: scale(1);}
50%{opacity:0.4; -webkit-transform: scale(1.3);}
100%{opacity:1; -webkit-transform: scale(1.3);}
}
img{
display: block;
opacity: 1;
transform: scale(1);
-webkit-transform: scale(1);
}
img:hover{
animation: lI 4s linear 1 forwards;
-webkit-animation: lI 4s linear 1 forwards;
}
Please check this Fiddle http://jsfiddle.net/e7zfwncn/1/. It uses CSS3 animation.
Make sure you add your transition in CSS to the img and not hover, then you will get the transition to work on both the mouse in and mouse out.
http://jsfiddle.net/shannabarnard/v7c9y6qj/
HTML
<img src="http://www.w3schools.com/tags/smiley.gif" alt="Smiley face" height="42" width="42">
CSS
img {
opacity: 1;
transition: all 4s ease;
}
img:hover {
opacity: 0.4;
filter: alpha(opacity=40);
width: 84px; /* twice the original size */
height: 84px; /* twice the original size */
}

Have two elements appear when their container is hovered, and then have one disappear when the other is hovered specifically?

I have two navigational elements that are set up as columns on either side of an image. You can see them in place at my website, here. Click on any image and after it loads, hover over it.
What I'm trying to accomplish is as follows:
When the cursor is outside of the image, both nav buttons are set at 0% opacity.
When the image is hovered in the center (not over either of the two nav buttons), both nav buttons are set at 50% opacity.
When either nav button is hovered directly, it is set at 100% opacity and the other nav button is set at 0% opacity.
This isn't working at the moment. HTML is as follows:
<div id="sb-body">
<a id="sb-nav-previous" class="sb-bignav" title="Previous" onclick="Shadowbox.previous()"></a>
<a id="sb-nav-next" class="sb-bignav" title="Next" onclick="Shadowbox.next()"></a>
<div id="sb-body-inner">
<img style="position: absolute;" src="Corrosion.jpg" id="sb-player" height="405" width="609">
</div>
</div>
And CSS is as follows:
#sb-nav-next {
right:0;
background:url('../images/nav-right.png') center center no-repeat;
}
#sb-nav-previous {
left:0;
background:url('../images/nav-left.png') center center no-repeat;
}
#sb-body:hover .sb-bignav {
opacity:0.5;
-webkit-opacity:0.5;
-moz-opacity:0.5;
}
#sb-nav-next:hover #sb-nav-previous,
#sb-nav-previous:hover #sb-nav-next {
opacity:0;
-webkit-opacity:0;
-moz-opacity:0;
}
.sb-bignav {
cursor:pointer;
position:absolute;
width:200px;
height:100%;
top:0;
z-index:400;
opacity:0;
-webkit-opacity:0;
-moz-opacity:0;
transition: opacity .125s ease-in;
-webkit-transition: opacity .125s ease-in;
-moz-transition: opacity .125s ease-in;
}
.sb-bignav:hover {
opacity:1.0;
-webkit-opacity:1.0;
-moz-opacity:1.0;
}​
Demo: http://jsfiddle.net/zNkcQ/
This can be done using pure CSS, but, you need to move the previous and next elements past the inner body element.
Demo: http://jsfiddle.net/SO_AMK/c5Xn3/
CSS:
#sb-body-inner {
height: 405px;
}
/* This is the height of the image inside the slider.
If you do not change this line than #sb-body-inner will be about 20px tall and
will not trigger the hover event */
#sb-body-inner:hover ~ #sb-nav-previous.sb-bignav,
#sb-body-inner:hover ~ #sb-nav-next.sb-bignav {
opacity: 0.5;
}
#sb-nav-previous.sb-bignav:hover,
#sb-nav-next.sb-bignav:hover {
opacity: 1.0;
-webkit-opacity: 1.0;
-moz-opacity: 1.0;
}
.sb-bignav {
cursor: pointer;
position: absolute;
width: 200px;
height: 100%;
top: 0;
z-index: 400;
opacity: 0;
-webkit-opacity: 0;
-moz-opacity: 0;
transition: opacity .125s ease-in;
-webkit-transition: opacity .125s ease-in;
-moz-transition: opacity .125s ease-in;
}
#sb-nav-next {
right: 0;
background: url('http://www.element17.com/images/nav-right.png') center center no-repeat;
}
#sb-nav-previous {
left: 0;
background: url('http://www.element17.com/images/nav-left.png') center center no-repeat;
}​
HTML:
<div id="sb-body">
<div id="sb-body-inner">
<img style="position: absolute;" src="http://www.element17.com/gallery/01_CONSTRUCTS/Shear.jpg" id="sb-player" height="405" width="609">
</div>
<a id="sb-nav-previous" class="sb-bignav" title="Previous" onclick="Shadowbox.previous()"></a>
<a id="sb-nav-next" class="sb-bignav" title="Next" onclick="Shadowbox.next()"></a>
</div>
​
The first problem is the specificity of each selector. The more specific (more points) overrides the less specific (fewer points).
ID: 100 points
Class: 10 points
Element: 1 point
Then, this rule has 110 points:
#sb-body:hover .sb-bignav {
opacity:0.5;
-webkit-opacity:0.5;
-moz-opacity:0.5;
}
Below, the rule has 10 points and is being overwritten by the previous rule with 110:
.sb-bignav:hover {
opacity:1.0;
-webkit-opacity:1.0;
-moz-opacity:1.0;
}​
Try this CSS:
#sb-nav-next {
right:0;
background:url('http://www.element17.com/images/nav-right.png') center center no-repeat;
}
#sb-nav-previous {
left:0;
background:url('http://www.element17.com/images/nav-left.png') center center no-repeat;
}
#sb-body:hover .sb-bignav {
opacity:0.5;
-webkit-opacity:0.5;
-moz-opacity:0.5;
}
#sb-body .sb-bignav:hover {
opacity:1.0;
-webkit-opacity:1.0;
-moz-opacity:1.0;
}
.sb-bignav {
cursor:pointer;
position:absolute;
width:200px;
height:100%;
top:0;
z-index:400;
opacity:0;
-webkit-opacity:0;
-moz-opacity:0;
transition: opacity .125s ease-in;
-webkit-transition: opacity .125s ease-in;
-moz-transition: opacity .125s ease-in;
}
Demo: http://jsfiddle.net/DmAVQ/
​
The second problem is that you can not do the third item only with CSS.
"When either nav button is hovered directly, it is set at 100% opacity and the other nav button is set at 0% opacity."
You need to use JavaScript to do this.
Well, I've exhausted all of my references for a css solution to this problem. The issue is that you'll never get the left nav overlay to become transparent because there is no way to select an element's preceding sibling. I used
#sb-body .sb-bignav:hover ~ .sb-bignav {
opacity: 0;
}
with success on getting the right nav overlay to become transparent, but that's it.
I suggest using jQuery to do this:
OLD
$('.sb-bignav:hover').siblings().css('opacity', 0);
NEW
$('.sb-bignav').hover( function(){
var self = $(this);
self.css('opacity', 1);
self.siblings('.sb-bignav').css('opacity', 0);
}, function(){
var self = $(this);
self.css('opacity', .5);
self.siblings('.sb-bignav').css('opacity', .5);
});
Just an idea...
Maybe you could do it by placing 2 clone navs in your anchor tags...
I made a fiddle:
http://jsfiddle.net/zNkcQ/5/
<div id="sb-body">
<a id="sb-nav-previous" class="sb-bignav" title="Previous" onclick="Shadowbox.previous()">
<span class="sb-img-next"></span>
<span class="sb-img-previous"></span>
</a>
<a id="sb-nav-next" class="sb-bignav" title="Next" onclick="Shadowbox.next()">
<span class="sb-img-previous"></span>
<span class="sb-img-next"></span>
</a>
<div id="sb-body-inner">
<img style="position: absolute;" src="Corrosion.jpg" id="sb-player" height="405" width="609">
</div>
</div>
.sb-img-previous{
left:0;
pointer-events: none;
background:url('http://www.element17.com/images/nav-left.png') center center no-repeat;
}
.sb-img-next{
right:0;
pointer-events: none;
background:url('http://www.element17.com/images/nav-right.png') center center no-repeat;
}
.sb-img-previous, .sb-img-next{
position: fixed;
width: 200px;
height: 100%;
etc...
}
#sb-nav-previous .sb-img-next,
#sb-nav-next .sb-img-previous,
#sb-nav-previous:hover .sb-img-previous,
#sb-nav-next:hover .sb-img-next{
opacity: 0.5;
pointer-events: none; //So each button will not be burdened by its duplicate...
}
#sb-nav-previous .sb-img-previous,
#sb-nav-next .sb-img-next,
#sb-nav-previous:hover .sb-img-next,
#sb-nav-next:hover .sb-img-previous{
opacity: 0;
}

Resources