COME, CLICK WITH US 
 OMNIA CONNECT BLOG

Archive for the ‘css’ Category

Lavalamp effect with jquery easing plugin

Tuesday, August 11th, 2009

Here’s a small Javascript function which enables animated highlighting effect on the navigation (lavalamp effect) with the help of jquery easing plugin

$.fn.lavalamb = function(ImgPath){
/* ImgPath:  Path of the image which you need to animate when you hover over a navigation link
   this can be a shadow png image or a pointer image or underline image which you want to animate with a mouseover / mouseout action on a link

   Add css class "Highlight" to the node which is currently active, so the image will always be animated back to this node on mouseout
*/
var LeftPos;
$(this).append('<div id="lavalamp"><img src="'+ImgPath+'" alt="" /></div>'); //Appending lavalamb image to the html, this div can be skinned in the css.
$(this).parent().css({position: "relative"}); //setting the position
$("#lavalamp").css({
position: "absolute",top: $(this).height() // These css values can be edited to vertically position the lavalamb image
});
  $(this).find("li").hover(  //Link hover function
function(){ 	//Rollover
LeftPos = $(this).offset().left - $(this).parent().offset().left; //calculating the left position
LeftPos = (LeftPos - ($("#lavalamp").width()/2) + ($(this).width()/2)); //calculating the left position
$("#lavalamp").animate({left: LeftPos},{queue:false,duration:700,easing: "easeInQuart"}); //Animating the image from the start position to the current mouseover position
},
function(){
   LeftPos = $(this).parent().find("li.Highlight").offset().left - $(this).parent().offset().left; // Getting the position of the highlighted node
 	 $("#lavalamp").animate({left: LeftPos},{queue:false,duration:700,easing: "easeOutQuart"}); //Animating the image back to the start position from the current mouseover position
  });
}

And call this function in the html page

<script type="text/javascript">
$("#Navigation").lavalamb("Images/Background/NavShadow.png"); // Navigation is an id of the <UL> list which has navigation nodes
</script>

lavalamb
Here’s an example
Example1

Skinning HTML form elements

Sunday, August 2nd, 2009

It’s always a pain to skin the normal radio/checkboxes and the select lists by using CSS.
I was doing some research on this and figured out a way using javascript/css. I put the functions together in a small jquery plugin.

My idea was to customize the radio/checkbox/listboxes without disturbing the actual markup.
The solution makes use of real radio buttons with labels and their toggle functionality and skinned list-items, allowing radiobutton list rendering and easy skinning.

skindefault

In the above form thre are a few dropdown lists, radio button and checkboxes. The markup looks like

 <fieldset class="Dropdown">
	<select class="NonJsSelect">
	 <option>List Item 1</option>
	 <option>List Item 2</option>
	 <option>List Item 3</option>
	 <option>List Item 4</option>
	 <option>List Item 5</option>
	 <option>List Item 6</option>
	 <option>List Item 7</option>
	 <option>List Item 8</option>
	 <option>List Item 9</option>
	 <option>List Item 10</option>
	 <option>List Item 11</option>
	</select>
 </fieldset>
 <p><strong>Checkbox controls</strong></p>
 <fieldset class="CheckList">
 	<input type="checkbox" id="CheckBox1" class="Checkbox" />
 	<label for="CheckBox1">Checklist 1 value </label>
 </fieldset>
 <fieldset class="CheckList">
 	<input type="checkbox" id="CheckBox2" class="Checkbox" />
 	<label for="CheckBox2">Checklist 2 value </label>
 </fieldset>
 <fieldset class="CheckList">
 	<input type="checkbox" id="CheckBox3" class="Checkbox" />
 	<label for="CheckBox3">Checklist 3 value </label>
 </fieldset>

Just wrap your controls in a <fieldset> or a <div> and add css classes “Dropdown” for comboboxes and “CheckList” for radio/checkbox controls as shown above.

Download the css/javascript files then add the javascript javascript css references to the page.

Finally just initiate the javascript function

&lt;script type=&quot;text/javascript&quot;&gt;
$.function(){
 $(&quot;select&quot;).AddSkin();
 $(&quot;.Checkbox&quot;).AddSkin();
//you can reference the controls by its name, id or css class just like any other jquery calls.
}
&lt;/script&gt;

skin_1
You can change the skin by editing the CustomControls.css and replacing the images.

here’s an example

Try it out!

You can download the sample code and plugin from here.

Note: The plugin currently supports only Dropdown, checkbox and radio button controls.
I order to make this work you have to include the latest jquery library.