jquery-animate

How do I fake-time a jQuery animation using Sinon in a Jasmine unit test?

好久不见. 提交于 2019-12-05 00:00:40
I have a 1 second jQuery .animate action that launches 5 seconds after page load. I set up a Sinon timer in my Jasmine unit testing code and test after a tick of 7 seconds to see if the post-animation properties are as they should be. It doesn't work right, so I've placed an instance of the animation itself on my Jasmine HTML test page to better see what's going on. In Firefox and Chrome, the page loads, the animation function is called, the unit test immediately fails, and then (also immediately) the animation visibly occurs. In IE, Opera and Safari, the page loads, the animation function is

How does jQuery have asynchronous functions?

ⅰ亾dé卋堺 提交于 2019-12-04 23:55:44
I'm surprised I can't find a clear answer to this. So, in jQuery, you can do this: $(someElements).fadeOut(1000); $(someElements).remove(); Which, will start a fadeOut animation, but before it finishes executing in the 1 second duration, the elements are removed from the DOM. But how is this possible? I keep reading the JavaScript is single threaded (see also: Is JavaScript guaranteed to be single-threaded? ). I know I can do either: $(someElements).fadeOut(1000).promise().done(function() { $(someElements).remove(); }); or even better: $(someElements).fadeOut(1000, function() { $(this).remove(

Animating a CSS transform with jQuery

烂漫一生 提交于 2019-12-04 23:07:50
问题 I'm trying to animate a div, and get it to rotate about the y-axis 180 degrees. When I call the following code I get a jQuery error: $("#my_div").animate({ "transform": "rotateY(180deg)", "-webkit-transform": "rotateY(180deg)", "-moz-transform": "rotateY(180deg)" }, 500, function() { // Callback stuff here }); }); It says "Uncaught TypeError: Cannot read property 'defaultView' of undefined" and says it's in the jQuery file itself... what am I doing wrong? 回答1: You can also predefine the

jQuery animate() and CSS calc()

╄→尐↘猪︶ㄣ 提交于 2019-12-04 22:53:37
I tried to set CSS calc() using jQuery animate, for example: $element.animate({ height: 'calc(100% - 30px)' }, 500); and I noticed that calc() is not working with jQuery animate... I hope that there is a way to do it, I don't want a similar way to do it, an alternative or a workaround, I want to set calc() Is this impossible? In any way? If it is possible, please can you show how? Setting calc() like you want won't work. The easiest way to do it is to "calculate" it's value into a variable, something like this: var newHeight = $('.container').height() - 30; then you can use the animate() with

Animate CSS display

荒凉一梦 提交于 2019-12-04 22:38:36
Is there a way to animate the CSS display property in jQuery? I have the following: $(".maincontent").css("display","block"); and want it to do something like this: $(".maincontent").animate({"display": "block"}, 2500); Just use .show() passing it a parameter: $(".maincontent").show(2500); Edit (based on comments) : The above code fades in the element over a 2.5 second span. If instead you want a 2.5 second delay and then want the element to display, use the following: $(".maincontent").delay(2500).fadeIn(); If, of course, you want a delay and a longer fade, just pass the number of

Jquery animate background code not working!

空扰寡人 提交于 2019-12-04 21:42:43
See I have a jquery code which I thought that it should work but still it's not working! So please can help me out. Th input have original background color #fff and I want that on focusing that input the background color should change into #789 with a fade effect. Here is the code that I have made. $('input.login_reg_input').focus(function () { $(this).animate({ backgroundColor:fadeColor }, 250, 'linear', function() { }); }); I have search through the stackoverflow and had not found a good solution. So please help me out with this. Thanks in advance! With just the jQuery lib you cannot animate

Changing classes with animation depending on scroll position

心不动则不痛 提交于 2019-12-04 21:31:04
My page contains four sections, each set to 100% height with different background color. At the very top I have a fixed menu. I want the menu to change it's background color depending on which section the user is at the moment, so it blends better with the background. So far I have managed to make the menu's bg color to change when portfolio is entered, but it's not much and I am stuck. It has to change it's color again, when the user scrolls back to home, forth to about and so on. Also, I want it to be animated, but I don't know how to use animate() with addClass(). I've been trying for the

Easiest way to animate background image sliding left?

瘦欲@ 提交于 2019-12-04 21:18:00
What's the best way to animate a background image sliding to the left, and looping it? Say I've got a progress bar with a background I want to animate when it's active (like in Gnome or OS X). I've been playing with the $(...).animate() function and trying to modify the relevant CSS property, but I keep hitting a brick wall when trying to figure out how to modify the background-position property. I can't just increment its value, and I'm not sure if this is even the best approach. Any help appreciated! As soon as I posted this I figured it out. In case it helps anyone else, here's the function

jQuery: Animate (fade) background-color or image in div when hover a link?

喜欢而已 提交于 2019-12-04 19:07:10
I want to create a menu such as on redhotchilipeppers.com. When you hover a link in the top right the background color of the whole page change. The original image is still in the back, it's just the color that changes. Below you can see how I tried to accomplish it. It's fades way too slow and when I hover one link and then another it first fades to the first links bg color and then back to normal and then to the second links bg color. On redhotchilipeppers.com the bg colors fades right away. Here's the code I use right now: <head> <style> body { margin:0 auto; top:0; left:0; height:100%;

How to stop jQuery queuing animation effects

房东的猫 提交于 2019-12-04 18:32:52
I have a simple jQuery hover animation: jQuery(function($) { $('.category').hover(function(){ $(this).find('.banner').fadeIn(); },function(){ $(this).find('.banner').fadeOut(400); }); }); all this does is when someone hovers over the .category element, the banner div fades in and fades out. Simple. My problem is that as I have about ten of the .category elements, if someone moves across them too fast or off and on the same one multiple times jQuery queues the animations and keeps making them appear, disappear until it's caught up. Is there a simple way to stop this from happening? I saw