Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add .stop() method #94

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Add .stop() method #94

wants to merge 1 commit into from

Conversation

kfiku
Copy link

@kfiku kfiku commented Nov 26, 2012

Adding .stop() method. It's somethink line jQuery.animate().stop();

Adding .stop() method. It's somethink line jQuery.animate().stop();
@ullmark
Copy link

ullmark commented Nov 30, 2012

correct me if I'm wrong but isn't stop already there and working in 0.1.3, since I've been using it and it seemed to work 😄

@kfiku
Copy link
Author

kfiku commented Nov 30, 2012

sorry for my compit. I dont test it very much and there is a bug so dont public this! But if you paste to console somethink line this:

var div = $("

transmit test
");
$('body').prepend(div);
div = div.transit(
{ opacity: 0 },
5000,
function () {
console.log("transmit callback");
}
);
setTimeout(function () {
div.stop();
// transition dont stop
console.log("stop transmit");
}, 2500);

console prints:
stop transmit
transmit callback

You see that its not working very well. Correct me if I'm wrong.

@rstacruz
Copy link
Owner

Why is where windowTimeout?

@rstacruz
Copy link
Owner

Personally, I don't like monkey-patching the jQuery object to add a new method like .stop(). It should probably instead be a $.fn.transitionStop() or something similar.

Also, resetting the style attribute isn't very friendly... you may be killing some styles that you're not meant to reset. Perhaps .css('transition', 'none') would be nicer.

@rstacruz rstacruz closed this Dec 13, 2012
@tilleul
Copy link

tilleul commented Dec 17, 2012

Here's my humble solution based on kifku's fork (it requires the code lines with the windowTimeout/clearInterval as in his fork):

    self.transitionStop = function (clearTransitionCB) {
        if($.transit.useTransitionEnd) {
            self.unbind(transitionEnd);
        } else {
            clearTimeout(windowTimeout);
        }
        self.stop(true,true);
        if (clearTransitionCB) clearTransitionCB.apply(self);
        return self;
    };

it's still under testing but so far it seems to do the job ...

the .stop() is needed to clear the jQuery queue, otherwise new transitions on the same element won't work.

this function accepts a callback to include a way to clear/reset nicely the transitions using techniques explained in issue #18

thanks for this excellent plugin !

@ghost ghost assigned rstacruz Dec 18, 2012
@rstacruz
Copy link
Owner

Thanks @tilleul, nice call on the .stop(true, true). I still think this should be bound to jQuery.fn.transitionStop() though, because otherwise this won't work:

$("#box").transition(...);
$("#box").transitionStop();

@rstacruz rstacruz reopened this Dec 18, 2012
@PawelGIX
Copy link

Is there chance to have this functionality? jQuery.animate().stop(); It's very handy

@ghost
Copy link

ghost commented Feb 8, 2013

This is also a showstopper for me from using this plugin.

@lorenzomigliorero
Copy link

For stop a current animation, you only add on the selector the css transition declaration "-webkit-transition: all 1s ease;", then remove the attr style.

Example: http://jsfiddle.net/lurex89/g4H7X/

UPDATE:
Look also with this cross browsing solution:

jquery.transit.js row 557:

    // Set defaults. (`400` duration, `ease` easing)
    if (typeof duration === 'undefined') { duration = $.fx.speeds._default; }
    if (typeof easing === 'undefined')   {if ($.support.transition) { easing = $.cssEase._default; } else { easing = "swing"; } }
   if ($.support.transition) duration = toMS(duration);
    // Save the original style for reset on old browser
      $(this).attr("data-duration", duration);
      $(this).attr("data-easing", easing);
      if (!$.support.transition) {
       $(this).stop().animate(properties, duration, easing);
        for (properti in properties) {
          var upperCase = properti.replace(/[a-z]/g, '')
          var replaceProperti;
          (upperCase != "") ? replaceProperti = properti.replace(upperCase, "_" + upperCase) : replaceProperti = properti;
          $(this).attr("data-" + replaceProperti, $(this).css(properti));
        };
        return;
      };

and add this method for stop animation (JS + CSS)

  // reset transition
  $.fn.resetTransition = $.fn.transit = function(noanimation) {
    if ($.support.transition) {
      $(this).removeAttr("style");
      if (!noanimation) $(this).addClass("resetClass");
    } else {
      var originalProperties = {};
      for (properti in $(this).data()) {
        var dataProperti = properti;
        if (properti.indexOf("_") >= 0) {
            var index = properti.indexOf("_");
            var propertiArray = properti.split("");
            delete propertiArray[index];
            propertiArray[index + 1] = propertiArray[index + 1].toUpperCase();
            properti = propertiArray.join("");
        };
        originalProperties[properti] = $(this).data(dataProperti);
      };
      if (noanimation) $(this).data("duration", 1);
      $(this).stop().animate(originalProperties, $(this).data("duration"), $(this).data("easing"));
    }
  };

call in this simple way:

<script type="text/javascript">
$(init);
function init() {
    $(".box").live({
        mouseenter: function() {
            $(this).find(".overlay").stop().transition({opacity: 1}, 700, "easeOutBack");
            $(this).stop().transition({
                width: "250px"
            }, 500, "easeOutBack");
        },
        mouseleave: function() {
            $(this).resetTransition();
            $(this).find(".overlay").resetTransition();
        }
    })
};
</script>

you only declare a class to reset css animation, like:

.resetClass {
    -webkit-transition: all 700ms cubic-bezier(.175, .885,.32,1.275);
    -moz-transition: all 700ms cubic-bezier(.175, .885,.32,1.275);
    -o-transition: all 700ms cubic-bezier(.175, .885,.32,1.275);
    -ms-transition: all 700ms cubic-bezier(.175, .885,.32,1.275);
    transition: all 700ms cubic-bezier(.175, .885,.32,1.275);
}

Awesome plugin :)

@rstacruz rstacruz removed their assignment Sep 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants