Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Turning this simple code into a plugin

  • This topic is empty.
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #40581
    JohnMotylJr
    Participant

    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

    #113218
    TheDoc
    Member
    #113220
    JohnMotylJr
    Participant

    @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!

    #113221
    TheDoc
    Member

    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

    #113279
    Taufik Nurrohman
    Participant
Viewing 5 posts - 1 through 5 (of 5 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.