]> _ Git - fluidbook-toolbox-quiz.git/commitdiff
wip #6182 @0:10 question match
authorsoufiane <soufiane@cubedesigners.com>
Mon, 25 Sep 2023 09:28:15 +0000 (11:28 +0200)
committersoufiane <soufiane@cubedesigners.com>
Mon, 25 Sep 2023 09:28:15 +0000 (11:28 +0200)
js/quiz.match.js

index 265a93f27794043cc2d8d61cd68edc1a8a6e5f95..5509bcaa608c2398f8eec63dac8f4f2fb58e75aa 100644 (file)
@@ -12,9 +12,7 @@ function QuizMatch(quiz) {
 QuizMatch.prototype = {
     start: function() {
         const $this = this
-        let posInit = 0
-        this.positionsX = [{top: "10", opacity: ".48"},{top: "39", opacity: ".24"}]
-        this.counter = 0
+        this.rules = [{top: "10", opacity: ".48"},{top: "39", opacity: ".24"}]
         this.quiz.screens.currentQuestionAnswers = [];
 
         $(document).on("click", ".move-slide", function () {
@@ -61,7 +59,7 @@ QuizMatch.prototype = {
                 slideChange: function(swiper) {
                     $this.setRotation(swiper)
                 },
-                progress: function(swiper, progress) {
+                progress: function(swiper) {
                     $this.setRotation(swiper)
                 }
             }
@@ -70,46 +68,29 @@ QuizMatch.prototype = {
     },
 
     setRotation: function(swiper) {
-        const $this = this
-        const slides = swiper.slides
         let activeIndex = swiper.activeIndex
         let nextAllArray = swiper.slides.slice(activeIndex+1)
-        let prevAllArray = swiper.slides.slice(0,activeIndex)
-
-
-        console.log(nextAllArray)
-        //console.log(prevAllArray)
-        let angle = 4
-
-        if(swiper.swipeDirection === "next") {
-            angle -= 4
-        }
+        let prevAllArray = swiper.slides.slice(0,activeIndex).reverse()
 
-        if(prevAllArray.length > 0) {
-            let angle = -4
-            prevAllArray.reverse().forEach(function(el,index) {
-
-                $(el).css({
-                    'transform':'rotate('+(angle)+'deg)',
-                    'top': $this.positionsX[index] ? $this.positionsX[index].top+'px' : 0,
-                    'opacity': $this.positionsX[index] ? $this.positionsX[index].opacity : 0
-                })
-                angle -= 4
-
-            })
-        }
-
-        if(nextAllArray.length > 0) {
-            let angle = 4
-            nextAllArray.forEach(function(el,index) {
+        this.setStyleCard(prevAllArray,"prev")
+        this.setStyleCard(nextAllArray,"next")
+    },
 
+    setStyleCard: function(array,direction) {
+        const $this = this
+        let angle = direction === "next" ? 4 : -4
+        if(array.length > 0) {
+            array.forEach(function(el,index) {
                 $(el).css({
                     'transform':'rotate('+(angle)+'deg)',
-                    'top': $this.positionsX[index] ? $this.positionsX[index].top+'px' : 0,
-                    'opacity': $this.positionsX[index] ? $this.positionsX[index].opacity : 0
+                    'top': $this.rules[index] ? $this.rules[index].top+'px' : 0,
+                    'opacity': $this.rules[index] ? $this.rules[index].opacity : 0
                 })
-                angle += 4
-
+                if(direction === "next") {
+                    angle += 4
+                } else {
+                    angle -= 4
+                }
             })
         }
     },