Pages

Friday, November 18, 2011

Rounded Corners for IE using .htc files



                I’ve tried two methods which I found on the internet. They can be found in following URLs. These URLs point to the sites which I found them.
border-radius.htc
Unfortunately these have some issues. But the PIE solution is more advance and complete in my opinion. This is said by experience not by knowing inside workings of these.  I have mentioned the issues that I had to face using these solutions, there can be more but these are what I got into. I recommend PIE as the better solution. These are not just for the border radius; they also provide solutions to box shadow and some other stuff.

Issues Using border-radius.htc

Generate border lines for elements which were not present in the initial design.
Breakup jQuery code.  (This broke the spot light effect which I used)
Background images get repeated even if I use no-repeat

Issues Using PIE

I could not get the opacity controlling of elements which had background images. They work fine when background images are not present.

In case you are looking for equivalent properties for border-radius in CSS, -webkit and –moz look at the following url.

Saturday, November 12, 2011

Retain value between function calls without using global variables in JavaScript using callee



                Normally when we want to retain a value we use a global variable which is defined outside the scope of the function we are calling. But we can actually retain a value without using global variables but by using built in variables passed to the function. When a function is called two built in variables are made available to the function. One of them is the arguments variable. This variable contains a property named callee which contains a reference to the function itself.
                Since we can get a reference to the function we can use a property for that function to store the required value. See the example.

function deposit(amount){

var funct=arguments.callee;

 if(!funct.balance)
{
funct.balance=0;
}
funct.balance+=amount;

 return funct.balance;
}


When the function is called for the first time there is no property named balance for the function. Therefore we have to check it an initialize the property. Afterwards, we each time the function get called we can extract the stored value and modify it finally return the value. I tried and failed to develop a self-modifying function to avoid check each time and only check once for the existence of the property. You may give it a try!

Just  copy and paste this to firebug console and add these to check.

deposit(10);  //this would return 10