Help me, please, to animate a tag using css data
Before, I am sorry for my (rus)English.
There is a task: to create animation on the basis of data of dynamically added styles table.
The decision received for evening:
- //1 расширить до: получать массив из классов,
- //2 флага удаления противоположного модификатора по БЭМУ
- //3 рекурсивно выводить для всех вложенных классов которые он может затронуть
- $.fn.animateClass = function (className, callback){
- for(var StyleSheetList = document.styleSheets, i=0; i<StyleSheetList.length; i++){
- for(var cssRules=StyleSheetList[i].cssRules, j=0; j<cssRules.length; j++){
- if(cssRules[j].selectorText==className){
- var cssText = cssRules[j].style.cssText;
- cssText = cssText.replace(/\s/g,'');
- var cssAttributes = cssText.split(/[:;]/);
- var cssObject ={};
- for(var k=0;k<cssAttributes.length;k+=2){
- if(!cssAttributes[k]){continue;}
- cssObject[cssAttributes[k]]=cssAttributes[k+1];
- }
- }
- }
- }
- console.log(cssObject);
- $(this).animate(cssObject,'slow',callback);
- return this;
- };
This function is super crude, I need simpler alternative which will be a cross-browser and complete.
ps: to obtain data from classes, not differently
tnx