Joe
Joe

Reputation: 457

taking flexible arguments in javascript?

I'm trying to take flexible arguments in javascript to manipulate color with the eyecon colorpicker (www.eyecon.ro/colorpicker/)

But when I try to change color the page hangs, is it getting stuck in the arguments.length loop?

the html is:

<div class="colorSelector" id="colorSelector3"><div style="background-color: #0000ff"></div></div>

and the jquery/javascript is:

$('#colorSelector3').click(function(){
colorPickDynamic('#colorSelector3','h1','color');
});


function colorPickDynamic(cp){

var i;
var j;

for (x=0, i = 1, j = 2; j < arguments.length; i+2, j+2, x++) {

var tag = [];
var colorProperty = [];
tag[x]=arguments[i];
colorProperty[x]=arguments[j];
}

$(cp).ColorPicker({
    color: '#0000ff',
    onShow: function (colpkr) {
        $(colpkr).fadeIn(500);
        return false;
    },
    onHide: function (colpkr) {
        $(colpkr).fadeOut(500);
        return false;
    },
    onChange: function (hsb, hex, rgb) {

                            $(tag[0]).css(colorProperty[0], '#' + hex);

        $(cp + ' div').css('backgroundColor', '#' + hex);
    }
});
}

any help would be amazing! thanks

Upvotes: 0

Views: 109

Answers (1)

Kevin B
Kevin B

Reputation: 95023

You have an infinite loop, you are never incremementing j.

j+2 should be j+=2, i+2 should be i+=2

Upvotes: 6

Related Questions