Grow your CSS skills. Land your dream job.

Turning this simple code into a plugin

  • # November 2, 2012 at 7:50 pm

    Howdy peoples of CSS-TRICKS.. I am not new to coding but i am very new to plugin authoring (yeah i know im way behind the curve). But im dabbling with a few lines of code and seeing about turning it into a plugin. Ive read the documentation from the jQuery source, but im having trouble with settings and using the settings as parameters.

    Here is the code i am wanting to convert:

    function r_num() {
    return (Math.floor(Math.random() * 256));
    }

    !function seizure() {
    $('body').css('background', 'rgba('+r_num()+','+r_num()+','+r_num()+',1)');
    $('body').html($('body').css("background-color"));
    setTimeout(seizure, 50);
    }();

    The jsFiddle has my code that i am using in attempts to convert to a plugin (fail). If y’all have some suggestions or hints, i would be very grateful. I can read tutorials all day but until i actually sit down and do this stuff, i wont understand it. And i think this is a great little starting point for me.

    jsFiddle code

    # November 2, 2012 at 8:05 pm

    This is an amazing resource: http://shichuan.github.com/javascript-patterns/#general-patterns

    # November 2, 2012 at 8:09 pm

    @TheDoc,

    Function Declarations – creating anonymous functions and assigning them to a variable

    YES! Thanks man for that resource. See, ya learn something new every day. You just made my life super easier, thanks again bruh!

    # November 2, 2012 at 8:10 pm

    If you’re talking about creating a plugin to release to people, make sure you read further down: http://shichuan.github.com/javascript-patterns/#jquery-plugin-patterns

    # November 3, 2012 at 11:11 am

    @TheDoc: +1

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".