2
I need some help:
I have the following json
var jsonString = "{ \"0%\" : { \"margin-left\":\"-0%\"},";
jsonString += " \"25%\" : { \"margin-left\":\"-0%\"},";
jsonString += " \"30%\" : { \"margin-left\":\"-100%\"},";
jsonString += " \"50%\" : { \"margin-left\":\"-100%\"},";
jsonString += " \"55%\" : { \"margin-left\":\"-200%\"},";
jsonString += " \"75%\" : { \"margin-left\":\"-200%\"},";
jsonString += " \"80%\" : { \"margin-left\":\"-300%\"},";
jsonString += " \"100%\" : { \"margin-left\":\"-300%\"}}";
jsonString = JSON.parse(jsonString);
$.keyframe.define([
$.extend(
{ name: 'tocaSlide' },
jsonString
)
]);
Works for my purposes.
But the way it is, I’ve got a var jsonString
static.
I need it to be dinâmico
.
So I’m generating him into a loop for
, but it’s going wrong.
I wish I knew where I was going wrong.
var jsonString ={};
for (i = 0; i < quantasImagens; i++) {
tMin = t + tempoTransicao;
tMax = t + tamanhoIntervalos;
t+=tamanhoIntervalos;
if(i==0) tMin=0;
if(i==quantasImagens) tMax=100;
jsonString += "'" + tMin + "%' : { 'margin-left':'-" + tempoImagens + "%'],";
jsonString += "'" + tMax + "%' : { 'margin-left':'-" + tempoImagens + "%'},";
tempoImagens+=100;
}
jsonString = JSON.parse(jsonString );
gave the following error: Uncaught Typeerror: Cannot set Property '0%' of Undefined
– Carlos Rocha
@Carlosrocha yes, of course my mistake, had
var obj = obj;
and notvar obj = {};
.– Sergio
I’m sorry, here I posted wrong. But in drreamweaver is var obj = obj. and it didn’t work anyway. Do you have any idea what might be? See www.hotplateprensas.com.br/styles/slide2.php
– Carlos Rocha
@Carlosrocha this site gives me
500 Internal Server Error
. Put an example ofquantasImagens
and variables that are defined outside the code to mount a working example.– Sergio
So, @Sergio. Good Morning! For me it opens normal here. Maybe you are putting spaces in the URL! The error that returns me is this: "Uncaught Typeerror: Cannot set Property '0%' of Undefined". This in Chrome. In Fireox, the error is "Typeerror: obj is Undefined"
– Carlos Rocha
@Carlosrocha has now opened. You have
var obj = obj;
in the code. Corrects forvar obj = {};
– Sergio
fixed. It worked. But, as always, a logic error occurred! Can you help me? https://answall.com/questions/250778/loop-for-passando-de-100
– Carlos Rocha