JQuery одушевленный метод с функцией стрелки не выполняется? - PullRequest
0 голосов
/ 29 января 2019

У меня есть метод animate с функцией стрелки, который по какой-то причине не выполняется, при этом используется свойство углового класса, например: this.innerWidth, которое возвращает ширину устройства.Спасибо.

  $(".window").animate(() => {

     if (this.screenWidth >= 1281) {
       console.log(this.screenWidth);
        }
     else if (this.screenWidth >= 1025 && this.screenWidth <= 1280) {
      console.log(this.screenWidth);  
        }    
     },
      5000,
      "swing",
       () => {
        //call back function
     }
  );

Ответы [ 2 ]

0 голосов
/ 29 января 2019

animate () функция принимает следующие аргументы

(selector).animate({styles},speed,easing,callback)

Согласно приведенному выше синтаксису ваш код должен быть:

$(".window").animate({}, 5000, "swing", () => {
        if (this.screenWidth >= 1281) {
            console.log(this.screenWidth);
        } else if(this.screenWidth >= 1025 && this.screenWidth <= 1280) {
            console.log(this.screenWidth);      
        }
    });
0 голосов
/ 29 января 2019

Здесь вам не хватает закрыть одну фигурную скобку для условия «else if», это действительный код

$(".window").animate(() => {

 if (this.screenWidth >= 1281) {
   console.log(this.screenWidth);
  }
 else if (this.screenWidth >= 1025 && this.screenWidth <= 1280) {
  console.log(this.screenWidth);      
 }
},
  5000,
  "swing",
   () => {
    //call back function
 }
);
...