Как я могу установить слева неопределенным в JQuery Animate

0

У меня есть массив вроде

[undefined,"3px","3px",undefined,"3px",undefined,"3px",undefined]

это обозначено как css;

поэтому я хочу использовать

$(dom).animate{
        top:arr[0],
        right:arr[1],
        bottom:arr[2],
        left:arr[3],
}

но он всегда устанавливает верх: 0 right0, хотя он установлен неопределенным; благодаря


thank you ;
i am sorry to expression not correct;
i've solve  it in other ways.
Simply say it when i've set the dom left ;
than use animate to set the right property ;
it not work because css property can't set left and right in time;
i'hava a lot of dom.Some set left and some set right ;
Some animate right and some animate left;
i make an array 4 direction one dom;
so i want to ask there is any way to remove css property in animate;
Теги:
jquery-animate

4 ответа

0
Лучший ответ

Вы можете сопоставить undefined с "+=0px", поэтому анимация становится необязательной для неопределенных компонентов:

var components = [
    undefined, "3px", "3px", undefined, "3px", undefined, "3px", undefined
];
var animComponents = $.map(components, function(value) {
    return value === undefined ? "+=0px" : value;
});

$(dom).animate({
    top: animComponents[0],
    right: animComponents[1],
    bottom: animComponents[2],
    left: animComponents[3]
});
1

Вы не можете установить значение css как undefined. Вы можете преобразовать значение в 0 когда значение вашего массива не undefined:

$(dom).animate{
    top: arr[0] == "undefined" ? 0 : arr[0],
    right: arr[1] == "undefined" ? 0 : arr[1],
    bottom: arr[2] == "undefined" ? 0 : arr[2],
    left: arr[3] == "undefined" ? 0 : arr[3],
}
  • 0
    Короче будет arr[0] || 0 , arr[1] || 0 и т. Д.
0

Проверьте тип данных переменной с помощью typeof()

 $(dom).animate{
   top: typeof(arr[0]) == "undefined" ? 0 : arr[0],
   right: typeof(arr[1])  == "undefined" ? 0 : arr[1],
   bottom: typeof(arr[2])  == "undefined" ? 0 : arr[2],
  left: typeof(arr[3])  == "undefined" ? 0 : arr[3],
 }
0

Я не думаю, что css понимает undefined значение. Попробуйте отключить undefined с помощью 0 или 0px.

Ещё вопросы

Сообщество Overcoder
Наверх
Меню