I found a little trick that allows me to use jquery to add styles to a class with vendor prefixes:
var myTransform = ($.browser.webkit) ? '-webkit-transform' :
($.browser.mozilla) ? '-moz-transform' :
($.browser.msie) ? '-ms-transform' :
($.browser.opera) ? '-o-transform' : 'transform';
var myCSSObj = {};
myCSSObj[myTransform] = 'translate('+centrepos+'px, 0px)';
$("div.current").css(myCSSObj);
I'm not quite sure how this works, so if someone can explain, I would be very grateful.
But, my question is to apply this method and add it to the inline style of the jquery fragment. I currently have the following, but it is written by hand:
$fragment = $('<div class="preload" style="position: relative; -webkit-transform: translate('+start+'px, 0px);"/>');
I want to give this container an initial position when it is added to dom. How can I add code without having to manually add each browser prefix?
source
share