Archive for the ‘JavaScript’ Category.
December 17, 2009, 11:59 pm
This is a small library I wrote for creating simple and complicated easing effects without using JQuery, MooTools or other JS libraries. The library is small 13.4 KB or 5.6 KB compressed, The function can be called as follows: tween(element, property, from, to, duration, [optional] function) Parameters element: The idĀ of the HTML element you [...]
August 24, 2009, 7:09 am
The best you can do with built in JavaScript functions is to round a number to the nearest integer using the method Math.round(x), so to round a float to n decimal points we need to come up with our own function. The function round_float() rounds a floating point number x to n decimals, if you [...]
August 10, 2009, 2:21 am
The JavaScript methods setAttribute and getAttribute are very handy when you are designing dynamic effects for your website, but those methods have a lot of bugs in IE (6 an 7 at least), I use these two crossbrowser functions as alternatives instead of using directly setAttribute() and getAttribute(), I’ve been using them for quite a [...]
August 5, 2009, 6:35 am
This also was about to drive me crazy so I will not let it go without writing about it.. Let’s say you have some long HTML code contained on a PHP variable, something like this <?php $some_div = ‘ <div id=”box”> <h1>Title</h1> <p>Article contents + comments</p> <div>’; ?> Now you want to use this HTML [...]
August 5, 2009, 4:19 am
I use PHP a lot in my projects and it happens that sometimes I combine PHP with another language and write completely useless code. PHP arrays can be created and initialized with like this: <?php $cities[] = “mecca”; $cities[] = “medina”; ?> I thought that the same would apply to javascript… Yes, it can work, [...]
June 6, 2009, 3:56 am
The function generatePassword() is a simple yet customizable function that generates a random password string, the default password length is 6, you can override it by calling the function like thisĀ generatePassword(n) where n is the password length. The possible characters are defined within the function with the variable chars The function: generatePassword([len=6]) function generatePassword(len){ [...]
May 5, 2009, 1:54 am
Maths Ok, so you already know how to generate positive rondom numbers but let’s do it again: To generate a random number varying from 0 to 9 we will use this code: var randomN = Math.floor(Math.random()*10) This expression on the right of the “=” produces a random number from 0 to 1 (excluding 1, say [...]