I was looking at the features page of a web service called Fluxiom. I haven't used the product (although it looks pretty nice and might be good few a couple of our clients). It's the tabs on that page that I thought were pretty neat. As you click a different tab, the three columns of text fly upward at different rates and are replaced by new columns. It looks kinda like a slot machine. I didn't investigate too deeply how they were doing it, but as I often do, I set about recreating the effect with jQuery.
After clicking a new tab the three columns slide away and are replace with new ones at random rates, like a slot machine.
I thought I did OK… although it can definitely be improved. There are also enough interesting things to talk about, so let's get after it.
Find GIFs with the latest and newest hashtags! Search, discover and share your favorite Slot Machine GIFs. The best GIFs are on GIPHY. 3D Slots One of the main goals of reputable casinos is to offer gamblers a realistic and exciting gaming experience. This user experience largely depends on the software the casino uses. Most software is known to provide quality gaming with regard to the images and animation, resulting in excellent 3D sound and graphic features. Once the button is clicked I want to have the venues scroll through with a slot machine spinning animation using CSS3 and jQuery before a venue is selected. I thought about using -webkit-keyframes and changing the background position, but it's not the ideal animation I would like.
HTML
Just going to do a bit of a code dump here so you can see it all.
Important points:
- The whole thing is wrapped in an div with an ID value. Should we convert this idea into a plugin, the idea would be to target this ID and do the magic. But the ID is totally unnecessary for the CSS. That means we could have multiple instances of the slot machine tabs on a single page.
- The 'navigation' (the tabs) are at the top above the content boxes. With styling turned off, this will look like a navigation list like any other. The href values for the links point to the ID's of the content boxes, so the links would jump down the page to the corresponding content. Ideal.
- When there are a lot of closing 's in a row, I like to do the thing where you add a comment afterward to explain which thing this is closing (e.g. )
CSS
The tabs themselves will be like any other horizontal navigation. We'll make the list items inline and the anchors block floated left. Simple borders and backgrounds, and a special state for 'current' (no border and bumped down) and we're set.
Just going to do a bit of a code dump here so you can see it all.
Important points:
- The whole thing is wrapped in an div with an ID value. Should we convert this idea into a plugin, the idea would be to target this ID and do the magic. But the ID is totally unnecessary for the CSS. That means we could have multiple instances of the slot machine tabs on a single page.
- The 'navigation' (the tabs) are at the top above the content boxes. With styling turned off, this will look like a navigation list like any other. The href values for the links point to the ID's of the content boxes, so the links would jump down the page to the corresponding content. Ideal.
- When there are a lot of closing 's in a row, I like to do the thing where you add a comment afterward to explain which thing this is closing (e.g. )
CSS
The tabs themselves will be like any other horizontal navigation. We'll make the list items inline and the anchors block floated left. Simple borders and backgrounds, and a special state for 'current' (no border and bumped down) and we're set.
One somewhat-unsemantic thing we are using is the #box-wrapper div, but whatever it's not that bad and it helps us in a number of ways. For one, it's the the relative positioning container which limits the scope of absolute positioning inside it. We can then absolutely position each content box on top of each other inside.
My favorite part is the box-shadow CSS around the #box-wrapper div. Not only does it help the tabbed area pop up a bit, but it handles the shading on the tabs themselves. The box wrapper sits on top (literally, z-index wise) of the non-current tabs. This is exactly the illusion/visual-metaphor we are going for: the current tab is on top and connected, the non-current tabs are 'behind' (shadow is cast upon them).
Notice we also pull the box up by one pixel with a negative top margin. That makes sure the under-border of the non-current tabs don't make a 2px line but a consistent 1px line.
Another important empowering concept here is that the #box-wrapper has hidden overflow and a set height. The columns in all the content boxes that are non-current are hidden by way of pushing their top value to 350px (a value taller than the height of the box). This pushes them completely out of view because of the hidden overflow. JavaScript will later do the job of pulling up new columns and pushing the old ones out of the way when needed.
The columns:
Notice we only apply right margin to the first two columns. Another way to have done that is to apply the margin to all the columns but use .col:last-child { margin-right: 0; } to remove it. That might be the best way to go if you plan on having a variable number of columns. Just be aware of the lack of pseudo selector support on IE.
jQuery JavaScript
This isn't plugin-ized yet, but it probably could/should be. There are some things I would want to fix/make less redundant before that happens, which I'll cover later. You can view the full commented JavaScript file here.
I'm not going to do a full code dump but I'll cover some interesting lines.
Right away the first tab and the first content box are declared as current. The current content columns are moved to a top position of 0 (so they are visible) rather than the default hidden value from the CSS.
We use the delegate function for the click events on the tabs, since that's so efficient (and could handle dynamic addition of tabs if that came up):
When a click happens, action only takes place if the tab clicked on is not the current tab and there is no other animation taking place on the page. In this limited demo, the only animation possible is the columns. In a more 'real' environment the scope of this test should probably be pared down to inside the slot machine tabs specific ID. Something like $('#slot-machine-tabs *:animated)
I thought it was a more engaging effect if columns didn't change at the same rate each time. I set the speeds pseudo-randomly for each animation, but with a base value of half a second. The speed for the leaving column and entering column match though, so there is no overlapping.
Notice in the demo how all new columns always slide up from the bottom. But as they leave, the slide up to the top. That is accomplished because after the slide-them-up-and-away animation is finished, we instantly move them back down to the default low-and-hidden position. Before doing that, we need to make sure that all animations are completed. I had a slightly hard time doing this. Normally to fire something after an animation, it's no big deal because you can have a callback function on an animation which only fires when the animation is complete. But we are running six different animations here and because they all take a random length of time, we don't know which one is going to end last.
My solution so far is to call the same function on callback on every single finishing animation. For example:
The ifReadyThenReset() function will only do it's thing (reset the column top positions) when it's been called for the third time:
Issues:
- It's not a plugin.
- Each of the columns involved in a tab-changing event is individually animated. That's six things being animated at once and all of them are 'hard-coded'. This makes adding or removing columns more of a chore than it should be.
- The call-the-callback-three-times thing seems kludgey to me, and the hard coded three shares the same problem as above.
Demo & Download
As always, do what you will with this, including use it in a corporate project to impress your boss and use as example of why you deserve a raise.
After creating a Montage and editing the Montage , you will probably want to play your Montage at runtime. You can have your Montage automatically start playing by assigning it to a Skeletal Mesh or, for more flexibility, you may want to set up a Blueprint Script or C++ code that will call your Montage or Sections within your Montage to start playing based on gameplay conditions.
Using Anim to Play on a Skeletal Mesh
In the Details panel for a Skeletal Mesh, you can set the Animation Mode to Use Animation Asset and the Anim to Play to your desired Animation Montage.
At run time, the Skeletal Mesh will playback your selected Animation Montage automatically.
Using Blueprint's Play Montage Node
You can call the Play Montage node within Blueprint (below we tell a Skeletal Mesh called Mesh to play a Montage when the character is clicked on with the Left Mouse Button).
The Play Montage node enables you to not only select what Montage to play but you can also set the Play Rate, Starting Position and Starting Section as inputs.
On the output side, there are several callback events that you can use to trigger other script based on the state of the Montage:
On Completed - called when the Montage finishes playing and is fully blended out.
On Blend Out - called when the Montage is starting to Blend Out, using Blend Out Trigger Time or if the Montage ends.
On Interrupted - called if the Montage is starting to Blend Out, due to interruption by another Montage.
On Notify Begin and On Notify End - are callbacks when using either Play Montage Notify or Play Montage Notify WindowAnim Notifies in the Montage asset.
These Anim Notifies can forward an additional Notify Name to differentiate between multiple callbacks from the same Montage.
In order for the Montage to play, the Skeletal Mesh will need to have its Animation Mode set to Use Animation Blueprint and the Anim Class pointed to an Animation Blueprint.
Inside your Animation Blueprint, on the AnimGraph, you can use the Slot node to define which Slot from the Montage you want to play.
Sloth Animation
See Using Layered Animations for another example of how a Montage can be used inside of your Animation Blueprints.