Friday, May 6, 2011

jQuery - farbtastic PlugIn callback function

Hey!

I'm just setting up a web page with a color picker. I choosed farbtastic.

My problem is, that the callback function doesn't work. Here is the code I used:

$('#colorPicker1').farbtastic('#background-color', function callback() { /*commands*/ });

The callback function is not called, when the user choosed a color.

Does someone have a solution?

Thank you! Benedikt

From stackoverflow
  • farbtastic called like you did

    $('selector').farbtastic(...)
    

    awaits only one optional argument. This can be a DOM Node, jQuery object, jQuery selector or a function. So you should call the function as shown below

    $('#colorPicker1').farbtastic(function(color){
       // commands
    });
    

    If you want to use #background-color element, you should use it in the callbacks body

    $('#colorPicker1').farbtastic(function(color){
       $('#background-color').css({'background-color':color});
       // commands
    });
    
  • Yes. I also tried this, but then I don't have the feature of updating the color after loading the page and the text-color switch from black to white.

    Is there a simple way to do that? I think coding it manually is not a good way.

    Thank you for your answer!

    Benedikt R. : Nobody got a solution?
  • Your post is old I know but just in case :

    var picker = $.farbtastic('#colorPicker1');  //picker variable
    picker.setColor("#b6b6ff"); //set initial color
    picker.linkTo(onColorChange); //link to callback
    
    function onColorChange(color) {
      dosomeStuff();
    }
    

0 comments:

Post a Comment

Note: Only a member of this blog may post a comment.