I have 2 cards that overlap ie card A and card B.
When the user puts the mouse over eg card A I want card B to go behind card A and vice versa. when the mouse is over card B card A goes behind. I love the look of the animation this website uses for this and would like to do something similar: Cool Website Example
Although unlike this website I want one of the cards on top of the other upon page load. Also the blur is not necessary.
I realise that this probably utilises z-index somewhere, but what is the easiest way to do this?
This was a quick attempt that half way works.
Card A does not shrink when card B is hovered, because of how the sibling selector works, it only selects elements after, not before. There may be another selector that does it, anyone know?
Thanks for the replies guys!!
Rather than a backward and forth animation, is it possible to have the animation slightly circular-similar to how you shuffle cards? With the initial position being that one card is already overlapping the other?
This is a little too fiddly as B only seems to work when the mouse is hovered on the right edge of A. This whole concept of keyframes is new to meā¦gonna have to do lots of reading up.
P.S. I noticed thereās a floating ā2ā in your .card-wrap:hover .card:hover { rule is that an error?
Yes you will need to tweak for better operation but the basics are there. You lose focus on hover because the element moves out of the way and you could overcome this by nesting an inner element and moving the inner element while the parent stays put and so the effect is continuous.
What would also be easier is to add a class to the parent with JS to trigger the animations and then you can have more control over each block.
Hereās a version that uses jquery to add a class to the parent element when a card is hovered which simplifies the process a little and allows for better animation.
Massive thanks to @SamA74 and @PaulOB for your help with this. I ended reading loads about Animation/Transition and some jQuery before i began to edit/tailor the code samples you guys submitted here. Big thanks guys!!! Ive submitted my tweaked version.
Quick question though as for card shadow for cards with regard to material design are there any good resources to determine:
Shadow Colour based on background? e.g. if a card is to be placed on a very dark navy background what colour should be used for the shadow?
Position and depth(based on layer level) of shadow - eg looking at my codepen card Bās shadow(when on top) probably should be angled differently. A resource on both of these points would be handy.
Also @PaulOB for the benefit of my jQuery learning, I wondered if thereās any reason you used: var theParent = $(this).closest('.card-wrap'); as apposed to var theParent = $(".card-wrap");
You may use coloured shadows if that is the effect that you want, for example, you could give a daylight look by giving the shadow a blue tint. In my pen, I used black shadows with some transparency. The idea being that it would darken whatever colour the background, even if it were multi coloured like an image.
Iām not sure what you mean.
As these are not true 3D shadows, but simulated, they are never going to be 100% accurate. I tried to create the illusion of depth by making the shadows get more transparent, blurred and distant as the card moves closer, away from the background.
Yes .card-wrap would apply to all elements called .card-wrap and not the parent of the element that was hovered. If you only have the one element on the page then this is not an issue but if you had two elements then both would be actioned when you hovered the other one.
Finding the parent of the button that was clicked ensures that the code is modular and re-usable.
Ah that makes it clear!
I only have one element named card-wrap(donāt envisage any more), would you still advise using this method purely to ensure the code is modular and re-usable?
Well you canāt go darker than black, #000 is as for as you can go. So a black shadow would be invisible and any other colour would lighten the shaded area.
If you still wanted to see a shadow, you would make the background a little above black, like #222.