1
I have the following structure:
var prop = new Array();
prop[0] = "margin : auto";
prop[1] = "padding : 5px";
prop[2] = "border : none";
...
$(elemento).css({
for(i=0; i< prop; i++) {
/*Aqui vão serem feitos os laços do for e vão imprimir a toda linha, alguma coisa como:
document.write(prop[i]);
*/
margim: auto,
/*para cada laço do for, uma linha dessa será criada*/
}
});
For each element, the print inside the for will be different.
The idea is to see if in the end
The interpreter css
, for this case, interprets something as:
$(elemento).css({
margim: auto,
padding: 5px;
border: none,
etc...
});
There’s a way to make it work?
On the advice of a colleague here, I came to this solution.
But because it’s json
, And inside the variable there are keys, I didn’t know how to solve:
var variavel =
{
'0%' : { 'margin-left':'-0%'},
'33%' : { 'margin-left':'-0%'},
'38%' : { 'margin-left':'-100%'},
'66%' :{ 'margin-left':'-100%'},
'71%' : { 'margin-left':'-200%'},
100%' : { 'margin-left':'-200%'},
}
Here’s the shape I’m using to get to the array:
var tempoTransicao = 5;
var quantasImagens = 4;
var tamanhoIntervalos = Math.round(100/quantasImagens);
var tempoImagens = 0;
var t = 0;
var imagem = [];
for (i = 0; i < quantasImagens; i++) {
tMin = t + tempoTransicao;
tMax = t + tamanhoIntervalos;
t+=tamanhoIntervalos;
if(i==0) tMin=0;
if(i==quantasImagens) tMax=100;
imagem[i] = [];
imagem[i].push(tMin + "% { margin-left:-" + tempoImagens + "%};");
imagem[i].push(tMax + "% { margin-left:-" + tempoImagens + "%};");
tempoImagens+=100;
}
});
texto = "";
for (po=0; po<imagem.length; po++) {
texto += imagem[po][0]+imagem[po][1];
}
Please read again with more attention to the question. I think you did not understand well. There I did not find what I was looking for. If you know how to do, please post your answer which may serve to others with the same doubt.
– Carlos Rocha
Does this structure already exist or are you still defining? If you’re still defining, you can use a json for multiple css rules.
– Eduardo Abreu dos Santos
Thank you for answering. I’m still defining. Could you help me by posting an answer and showing me how you do it. Please? I would be grateful.
– Carlos Rocha
Brother, by your example, it seems that you want to transition the image from one side to the other, correct?
– Eduardo Abreu dos Santos
Yes Eduardo. But you can’t tell how many images will be inserted into html. In this case, I need to create the keyframe settings before applying them.
– Carlos Rocha