0

I am doing a simple animation of just 3 objects. When I do this animation on a normal page, it works just fine. When I transfer it over to a Wordpress template, the animations seem to queue up and run one at a time

I've tried This S.O. Solution but it did not work.

The desired behavior is Here. When you hover over an image, the image you hover over (if it's not #1) animates at the same time as the other images that are 'getting out of the way'.

The incorrect behavior is Here. As you can see, when you hover over an image, the slides that are not being hovered over animate first, then the slide you have 'selected' hovers to the correct position.

The problem is the "then". All of these tiles should animate at the same time.

Here is the jQuery:

var speed = 500,
    ease  = "easeInOutCirc",
     inc = 5;
$(document).ready(function(){
    $('#hero .featured').hover(function(){
        var e = $(this).index();
        console.log(e);
        $('#hero .featured').each(function(i){
            $(this).find('.content-box').animate({"width":"100%"}, speed, ease);
            if(i > e){
                $(this).stop().animate({"left":100-(($('#hero .featured').length - i)*inc)+"%"}, speed, ease);  
                console.log("right");
            } else if(i <= e){
                $(this).stop().animate({"left":i*inc+"%"}, speed, ease);    
                console.log("left");
            }
        });
    }, function(){
        $('#hero .featured').each(function(i){
            $(this).find('.content-box').animate({"width":"100%"}, speed, ease);
            $(this).stop().animate({"left":i*25+"%"}, speed, ease);
        });
    });
});

So, why is it, that when I add exactly the same HTML and exactly the same javascript to a wordpress template, does it animate incorrectly? I've even included the same jQuery library in each demo.

Any solutions?

Community
  • 1
  • 1
ntgCleaner
  • 5,865
  • 9
  • 48
  • 86
  • _"I've even included the same jQuery library in each demo."_ Try `jQuery().jquery` at `console` , both pages – guest271314 Jan 30 '15 at 02:10
  • https://wordpress.org/support/topic/how-to-update-jquery-javascript-library ? – guest271314 Jan 30 '15 at 02:18
  • @guest271314, Great point in the right direction - The dev site was on 2.1.1, while the wordpress site was on 1.11.1. I've updated wordpress to the latest release 2.1.3, but now I'm getting an error in jQuery itself "Undefined is not a function" I'll take a look to see what's going on – ntgCleaner Jan 30 '15 at 02:18
  • @guest271314, I've updated both dev and wordpress to the latest now. I'm getting an error on the wordpress site, but not dev. I guess it has something to do with wordpress – ntgCleaner Jan 30 '15 at 02:24
  • @guest271314, I've fixed everything but it still is not happening correctly. Both versions of jquery and both scripts to control this are exactly the same, but the behavior is still wrong. Any ideas? – ntgCleaner Jan 30 '15 at 02:44
  • Utilize page that returns correct behavior ? – guest271314 Jan 30 '15 at 02:52
  • @guest271314, Unfortunately, I have to add this into a wordpress "theme" But I've basically just copied everything over. – ntgCleaner Jan 30 '15 at 02:55

1 Answers1

1

First you are using another css framework. I took a look and I saw you are using bootstrap. So here's what I recommend you:

a) add z-index to featured:nth-of-type(n), from 1 to 4, example add z-index: 3 to the element featured:nth-of-type(3); and z-index: 4 to the element featured:nth-of-type(4) because when you hover the 4th element in fact you're triggering now the 3rd element.

b) add transition: all 0.2s ease; to :hover also to .featured:hover and #hero .featured. Check all your transitions are there. I saw you added -webkit and opera but forgot transition: all 0.2s ease;

c) and Finally add css hardware accelerator: #hero .featured translate3d(0,0,0); see more here

I tried that and works smoothly. Take a look at the result.

PS: try to do all animations with CSS rather than with jQuery because you will use less resources, hence optimize GPU. you can read more here

enter image description here

#hero .featured {
width: 100%;
float: left;
height: 100%;
position: absolute;
top: 0;
left: 0;
border-left: 2px solid white;
box-shadow: 0 0 40px rgba(0,0,0,0.75);
-webkit-transition: all .35s ease;
-moz-transition: all .35s ease;
-o-transition: all .35s ease;
transition: all .35s ease;
-webkit-transform: translate3d(0,0,0);
-moz-transform: translate3d(0,0,0);
-ms-transform: translate3d(0,0,0);
-o-transform: translate3d(0,0,0);
transform: translate3d(0,0,0);
}

.featured:hover {
-webkit-transition: all .35s ease;
-moz-transition: all .35s ease;
-o-transition: all .35s ease;
transition: all .35s ease;
}
Michel Arteta
  • 1,384
  • 2
  • 13
  • 25
  • Mike, Thank you for testing this out. I've been heavily relying on jquery animations for the past many years, so I will have to finally check out CSS3 transitions. Is there any way you would be able to post a fiddle of what you've done? or did you just write all of this in inspector? – ntgCleaner Jan 30 '15 at 04:55
  • Also, I try to avoid using bootstrap if at all possible, but the client wanted this specific wordpress theme... I'm just not sure why it would run so poorly on wordpress when the exact same code is applied to a normal page – ntgCleaner Jan 30 '15 at 04:58
  • Sorry to spam this, but you made me realize that the damn `:hover` in bootstrap was screwing everything up. I just commented out the `:hover` selector in the main CSS and it works perfectly, though I will still look into CSS animations – ntgCleaner Jan 30 '15 at 05:00
  • I see you added the z-index, code is above! don't forget to vote :) PS: you could use translate X to get the same result. kind of like this one but horizontally of course http://blogs.sitepointstatic.com/examples/tech/css3-target/accordionvert.html here's the explanation: http://www.sitepoint.com/css3-vertical-accordion-using-target-selector/ – Michel Arteta Jan 30 '15 at 06:38
  • Perfect! Thank you Mike, I'll accept that answer with the relevant code. You've helped a lot! – ntgCleaner Jan 30 '15 at 12:15