javascript - how to animate CSS "clip" property in loop-jQuery-animation? -
i want animate slider of twenty-twenty plugin zurb. (http://zurb.com/playground/twentytwenty) github: https://github.com/zurb/twentytwenty
this have currently:
$(".twentytwenty-container").twentytwenty({ default_offset_pct: 0.15, // how far left slider should move_slider_on_hover: true // move slider on mouse hover? }); var leftoffset = parseint($(".twentytwenty-handle").css("left"), 10); function animation() { var options = { duration: 650, easing: 'swing' }; $('.twentytwenty-container') .find('.twentytwenty-handle') .animate({ left: leftoffset + 5 + "px" }, options) .animate({ left: leftoffset - 5 + "px" }, $.extend(true, {}, options, { complete: function() { animation(); } }) ); } function animationimg() { var options = { duration: 650, easing: 'swing' }; $('.twentytwenty-container') .find('.twentytwenty-before') .animate({ clip: "rect(0px " + leftoffset + 5 + "px 856px 0px)" }, options) .animate({ clip: "rect(0px " + leftoffset - 5 + "px 856px 0px)" }, $.extend(true, {}, options, { complete: function() { animationimg(); } }) ); } settimeout(function() { animation(); animationimg(); }, 1500); $('.twentytwenty-container').mouseenter(function() { $(".twentytwenty-handle").stop(true).fadeto(200, 1); $(".twentytwenty-before").stop(true).fadeto(200, 1); }); $('.twentytwenty-container').mouseleave(function() { leftoffset = parseint($(".twentytwenty-handle").css("left"), 10); animation(); animationimg(); });
can't make fiddle cause plugin doesn't work on jsfiddle.. don't know why?
the animation of sliding-arrows works, not effect (comparison) doesn't animate (function: animateimg). clip-css won't animated.
any appreciated, thank you!!
i resolved adding custom event twentytwenty code can trigger whenever need to. suppose extend twentytwenty if don't want hack code, added following code below listeners:
$(window).on("slidein", function(e,pct){ $({slide:0}).animate({slide:pct}, { duration: 2000, step: function(val){ adjustslider(val/100) } }) });
this uses jquery animate trick animate 0 x passing along twentytwenty adjustslider method after converting decimal percent.
in app trigger event via:
$(window).trigger('slidein', 50)
you change around listener selector , trigger if have multiple on page, above working me.
Comments
Post a Comment