I want the menu to close in the same duration it takes for it to open. For some reason, there is a delay before closing, along with showing some extra space I have no idea where it comes from.
Here is the jsfiddle: https://jsfiddle.net/m9pd8bjh/7/
Here's the CSS code in case you see something wrong immediately:
.hide {
visibility: hidden;
overflow: hidden;
max-height: 0;
}
input[type=checkbox]:checked~.toggleable {
visibility: visible;
overflow: visible;
max-height: 1000px;
}
.toggleable {
transition: visibility 5s ease-in-out, overflow 2.5s ease-in-out, max-height 2.5s ease-in-out;
}
I'm using a checkbox-label combination to trigger the opening and closing of the menu.
The first thing you need to understand is that the visibility property in CSS cannot be animated. This is due to it only having two states (either visible or hidden, nothing in between to facilitate the animation).
If you want to make a fade-in effect, you can use opacity:0; to opacity:1; and give that a transition instead.
The next thing to note is that your animation time is very long, and if you are animating a max-width, you need to shorten the animation time to adjust.
See fiddle : https://jsfiddle.net/m9pd8bjh/12/
And CSS:
.toggleable {
transition: max-height 0.25s ease-in-out;
}
If you specifically want that long animation timeframe, then you will have to use something other than a max-height solution.
This would then become a new avenue to approach as you would have to use JavaScript, jQuery or some other such framework.
For future reference, here is a fiddle doing the same using jQuery: https://jsfiddle.net/m9pd8bjh/15/
And here is the jQuery code:
$('.toggler').click(function(){
$('.hide').slideToggle();
});
I add another transition when you close the menu and I removed the initial margin of the ul element. Is that effect ok for you ?
CSS code changed
.hide {
visibility: hidden;
overflow: hidden;
max-height: 0;
transition: visibility 0.5s ease-in-out, overflow 0.5s ease-in-out, max-height 0.5s ease-in-out;
}
#menu-main { margin: 0; padding: 10px 40px }
input[type=checkbox]:checked ~ .toggleable {
visibility: visible;
overflow: visible;
max-height: 1000px;
transition: visibility 2.5s ease-in-out, overflow 2.5s ease-in-out, max-height 2.5s ease-in-out;
}
See this fiddle
Related
I am trying to create a transition on a full screen overlay that is full width and full height with nonactive styles of visibility: hidden and opacity: 0. When clicking on a hamburger icon, an .active class is added to the div and it has the following styles: visibility: visible and opacity: 1.
Here is the CSS:
.overlay {
position: fixed;
left: 0;
right: 0;
height: 100%;
width: 100%;
background: '#272727';
z-index: 100;
transition: visibility 500ms ease, opacity 500ms ease;
visibility: hidden;
opacity: 0;
&.active {
visibility: visible;
opacity: 1;
}
}
The transition is occurring as expected on Chrome and Safari but the "fade-in" part of the transition fails on Firefox. It's basically skipping from the first frame to the last frame without transitioning. Here is a link to the page if you want to see it in action: link to webpage
And a video of what is occurring if you are unable to replicate the issue on your browser screen recording:
Why is this transition not working on Firefox?
I think this is due to when the visibility is changed in the transition and seems to display inconsistently between browsers.
This demonstrates your code and for me in Firefox if you toggle the element quickly it does not transition smoothly. This is always how I've done similar transitions and only recently started noticing the problem.
var element = document.querySelector(".element")
var toggle = document.querySelector(".element-toggle")
toggle.addEventListener("click", function(event) {
element.classList.toggle("active");
});
.element{
opacity: 0;
visibility: hidden;
transition: opacity 500ms ease, visibility 500ms ease;
}
.element.active{
opacity: 1;
visibility: visible;
}
<div class="element">This is a div element</div>
<button type="button" class="element-toggle">Toggle</button>
After reviewing, this is what works for me:
var element = document.querySelector(".element")
var toggle = document.querySelector(".element-toggle")
toggle.addEventListener("click", function(event) {
element.classList.toggle("active");
});
.element{
opacity: 0;
visibility: hidden;
transition: opacity 500ms ease, visibility 0s ease 500ms;
}
.element.active{
opacity: 1;
visibility: visible;
transition: opacity 500ms ease, visibility 0s ease 0s;
}
<div class="element">This is a div element</div>
<button type="button" class="element-toggle">Toggle</button>
Seems like visibility doesn't have transition options. So the transition works incorrect.
In .bbfIaB this part
transition: visibility 500ms ease 0s, opacity 500ms ease 0s;
Change to this
transition: opacity 500ms ease 0s;
UPDATED
The best solution in this situation will be next:
Removing visibility from transition in CSS.
Removing visibility: hidden; from .bbfIaB
Add new css class, like .hidden {visibility: hidden;}
Add a JavaScript, which will add .hidden 500ms after removing .active
Class .hidden should be added to the template by default, should be removed with activation of class .active
UPDATE 2
Working example without visibility transition at all.
var element = document.querySelector(".element")
var toggle = document.querySelector(".element-toggle")
toggle.addEventListener("click", function(event) {
if (element.classList.contains("active")) {
setTimeout(function() {
element.style.visibility = '';
}, 500);
} else {
element.style.visibility = 'visible';
}
element.classList.toggle("active");
});
.element{
opacity: 0;
visibility: hidden;
transition: opacity 500ms ease;
}
.element.active{
opacity: 1;
}
<div class="element">This is a div element</div>
<button type="button" class="element-toggle">Toggle</button>
In this example version of my code if you hover over one of the non-faded faces some text appears over it for the duration of the transition and then disappears. If you do the same thing over one of the faded faces the text appears over it for the duration of the transition and then seems to jump to behind everything.
https://www.youtube.com/watch?v=Dx2d2G9pXb8
I have tried altering the z-index of all the elements involved but it seems to have no effect. How do I make it fade from invisible to visible, and then stay there?
This is a cut down version of the important scss
.value-tweet-container {
z-index: 2000;
-webkit-transition: opacity 0.5s ease-in;
-moz-transition: opacity 0.5s ease-in;
-ms-transition: opacity 0.5s ease-in;
-o-transition: opacity 0.5s ease-in;
transition: opacity 0.5s ease-in;
opacity: 0;
&:hover{
opacity: 1;
}
}
To get the overlay to stay, add position: absolute and top: 0 / left: 0.
Like this:
.value-tweet-container {
position: absolute;
box-sizing: border-box; /* Remove if you don't want to cover the entire tile */
top: 0;
left: 0;
height: 100%; /* Remove if you don't want to cover the entire tile */
width: 100%; /* Remove if you don't want to cover the entire tile */
}
Here is your new pen.
The border-box helps as it adds the padding into the height and width percentage calculation and I removed the 3px margin.
If you don't want the tile to be covered by the overlay, remove the lines where indicated.
There are couple of similar questions around. But here's a little change in the case.
I am using CSS3 transition to show a small div in the bottom of the page. When I set the class .show, it slides up and when I remove it, it slides down and goes out of the page.
.bar {
transition: bottom 0.3s ease-out, opacity 0.3s;
opacity: 0;
bottom: -44px;
}
.bar.show {
opacity: 0.85;
bottom: 0;
transition: bottom 0.3s ease-out, opacity 0.3s;
}
My problem is, though it goes away, it still is a display:block element. Which causes my body have scroll. Is there any way by which I can set display:none (using CSS only) after transition? Or some how convince body not to have scroll? (I already have overflow: hidden).
Since transition-delay don't work on display property. I tried visibility, but still the browser keeps some space for scroll.
Update:
Just incase we don't find any good solution, I've done it this way for now instead of display: none.
.bar {
transition: max-height 0s linear 0.3s, bottom 0.3s ease-out, opacity 0.3s;
opacity: 0;
bottom: -44px;
max-height: 0;
overflow: hidden;
border-top-width: 0;
padding: 0;
}
.bar.show {
opacity: 0.85;
bottom: 0;
max-height: 50px;
padding: 5px;
border-top-width: 1px;
transition: bottom 0.3s ease-out, opacity 0.3s;
}
Here's something that could be useful, I've essentially implemented this via position:fixed, check this fiddle to see if it's something that meets your requirements - http://jsfiddle.net/7x0oajv2/
Second approach could be using position:absolute with a overflow:hidden on the body like so - http://jsfiddle.net/7x0oajv2/1/
I would try to set the margin as following:
height of the division = x
margin-bottom: -x;
Not sure if this works but I think it should. Otherwise you might use
position: fixed;
Or the third possible solution would be to not let the division slide out at the bottom but on the left side. This can be done like this:
.bar {
transition: bottom 0.3s ease-out, opacity 0.3s;
opacity: 0;
left: -100px;
}
If you want to change CSS dynamically you must use JavaScript or jQuery to change DIVs property.
E.g
$.("#myDiv").removeClass('displayBLOCK');
$.("#myDiv").addClass('displayNONE');
CSS:
.displayNONE{
display: none;
}
.displayBLOCK{
display: block;
}
If you just want to remove the div, call $.('#myDiv').hide(). You don't need to set display property to "none".
I've gotten an idea to make a search "button" upon clicking which the input box would show up and stretch. However instead of using an invisible checkbox I decided to try and use the label since clicking the label would put focus on the element the label is connected to. And while giving focus and doing basic transformations do work, I can't seem to hide/show the textbox either using visibility: hidden/visible or display: none/inline-block. And I don't want to just rely on opacity since the textbox can be found/clicked even while it's hidden.
Current attempt: JsFiddle
Why doesn't this work? What am I doing wrong?
Elements that are not visible cannot receive focus, therefore the :focus psuedo-class cannot apply.
Using width and opacity seems to produce a reasonable effect.
you can use opacity only, visibility:hidden or display:none; are not suppose to allow focus (IMHO), since element are not visible.
form label {
font-size: 23px;
}
#box {
width: 0px;
opacity:0;
-webkit-transition: 200ms;
-moz-transition: 200ms;
-ms-transition: 200ms;
-o-transition: 200ms;
transition: 200ms;
}
#box:focus {
opacity:1;
width: 50px;
}
http://jsfiddle.net/6h8cF/7/
You can't really get a focus from a label since it is not a focussable element.
See BoltClocks answer here : Anyway to have a label respond to :focus CSS
Fiddle:
http://jsfiddle.net/h6NNs/
Change from :focus to :hover.
Resulting CSS should be:
form label {
font-size: 23px;
}
#box {
width: 0px;
visibility: hidden;
opacity: 0;
-webkit-transition: 200ms;
-moz-transition: 200ms;
-ms-transition: 200ms;
-o-transition: 200ms;
transition: 200ms;
}
#box:hover{
visibility: visible;
opacity: 1;
width: 50px;
}
I am trying to create a nav menu like the one here(http://themes.fuelthemes.net/bouncy/) for practice, and I have come pretty close but mine doesn't quite look (the animation isn't as smooth) as good as the one in the example. The source code is very large and I cannot find how the author creates the animations in the css code or through javascript. Here is what I have so far. Could someone please take a look and tell me what I am doing wrong?
The method I am using to make the menu slide down is by using the max-height property and I am making it fade in with the opacity property.
Bulk of animation code:
.menu > li:hover > ul {
display: block;
-webkit-transition: max-height 0.2s, opacity 0.2s;
-moz-transition: max-height 0.2s, opacity 0.2s;
-ms-transition: max-height 0.2s, opacity 0.2s;
-o-transition: max-height 0.2s, opacity 0.2s;
transition: max-height 0.2s, opacity 0.4s;
max-height: 500px;
-ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=100)";
filter: alpha(opacity=100);
opacity: 1;
}
.dropdown {
max-height: 0;
position: absolute;
list-style: none;
background: #2c2c2c;
margin: 0;
padding: 0;
overflow: hidden;
-ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=0)";
filter: alpha(opacity=0);
opacity: 0;
}
My JSFiddle:
http://jsfiddle.net/cn2fZ/
They aren't using Transistions what the code is is something like this
http://jsbin.com/onituc/1/
or
this http://jsbin.com/onituc/2/edit
Both are different styles
The first one uses the mouseenter and mouseleave functions combined with the delay function. As well as using the fadeIn, we can change the fadeIn to other stuff like
show
slideDown
The second one just uses the slideUp and slideDown functions combined as well with the mouseenter mouseleave
Hope one of these two help you, if you need more help please comment