Archive for April, 2010

Wednesday, April 21st, 2010

How to Find & Delete a Specified Value From an Array in JavaScript

You would think that this would be part of JavaScript's core functionality, but... no. It's delete function leaves a value of "undefined" in place of the original. Using splice is the solution, but first you have to know the index of the element. These two simple functions make easy work of the task.

Object-oriented folk may want to enclose these functions within an extended array object (or extend the Array object, if that's your style):


var getArrayIndex = function(array, item){
for (var i = 0; i < array.length; i++) {
if (array[i] === item) {
return i;
}
}
return -1;
};

var deleteArrayItem = function(array, item){
var index = getArrayIndex(array, item);
if (index > -1) {
return array.splice(index, 1);
}
return array;
READ MORE»

View Comments

Monday, April 19th, 2010

Typeface.js :hover workaround

A while ago I wrote a sIFR vs Typeface.js article, and ever since then I've seen hits to my site from people searching for a :hover workaround for Typeface. Here's a limited solution. It's using jQuery, but you could easily adapt this method to use another library (or none at all). I'll admit this isn't the most eloquent solution in the world, but this proved to be functional, so I thought I'd share.


var typefacehover = function (){
$(".typeface-js").each(function(){
//Get all the classes for an element.
var elementStyles = $(this).attr('class');
elementStyles = elementStyles.split(' ');
//Run through them and check for a :hover color property.
var hoverColor;
for (var i ... READ MORE»

View Comments

Thursday, April 15th, 2010

Playing with CSS3 Transformations

Firefox & Chrome users, check out my latest little tech demo. It's the beginnings of a purely javascript game that makes use of early implementations of CSS3 rotation. I love it!

View Comments

Copyright © 2009 Rajeev Singh