How can I make buttons unclickable until CSS transition is finished? - html

I'm designing a website in plain CSS and HTML, and I was trying to implement a transition similar to this one:
https://codepen.io/fox_hover/pen/wYrvod?editors=1100
My problem is on mobile devices : the link buttons (link and search) are clickable before they become visible, because the transition is simply making them opaque.
I have tried styling the buttons with display:none, pointer-event:none, or visibility: hidden, then making them clickable only once the box is :active or :hover; however it doesn't fix my problem.
While I know this can be easily fixed in Javascript, is there a way fixing the issue using only HTML and CSS (maybe by re-structuring/re-thinking my transition)? Thanks!
<div class="portfolio-item portfolio-effect__item portfolio-item--eff1">
<img class="portfolio-item__image" src=".." alt="Portfolio Item">
<div class="portfolio-item__info">
<div class="portfolio-item__links">
...
</div>
</div>
</div>
.portfolio-item--eff1 .portfolio-item__info {
-webkit-transform: scale(1.1);
transform: scale(1.1);
opacity: 0;
}
.portfolio-item--eff1:hover .portfolio-item__info {
transition-property: all;
transition-duration: 0.4s;
transition-timing-function: linear;
transition-delay: 0s;
-webkit-transform: scale(1);
transform: scale(1);
opacity: 1;
}

If you're trying to not use js then you may have to employ some sort of css-controlled veil.
If you can get a element to sit over the button (all clickable area, probably even at scale(1.1)) then you can likely set it up to 'uncover' when your other transition finishes. You could probably do this with a css animation, though I can't double check right now.
As a general thought, I'd personally think twice about actively stopping users from clicking CTAs due to animation. It's a sure fire way to get users to lose interest in a website when they have to start click buttons a second time after they thought they'd already click it.
If you need more to go on, or it doesn't work, then feel free to comment and try come back and update my answer.
Hope this helps.

I figured it out; I simply needed to add a delay when changing the visibility, using a CSS transition (with the same duration as the actual transition effect).
.portfolio-item--eff1:hover .portfolio-item__links {
visibility: visible;
transition: visibility 0ms 0.3s;
}
.portfolio-item__links{
visibility: hidden;
}

Related

Rotating icon on hover

I am still learning web development and decided to test my skills by making the minecraft.net website again. On one of the links on the main page there is a dropdown menu with an arrow pointed down beside the link. On hover the dropdown menu comes down and the arrow points up. Does anyone know how to code this hover effect for the link and arrow. Also the arrow changes direction and the menu comes down wherever you hover over the link or the arrow beside it. Your help would be much appreciated. Thanks in advance.
img:hover {
-webkit-transform: rotate(-180deg);
-moz-transform: rotate(-180deg);
-o-transform: rotate(-180deg);
}
If this arrow element (div, img etc) has a class e.g. "dropdown-arrow", you could do something like this:
.dropdown-arrow {
transform: rotate(0deg)
transition: transform 0.3s ease-in-out
}
.dropdown-arrow:hover {
transform: rotate(180deg)
}
Setting two transforms will ensure that when you are not hovering, it will return to its normal rotation. The transition will make this rotation smoother, not an instant change.
You can make an on hover event happen in CSS using the :hover psuedoselector. As for rotating your arrow, this using CSS' rotate() function will work:
#arrow:hover {
transform: rotate(180deg);
}
<div id="arrow">▼</div>

Please explain to me how this CSS property removes the trailing lines from a transition

This is a bit of a long-winded question, but I hope someone can break this down for me. I have 2 questions:
Why a CSS property doesn't do what it should.
Why this particular CSS property works on an unsuspecting element, and why it doesn't work on the CSS :hover selector.
Created a flipcard animation. Got some graphics/trailing lines issues with transitions (in Chrome).
Doing some Googling, I found out that apparently, using -webkit-transform: translate3d(0,0,0); is supposed to fix the issue by using hardware acceleration.
However, I couldn't figure out where to place this CSS property. I tried placing it on the .flipcard-container, .flipcard, on the actual transition (.flipcard-container: hover .flipcard).
None of these removed the trailing lines caused by the animation.
Question 1: Where can I use the -webkit-transform: translate3d(0,0,0); properly in order to take advantage of the hardware acceleration, and why does/doesn't it work there?
But, after doing even more Googling and copying someone else's code, I found adding perspective: 600pxto the .flipcard-container somehow fixed the issue. And on top of that, it even makes my animation look really nice.
It shouldn't bother me so much, but it does that I cannot figure out why this worked.
According to the MDN docs:
The perspective CSS property determines the distance between the z=0
plane and the user in order to give a 3D-positioned element some
perspective.
Question 2: Why does this work in my transition so well? Shouldn't I have to place perspective in .flipcard-container: hover .flipcard instead of the .flip-container?
Of course, when placing it in the css :hover selector, the entire transition stops working. Does the perspective property also use hardware acceleration?
Here is the code, and thank you in advance.
.flipcard-container {
height: 400px;
width: 300px;
/* uncommenting the below property will fix the issue */
/* -webkit-perspective: 600; */
}
.flipcard-container:hover .flipcard {
transform: rotateY(180deg) scale(1.5);
}
.flipcard, .front, .back {
width: 100%;
height: 100%;
}
.flipcard {
transform-style: preserve-3d;
transition: all .8s ease-in-out;
}
.front {
background: #6093e5;
position: relative;
backface-visibility: hidden;
}
.back {
background: #e56060;
position: absolute;
backface-visibility: hidden;
top: 0;
transform: rotateY(180deg);
}
<div class="flipcard-container">
<div class="flipcard">
<div class="front"></div>
<div class="back"></div>
</div>
</div>
Question 1
You are overriding the transform: tags with the hardware acceleration. This causes that the animation doesn't work if you put it in.
You can use this, to archive better (more stable fps)
.flipcard-container:hover .flipcard {
transform: rotateY(180deg) scale(1.5);
will-change: -webkit-transition;
will-change: transition;
}
it uses the new will-change property.
More details
The will-change CSS property provides a way for authors to hint
browsers about the kind of changes to be expected on an element, so
that the browser can setup appropriate optimizations ahead of time
before the element is actually changed. These kind of optimizations
can increase the responsiveness of a page by doing potentially
expensive work ahead of time before they are actually required.
Question 2
If you look at e.g. this:
https://codepen.io/jfcorugedo/pen/bBPWaO?q=3d+turn&limit=all&type=type-pens
you see that it also uses the perspective tag. It is used that you can see the rotation of the box (like in your case).
If you remove it, it looks like your code. It works only on the container because the object you want to flip is wrapped in it.
If you have more questions just ask :)

Edge 40/15 opacity/visibility transition event propagation (flickering) bug?

In older versions of Edge, the desired transition effect works correctly.
I am simply animating a div by transitioning opacity/visibility with CSS when its parent's hover event is called.
//LESS
&:hover .inside{
//part that matters:
visibility: visible;
opacity: 1.0;
transition-delay:0s;
}
.inside{
//part that matters:
visibility: hidden;
opacity: 0;
transition: visibility 0s linear 1s,opacity 1s ease;
}
//Pug
.wrapper
.button text
.inside more text
The problem.
In Chrome, IE 11, and Edge 25 the transition is consistent and correct. However, the transition events seem to be stacking up and making the opacity jump back and forth if I hover over or leave the button before the transitions complete naturally.
Here's an example of it: https://codepen.io/vtsells/pen/RZjLYP
Is this a bug or am I missing something? I find it odd that older versions of Edge work correctly
Your transition-delay:0s is causing the problems. Setting it to a very low value should give you a good result: transition-delay: 0.01s
Here's your working codepen.

Overlay effect works with mouse but not with keyboard

Here is my problem. I'm building portfolio page, and now I want to make it easy to navigate for people that can't use the mouse.
What does the outline property do? It provides visual feedback for
links that have "focus" when navigating a web document using the TAB
key (or equivalent). This is especially useful for folks who can't use
a mouse or have a visual impairment. If you remove the outline you are
making your site inaccessible to these people.
I built it so you can navigate all the links on my page using TAB key and you can open that link using ENTER key.
But...
I have nice visual effect with overlay. You can see images of apps, and only when you hover the mouse above that picture you can see links.
So TAB is working and you can select a link using keyboard but you can't see active links, because that overlay effect works only with the mouse (while mouse is hovering above particular picture).
It is hard to explain by words, so I recorded a short video:
https://youtu.be/IQbXL7iyG6w?t=5
Any idea how to fix this? Overlay effect should be tiggered by TAB navigation as well.
GitHub code:
https://github.com/elminsterrr/portfolio
You can do this with a simple jquery code. First change your css
CSS
change this:
#portfolio .inner-content:hover .overlay-content {
top: 0px;
z-index: 1;
background: rgba(0,0,0,0.9);
transition: all 0.5s ease-out;
-webkit-transition: all 0.5s ease-out;
-moz-transition: all 0.5s ease-out;
}
with:
#portfolio .inner-content:hover .overlay-content {
top: 0px;
z-index: 1;
background: rgba(0,0,0,0.9);
}
#portfolio .inner-content .overlay-content.focus_test{
top: 0px;
z-index: 1;
background: rgba(0,0,0,0.9);
}
jQuery:
$('.overlay-content p a').focus(function(){
$(this).parents('.overlay-content').addClass('focus_test');
});
$('.overlay-content p a').blur(function(){
$(this).parents('.overlay-content').removeClass('focus_test');
});
You're showing your overlay on :hover when using TAB the elements get focused, so you have to add the :focus selector to your css for your overlay to show.
.my-class:hover .my-overlay { ... } => .my-class:focus .my-overlay, .my-class:hover .my-overlay { ... }

CSS transition-delay bug in Mac Safari 5.1 -- any workarounds?

I'm experiencing a very annoying bug which appears in Safari 5.1 on Mac. Since this browser is still very common I need to support it.
JSFiddle: http://jsfiddle.net/QCvZt/2/
On clicking a button, a class is added to a containing element #chance. The stylesheet has rules that then cause the clicked element #chance-loose-card to animate away with transitions immediately and then, after a delay, #chance-card animates in.
They fade out and in with opacity, and I flip visibility to hidden when they're totally transparent, since in the full site they might otherwise be over top of things and capturing clicks meant for elements below.
This works very well in Firefox and Chrome (and Safari 6).
But in Safari 5.1 on Mac the first animation is happening as expected but then #chance-card isn't appearing. It's not until I hover over the #carousel element (presumably it's because it triggers another transition -- a button fading in) that #chance-card makes its appearance.
Now, given my assumption that it's to do with another transition being triggered, I tried forcing a transition to happen every second via a Javascript setInterval flipping a class on an element, causing it to transit back and forth. But this did not unfreeze the transition and make #chance-card appear. Transitioning a transform: translate instead of margin-left on the #chance-card doesn't help either.
As noted in the JSFiddle, reducing the transition-delay on #chance-card does make the bug go away, but for my use case this isn't an acceptable solution.
I wonder if anyone can suggest any workarounds? I haven't found anything which sounds similar in my searches.
I found a solution!
http://jsfiddle.net/QCvZt/4/
Changing the transition-delay of the visibility property to just less than the delays of the other properties fixes the issue. So it seems that if transitions are delayed, if visibility is hidden at the time when the transitions start (even if it's going to flip to visible at that same moment), the transitions don't start until somehow triggered (like in this case with the mouse over the grey area, though I don't know exactly the mechanism). Flipping visibility to visible just before the other transitions are due to start makes the problem disappear.
In this case I changed this (vendor prefixes omitted)
#chance.state-chancecard #chance-card {
transition: transform 0.5s, opacity 0.1s, visibility 0s;
transition-delay: 0.5s, 0.5s, 0.5s;
transition-timing-function: ease-out;
transform: none;
opacity: 1;
visibility: visible;
}
to this
#chance.state-chancecard #chance-card {
transition: transform 0.5s, opacity 0.1s, visibility 0s;
transition-delay: 0.5s, 0.5s, 0.49s; /* flip visibility just before other transitions are to start */
transition-timing-function: ease-out;
transform: none;
opacity: 1;
visibility: visible;
}