How do I animate this? jquery

I’m a novice at jquery (or maybe just a beginner).

I have this page - (content has been removed so ignore the broken menu and empty areas)

I only need help with the portion that says, “Target at scale…” and has floating people.

Right now on hover, the profile images change along with the background image. I need the profile images to animate in a way where their name remains in place (animators, photographers, etc) and the image quickly fades into the next and fades out when you move away. Right now it’s jumpy. I’m not sure how to approach it.

I tried to animate it and do some things but i really couldn’t get right.


Hey rpeg,

The trick here is to, rather than swap the images out like you’re currently doing, to have both images on the page and then fade from one to the other.

I’ve knocked up a quick demo on JS Fiddle:

The basics are:

<div class="pic">
    <img src="" alt="" class="on" />
    <img src="" alt="" class="off" />

Just basic markup - a container that will be relatively positioned, then we absolutely position the images inside of it.

.pic { /* pic container */
    position: relative;
    float: left;

.pic img  { /* pics are absolutely positioned so their content can overlap exactly */
    position: absolute;
/* if you need to, you can position the off or on image slightly differently so that things line up better */

.pic { /* hide the "off" state by default */
    display: none;

so, css is pretty basic as well - no need for it to be too complicated :slight_smile:

    //monitor the mouseenter/leave events
    $(".pic").on("mouseenter mouseleave", function(e){
        //make sure we're showing/hiding the correct els
        var showEl = e.type === "mouseenter" ? ".off" : ".on",
            hideEl = e.type === "mouseenter" ? ".on" : ".off";
        // fade in/out the elements, play around with the speeds for different effects
        // sometimes a fast fadeout and slightly slower fadein can look nice for example
        $(this).find(showEl).fadeIn( 500);

Again, the JavaScript is relatively simple, it’s the combination of css/js/markup that makes it all work nicely :slight_smile: