jquery color animation throws Invalid property val

2019-02-03 12:27发布

I'm trying to animate the background for an ASP.Net hyperlink to do a yellow fade on an update panels refresh. So far it works almost all of the time, but occasionally a javascript error is thrown "Invalid Propery value." and it debugs into the jquery color plug-in code to this line...

fx.elem.style[attr] = "rgb(" + [
     Math.max(Math.min(parseInt((fx.pos * (fx.end[0] - fx.start[0])) + fx.start[0]), 255), 0),
     Math.max(Math.min(parseInt((fx.pos * (fx.end[1] - fx.start[1])) + fx.start[1]), 255), 0),
     Math.max(Math.min(parseInt((fx.pos * (fx.end[2] - fx.start[2])) + fx.start[2]), 255), 0)
].join(",") + ")";

Here is the order of events as they are currently happening...

First, the window loads so on doc.ready it registers an event to be carried out when the update panel has finished refreshing like so...

Sys.WebForms.PageRequestManager.getInstance().add_endRequest(yellowFade);

Where yellowFade is defined as...

function yellowFade() {
    window.setTimeout("$('#' + hyperlinkUrlId).animate( { backgroundColor: 'white' }, 2000)", 2000);
    window.clearTimeout();
}

Now, rarely I've had it crash right at this point but typically it is later, so I'll continue...

I then click a button titled "Generate" that creates a URL loads the ASP.Net hyperlink with the text for the URL it created and then via javascript sets it's background color to the yellow color to fade from via this...

$("#" + hyperlinkUrlId).css("background-color", "#FBFF9C");

I initially had it setting the color in the code behind via this code...

Url.BackColor = ColorTranslator.FromHtml("#FBFF9C");

But then I thought maybe the back color was getting set to something the jquery color plug-in couldn't recognize, or since it was being set server side the plug-in couldn't access it's style or something but changing it still had no effect on fixing the bug.

Finally, generate changes the URL's back color from white to yellow then as I said most of the time it fades just fine but rarely it throws an error "Invalid property value."

As far as I can tell my syntax is just the way it should be for using the color animations. I feel like the fact that I'm using an updatepanel might be wreaking havoc here but I'm not sure.

Does anyone have any insight into what might cause such a thing? It's been a real mess trying to debug since it happens so infrequently disregarding the fact that javascript is already a pain to debug.

Using jquery 1.3.1 and jquery.color 1.0 on Windows Vista. Using Visual Studio 2008. Let me know if there is anything I can clear up.

EDIT: Dang, not a single response yet. I've taken a bit of a hiatus from working on this but I just found the bug in another part of my app where I am doing the yellow fade. Both of these pages use an update panel. I'm not a fan of the update panel in many cases and it has definitely wreaked havoc on my jquery. I'm wondering if it has something to do with this. Oh, this was kind of implied with the whole Vista thing but I'll point out that I'm running on IIS7.

Does this provoke any insights?

8条回答
该账号已被封号
2楼-- · 2019-02-03 13:02

I have another solution, it works for me. Just add these validation lines:

if (fx.start == undefined) { fx.start = getRGB('white'); } 
if (fx.end == undefined) { fx.end = getRGB('white'); }

Before this:

fx.elem.style[attr] = "rgb(" + [
 Math.max(Math.min(parseInt((fx.pos * (fx.end[0] - fx.start[0])) + fx.start[0]), 255), 0),
 Math.max(Math.min(parseInt((fx.pos * (fx.end[1] - fx.start[1])) + fx.start[1]), 255), 0),
 Math.max(Math.min(parseInt((fx.pos * (fx.end[2] - fx.start[2])) + fx.start[2]), 255), 0)].join(",") + ")";
查看更多
手持菜刀,她持情操
3楼-- · 2019-02-03 13:12

For those having this issue with the jQuery color plugin, a good enough hack is to change

if ( fx.state == 0 ) {

to something low like

if ( fx.state <= 0.045 ) {

Oddly enough fx.state is not always 0, which is why the invalid property error gets thrown occasionally.

查看更多
祖国的老花朵
4楼-- · 2019-02-03 13:13

I was having similar problem with jquery.color.js. Resolved this by using jquery.effects.core.js (jquery ui effects core).

I hope it works for you as well.

查看更多
Emotional °昔
5楼-- · 2019-02-03 13:14

This doesn't appear to work if you are trying to animate some elements in certain browsers (works in Firefox, not in Google Chrome). For example, this will not work with an HTML Canvas. fx.start will be undefined.

My 'hack' to get it to work with HTML Canvas elements for example -

if (fx.start == undefined) { fx.start = getRGB('white'); }
查看更多
爷的心禁止访问
6楼-- · 2019-02-03 13:19

I think I ran into the same problem as you on another project; I had a DIV inside of another DIV (which didn't have it's background explicitly defined.) I was trying to "flash" the background color of the inner DIV and was running into that error. Only after I assigned a specific color to the container DIV did the error go away.

查看更多
Ridiculous、
7楼-- · 2019-02-03 13:20

I was having this same problem in IE8 with a background color animation on some td elemtents. It persisted even though I gave a background color to the tr.

I think I have it fixed now, by changing some code in jquery.ui.

Find this section:

// We override the animation for all of these color styles
$.each(['backgroundColor', 'borderBottomColor', 'borderLeftColor', 'borderRightColor', 'borderTopColor', 'color', 'outlineColor'], function(i, attr) {
    $.fx.step[attr] = function(fx) {
        if (fx.state == 0) {

Change:

if (fx.state == 0)

To:

if (fx.state == 0 || fx.start.constructor != Array || fx.end.constructor != Array)

Sometimes when this code is executed. fx.State is not 0, but fx.start and fx.end haven't been initialized as RGB arrays. In the updated code, we initialize the fx.start and fx.end arrays if they haven't been initialized.

That seems to have fixed it, but it's hard to be sure on an intermittent problem.

More details here: http://dev.jqueryui.com/ticket/4251

查看更多
登录 后发表回答