Showing posts with label CSS. Show all posts
Showing posts with label CSS. Show all posts

Tuesday, August 28, 2012

CSS3 transitionend event with cross browser compatability using Javascript

I had 2 animations, the first one would last 10 seconds and the second one had to start from the time the first one ends. After some research I found the following solution:

First animation:

canvas1 =  document.getElementById("myCanvas") ;


canvas1.addEventListener('transitionend',     spin_finished, false);


---Start First animation


Second animation:


function spin_finished() {

       canvas1.removeEventListener('transitionend', spin_finished, false);


         - start second animation


}



The removeEventListener is required to make sure the transitionend event happens only once.



Then I ran into cross browser naming convention problem because each browser calls the transitionend event differently. Then I ran into this elegant solution by NeilJS



// CROSS-BROWSER TRANSITION END EVENT LISTENERS

var transEndEventNames = {


    'WebkitTransition': 'webkitTransitionEnd',


    'MozTransition': 'transitionend',


    'OTransition': 'oTransitionEnd',


    'msTransition': 'MSTransitionEnd',


    'transition': 'transitionend'


},


transEndEventName = transEndEventNames[Modernizr.prefixed('transition')]; // bind event listener to transEndEventName eg:


//



So the revised code looks like this after inserting the previous snippet:



First animation:



canvas1 =  document.getElementById("myCanvas") ;


canvas1.canvas.addEventListener(transEndEventName,
spin_finished,
false);


---Start animation


Second animation:


function spin_finished() {



canvas1.canvas.removeEventListener(transEndEventName, spin_finished, false);

- start second animation


}



Works great on Firefox, Safari, Opera and Chrome!



References:




  1. Cross-browser CSS3 transitionend event for event listeners by NeilJS


  2. Css3 Transitions Tutorial : Javascript


  3. Quick Tip: CSS3 Transition End Event



Thursday, August 23, 2012

Jquery Mobile gradient background for content

I have given below the HTML snippet and the CSS file I used for adding a gradient to the Content div.

I  used the gradient CSS code from this excellent site:

Ultimate CSS Gradient Generator by ColorZilla.

 

HTML

<div data-role="content"  class="main_div_blue" style="overflow:hidden;"  >  


CSS


.main_div_blue {

background: rgb(208,228,247); /* Old browsers */


background: -moz-linear-gradient(top, rgba(208,228,247,1) 0%, rgba(115,177,231,1) 24%, rgba(10,119,213,1) 50%, rgba(83,159,225,1) 79%, rgba(135,188,234,1) 100%); /* FF3.6+ */


background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(208,228,247,1)), color-stop(24%,rgba(115,177,231,1)), color-stop(50%,rgba(10,119,213,1)), color-stop(79%,rgba(83,159,225,1)), color-stop(100%,rgba(135,188,234,1))); /* Chrome,Safari4+ */


background: -webkit-linear-gradient(top, rgba(208,228,247,1) 0%,rgba(115,177,231,1) 24%,rgba(10,119,213,1) 50%,rgba(83,159,225,1) 79%,rgba(135,188,234,1) 100%); /* Chrome10+,Safari5.1+ */


background: -o-linear-gradient(top, rgba(208,228,247,1) 0%,rgba(115,177,231,1) 24%,rgba(10,119,213,1) 50%,rgba(83,159,225,1) 79%,rgba(135,188,234,1) 100%); /* Opera 11.10+ */


background: -ms-linear-gradient(top, rgba(208,228,247,1) 0%,rgba(115,177,231,1) 24%,rgba(10,119,213,1) 50%,rgba(83,159,225,1) 79%,rgba(135,188,234,1) 100%); /* IE10+ */


background: linear-gradient(to bottom, rgba(208,228,247,1) 0%,rgba(115,177,231,1) 24%,rgba(10,119,213,1) 50%,rgba(83,159,225,1) 79%,rgba(135,188,234,1) 100%); /* W3C */


filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#d0e4f7', endColorstr='#87bcea',GradientType=0 ); /* IE6-9 */


}

Sunday, August 19, 2012

CSS prefix issue and Modernizr Prefixed

If you are doing any CSS development using Javascript you must be aware of prefixes like -moz-transform, -webkit-transform, -o-transform required by Firefox, Safari and Opera. Safari and Chrome use the same –webkit- prefix.

You can use  Modernizr to simplify the task.

the article Modernizr Prefixed by Andi Smith is a definite read.

In this article Andi explains how you can use Modernizr to simplify your life.

Typical usage:

In HTML page

<script src="js/modernizr.js"></script>

In the Javascript

var car_cont=document.getElementById('carousel_container') ;
    
car_cont.style[Modernizr.prefixed('perspective')]  = '1100px';

This is equivalent to the CSS statement

-webkit-perspective: 1100px;
moz-perspective: 1100px;
-o-perspective: 1100px; ----and so on.

Some more references from W3Schools

  1. CSS3 Browser Support Reference
  2. CSS Reference
  3. example: CSS3 perspective Property

CSS 3d Transforms for Safari, Chrome and Firefox

I am now developing a 3d Carousel for use in different browsers. It uses 3d transforms available in Safari, Chrome and Firefox. Unfortunately IE 9 and Opera do not seem to support it.

The following references are excellent resources.

  1. Using 2D and 3D Transforms is an excellent place to start
  2. CSS3 Transitions, Transforms and Animation Tutorial has excellent tutorial.
  3. Intro to CSS 3D transforms has very good step by step approach which explains the fundamentals of transforms and how to implement it with CSS3.
  4. Cloud Carousel - A 3d Carousel in Javascript does not use CSS 3d and done in Javascript
  5. CSS Infos is an excellent reference site.
  6. Ceaser CSS EASING ANIMATION TOOL is worth visiting.
  7. CSS3 tools is also worth visiting.
  8. Rotating Image Using JQuery has also some introductory information.

Saturday, November 20, 2010

JQuery Mobile, JQTouch and CSS: This is not your father’s HTML or CSS!

Like what they would say, this is not your father’s HTML. Things have advanced a lot in HTML and CSS. I am now designing for the mobile phones, concentrating on Windows Phone 7. At the same time I am fascinated with HTML 5 which is available in both Android and Iphone. I am not happy that Microsoft has not provided HTML 5 in Windows Phone 7. I like Silverlight, but you can also do cool things with HTML 5 and CSS.
Button design is also lot of fun with CSS, Icons and HTML! If you want to design seriously for mobile phones you should definitely  look at these sites.

  1. iPhone Book Excellent book by Jonathan Stark on mobile telephone design and development.
  2. JQTouch A plug in for JQuery which works fine for Iphone. Unfortunately Windows Phone 7 ignores most of it because it is still based on IE 7.
  3. JQueryMobile Excellent work, very good again for Iphone and Android but does not render in Windows Phone 7.
  4. Rediscovering the button element Excellent Article by Kevin Hale which is a very good introduction to merging icons with text on buttons.
  5. jQuery Image Strip Very good article about simple tricks in Javascript to create nice results
  6. CSS Image Techniques: Part 1 Excellent series of articles by GuiStuff
  7. Scalable CSS buttons using PNG and background colors
  8. 3d css buttons
  9. 30 Excellent CSS Based Navigation and Buttons Tutorial
  10. Button Collection
  11. icons for mobile apps
  12. Display icons using a single image and CSS “Sprites”
  13. Create superior web buttons and menus in a few clicks! very good software mainly to create prototypes quickly.
  14. Glueit Excellent software to create icon strips
  15. What Are CSS Sprites?
  16. Playing with CSS3 gradients
  17. Playing with CSS3 gradients
  18. Updated: Windows Phone 7 IE Mobile gets webkit-compatible update