- This topic is empty.
-
AuthorPosts
-
April 19, 2016 at 8:28 pm #240753kerrinroseParticipant
I’m looking to achieve this effect I mocked up in the pictures below, where an element appears to expand and popout in front of other elements, revealing more information. I don’t really even know where to start, I was hoping someone could point me in the right direction? wasn’t sure whether to post this in css or js as I’m sure it’ll use both
Thanks!
Here is the before state: http://s31.postimg.org/cy64gqk0r/beforestate.png
and after click: http://s31.postimg.org/d0d513hej/afterstate.pngApril 20, 2016 at 2:08 am #240761ShikkedielParticipantYou might be able to do it with CSS but it’ll be a lot easier to control with JS. If you ask me, just add or remove a class when the item is clicked and do a
transform: scale
. But the exact style to be added depends a lot on how you want the enlarged item to look exactly of course.Edit – and you’ll have to show some content that’s initially hidden…
April 20, 2016 at 2:19 am #240762Paulie_DMemberYeah, depends on whether it’s the SAME image expanding or a different image in a modal…sort of a Lightbox effect.
I’d be using JS depending on the effect required (mostly for the clicking) but you could do with the checkbox hack as well I suppose.
April 20, 2016 at 2:36 am #240763ShikkedielParticipantLooking at it again, the image is actually the same size. But that may just be in this example…
April 20, 2016 at 2:18 pm #240782kerrinroseParticipantThanks, I’ve made some progress, here’s a codepen…
http://codepen.io/kerrinrose/pen/Yqvday
two things…I’d like the elements not clicked to stay in place rather than shift over, I’ve tried temporarily adding a position: absolute; to both but they both go to the left corner on top of each other if I do that
and also is it possible for the origin point of the animation to be centered for the center one and expanding out to the left on the right most one? I tried transform-origin for this one to no avail.
Thanks a lot
April 20, 2016 at 4:56 pm #240786ShikkedielParticipantA demo… with cats! Two major selling points we should be able to work with.
:-)
I’d like the elements not clicked to stay in place rather than shift over
Could you maybe explain what you mean by this?
It’s probably a bit more complicated than I initially anticipated on by the way. Let me see what I can put together…
Edit – here’s a first example with some minor adjustments :
April 20, 2016 at 5:47 pm #240787kerrinroseParticipantwow, incredible! thank you, you are a wizard!
April 20, 2016 at 5:56 pm #240788ShikkedielParticipantI fiddled with it some more so an opened item will now automatically resize to small again when another is clicked.
:-)
April 20, 2016 at 6:10 pm #240789kerrinroseParticipantawesome! okay, I actually need this to work for multiple rows where the number of items is not predetermined (it will be populated in on load) any ideas? It looks to me like right now all the items are absolute positioned and a new item will just be under the others?
April 20, 2016 at 8:18 pm #240790ShikkedielParticipantIf the items are in a responsive grid (that’s what I take from that), you’d probably have to go a step further and use a cloned or pseudo element that is absolutely positioned. It’ll always mess with the layout otherwise. Responsive designs are usually not based on
position: absolute
. It’ll likely require more JS to determine if an item has “neighbours” and if so, how many in order to make the enlarged item zoom correctly if it’s on the side of a row.April 22, 2016 at 7:44 am #240815kerrinroseParticipantThanks! With the help of a friend I was able to achieve the effect I was after. Not sure if it’s the most elegant solution but for demo purposes, it works :) Couldn’t have done it without your help, thank you!
April 22, 2016 at 8:19 am #240818ShikkedielParticipantLooks good to me, glad I could help a bit. But since I like code as clean as can be, here’s a slightly sleeker version.
:-)
var i = 0; $('.item').each(function() { i++; i = i%3; if (i == 1) $(this).addClass('left'); else if (i == 2) $(this).addClass('middle'); else $(this).addClass('right'); }); $('.absItem').on('click', function() { var active = $(this).parent().hasClass('index'); if (!active) { $('.scaleTransLeft').removeClass('scaleTransLeft'); $('.scaleTransMid').removeClass('scaleTransMid'); $('.scaleTransRight').removeClass('scaleTransRight'); $('.index').removeClass('index'); } if ($(this).parent().hasClass('left')) $(this).toggleClass('scaleTransLeft'); else if ($(this).parent().hasClass('middle')) $(this).toggleClass('scaleTransMid'); else if ($(this).parent().hasClass('right')) $(this).toggleClass('scaleTransRight'); $(this).parent().toggleClass('index'); });
The
%
here is the modulus operator, quite handy in this case.i = i%3;
-
AuthorPosts
- The forum ‘CSS’ is closed to new topics and replies.