Bladeren bron

评测系统

gzb
guozhongbo 1 jaar geleden
bovenliggende
commit
2cfcf8c56c
3 gewijzigde bestanden met toevoegingen van 53 en 28 verwijderingen
  1. 1
    3
      css/product.css
  2. 51
    24
      js/product.js
  3. 1
    1
      sections/product.html

+ 1
- 3
css/product.css Bestand weergeven

@@ -218,15 +218,13 @@
218 218
 .exam_slide{
219 219
   width: 100%;
220 220
   height:  100%;
221
+  position: absolute;
221 222
 }
222 223
 .exam_content img {
223 224
   width: 100%;
224 225
   height:  100%;
225 226
   /* object-fit: cover; */
226 227
 }
227
-.exam_slide{
228
-  position: relative;
229
-}
230 228
 .exam_slide span{
231 229
   position: absolute;
232 230
 }

+ 51
- 24
js/product.js Bestand weergeven

@@ -6,30 +6,62 @@ $(function () {
6 6
   //获取元素
7 7
   var divheight = $(".exam_one").height();
8 8
   var container = $(".exam_container");
9
+  var exam_slide = $(".exam_slide"); //右侧图片
9 10
   var list = $(".show_exam");
10 11
   var buts = $(".exam_item");
11 12
   var index = 0; //存放当前显示的图片的下标
13
+  var beforeidx = 0; //之前的索引
12 14
   var interval = 5000; //位移时间间隔
13 15
   var timer;
14 16
   var blue = $(".blue");
15 17
   var grey = $(".grey");
18
+  var that = $;
16 19
   function animate(offset, type) {
17 20
     var top = parseInt(list.css("top")) + offset;
18 21
     // console.log(list.css("top"));
19 22
     var absnum = Math.abs(offset);
20
-    index++;
21
-    offset = "-=" + Math.abs(offset);
22
-    if (index == 5) {
23
-      index = 0;
24
-      offset = 0;
25
-    }
23
+    $.each(exam_slide, (idx, item) => {
24
+      if (index != idx) {
25
+        //隐藏
26
+        exam_slide.eq(idx).css("visibility", "hidden");
27
+      } else {
28
+        //显示当前索引图片
29
+        exam_slide.eq(idx).css("visibility", "visible");
30
+      }
31
+    });
32
+
26 33
     if (!type) {
34
+      beforeidx = index;
35
+      index++;
36
+      offset = "-=" + Math.abs(offset);
37
+      if (index == 5) {
38
+        index = 0;
39
+        offset = 0;
40
+      }
41
+
27 42
       showButton();
28 43
     }
29
-    list.animate({ top: offset }, 300, function () {
30
-      if (top > -200) {
44
+    if (index > beforeidx) {
45
+      console.log("从下往上滚");
46
+    } else {
47
+      console.log("从上往下滚");
48
+    }
49
+    console.log("当前索引", index, "上一个索引", beforeidx);
50
+
51
+    exam_slide.eq(beforeidx).animate(
52
+      {
53
+        visibility: "hidden",
54
+        transformOrigin: "top center",
55
+        transform: "scale(0)"
56
+      },
57
+      500,
58
+      () => {
59
+        console.log("动画完成");
60
+        if (type) {
61
+          beforeidx = index;
62
+        }
31 63
       }
32
-    });
64
+    );
33 65
   }
34 66
   var imglist = [
35 67
     {
@@ -131,26 +163,21 @@ $(function () {
131 163
   buts.on({
132 164
     mouseenter: function () {
133 165
       //移入
166
+      var myIndex = parseInt($(this).attr("index"));
167
+      $.each(grey, function (idx, item) {
168
+        $(this).show();
169
+      });
134 170
       $.each(blue, function (idx, item) {
135
-        $(this).hide();
171
+        if (idx == myIndex) {
172
+          $(this).show();
173
+        } else {
174
+          $(this).hide();
175
+        }
136 176
       });
137
-      var myIndex = parseInt($(this).attr("index"));
138
-      blue.eq(myIndex).show();
139 177
       index = myIndex;
140 178
       animate(divheight, 1);
141
-      console.log("移入当前索引", myIndex);
142 179
     },
143
-    mouseleave: function () {
144
-      //移出
145
-      var myIndex = parseInt($(this).attr("index"));
146
-      if (myIndex != 0 && myIndex != 4) {
147
-        console.log(123);
148
-        blue.eq(myIndex).hide();
149
-        grey.eq(myIndex).show();
150
-      }
151
-
152
-      console.log("移出当前索引", myIndex);
153
-    }
180
+    mouseleave: function () {}
154 181
   });
155 182
   // 回到顶部
156 183
   $(".top").on("click", function () {

+ 1
- 1
sections/product.html Bestand weergeven

@@ -221,7 +221,7 @@
221 221
               <div class="exam_content">
222 222
                 <div class="show_exam">
223 223
                   <div class="exam_slide">
224
-                    <img class="exam_one" src="../img/product/mtznh.png" />
224
+                    <img src="../img/product/mtznh.png" />
225 225
                   </div>
226 226
                   <div class="exam_slide">
227 227
                     <img src="../img/product/zdqss.png" />

Laden…
Annuleren
Opslaan