浏览代码

Bug Fix and Refactoring: "is-visible" was not toggled properly in Fade mode.

NaotoshiFujita 5 年之前
父节点
当前提交
df028844df
共有 5 个文件被更改,包括 21 次插入9 次删除
  1. 10 4
      dist/js/splide.js
  2. 0 0
      dist/js/splide.min.js
  3. 二进制
      dist/js/splide.min.js.gz
  4. 8 2
      src/js/components/elements/slide.js
  5. 3 3
      src/js/components/lazyload/index.js

+ 10 - 4
dist/js/splide.js

@@ -1968,6 +1968,12 @@ var STYLE_RESTORE_EVENTS = 'update.slide';
      * @return {boolean} - True if the slide is visible or false if not.
      * @return {boolean} - True if the slide is visible or false if not.
      */
      */
     isVisible: function isVisible() {
     isVisible: function isVisible() {
+      var active = this.isActive();
+
+      if (Splide.is(FADE) || active) {
+        return active;
+      }
+
       var floor = Math.floor;
       var floor = Math.floor;
       var Components = Splide.Components;
       var Components = Splide.Components;
       var Track = Components.Track;
       var Track = Components.Track;
@@ -1975,7 +1981,7 @@ var STYLE_RESTORE_EVENTS = 'update.slide';
       var position = floor((Track.toPosition(index) + Track.offset(index) - Track.position) * Track.sign);
       var position = floor((Track.toPosition(index) + Track.offset(index) - Track.position) * Track.sign);
       var edge = floor(position + slide[prop]);
       var edge = floor(position + slide[prop]);
       var size = Components.Elements.track[prop];
       var size = Components.Elements.track[prop];
-      return 0 <= position && position <= size && 0 <= edge && edge <= size || this.isActive();
+      return 0 <= position && position <= size && 0 <= edge && edge <= size;
     },
     },
 
 
     /**
     /**
@@ -4832,7 +4838,7 @@ var SRC_DATA_NAME = 'data-splide-lazy';
         init();
         init();
         Components.Elements.each(function (Slide) {
         Components.Elements.each(function (Slide) {
           each(Slide.slide.querySelectorAll("[" + SRC_DATA_NAME + "]"), function (img) {
           each(Slide.slide.querySelectorAll("[" + SRC_DATA_NAME + "]"), function (img) {
-            if (img && !img.src) {
+            if (!img.src) {
               images.push({
               images.push({
                 img: img,
                 img: img,
                 Slide: Slide
                 Slide: Slide
@@ -4873,7 +4879,7 @@ var SRC_DATA_NAME = 'data-splide-lazy';
 
 
 
 
   function check(index) {
   function check(index) {
-    index = index === undefined ? Splide.index : index;
+    index = isNaN(index) ? Splide.index : index;
     images = images.filter(function (image) {
     images = images.filter(function (image) {
       if (image.Slide.isWithin(index, options.perPage * (options.preloadPages + 1))) {
       if (image.Slide.isWithin(index, options.perPage * (options.preloadPages + 1))) {
         load(image.img, image.Slide);
         load(image.img, image.Slide);
@@ -4883,7 +4889,7 @@ var SRC_DATA_NAME = 'data-splide-lazy';
       return true;
       return true;
     }); // Unbind if all images are loaded.
     }); // Unbind if all images are loaded.
 
 
-    if (!images.length) {
+    if (!images[0]) {
       Splide.off(NEARBY_CHECK_EVENTS);
       Splide.off(NEARBY_CHECK_EVENTS);
     }
     }
   }
   }

文件差异内容过多而无法显示
+ 0 - 0
dist/js/splide.min.js


二进制
dist/js/splide.min.js.gz


+ 8 - 2
src/js/components/elements/slide.js

@@ -6,7 +6,7 @@
  */
  */
 
 
 import { find, addClass, removeClass, hasClass, getAttribute, setAttribute } from '../../utils/dom';
 import { find, addClass, removeClass, hasClass, getAttribute, setAttribute } from '../../utils/dom';
-import { SLIDE } from '../../constants/types';
+import { FADE, SLIDE } from '../../constants/types';
 import { STATUS_CLASSES } from '../../constants/classes';
 import { STATUS_CLASSES } from '../../constants/classes';
 import { values } from "../../utils/object";
 import { values } from "../../utils/object";
 import { pad } from "../../utils/utils";
 import { pad } from "../../utils/utils";
@@ -133,6 +133,12 @@ export default ( Splide, index, realIndex, slide ) => {
 		 * @return {boolean} - True if the slide is visible or false if not.
 		 * @return {boolean} - True if the slide is visible or false if not.
 		 */
 		 */
 		isVisible() {
 		isVisible() {
+			const active = this.isActive();
+
+			if ( Splide.is( FADE ) || active ) {
+				return active;
+			}
+
 			const { floor }  = Math;
 			const { floor }  = Math;
 			const Components = Splide.Components;
 			const Components = Splide.Components;
 			const Track      = Components.Track;
 			const Track      = Components.Track;
@@ -141,7 +147,7 @@ export default ( Splide, index, realIndex, slide ) => {
 			const edge       = floor( position + slide[ prop ] );
 			const edge       = floor( position + slide[ prop ] );
 			const size       = Components.Elements.track[ prop ];
 			const size       = Components.Elements.track[ prop ];
 
 
-			return ( 0 <= position && position <= size && 0 <= edge && edge <= size ) || this.isActive();
+			return ( 0 <= position && position <= size && 0 <= edge && edge <= size );
 		},
 		},
 
 
 		/**
 		/**

+ 3 - 3
src/js/components/lazyload/index.js

@@ -93,7 +93,7 @@ export default ( Splide, Components, name ) => {
 
 
 				Components.Elements.each( Slide => {
 				Components.Elements.each( Slide => {
 					each( Slide.slide.querySelectorAll( `[${ SRC_DATA_NAME }]` ), img => {
 					each( Slide.slide.querySelectorAll( `[${ SRC_DATA_NAME }]` ), img => {
-						if ( img && ! img.src ) {
+						if ( ! img.src ) {
 							images.push( { img, Slide } );
 							images.push( { img, Slide } );
 						}
 						}
 					} );
 					} );
@@ -130,7 +130,7 @@ export default ( Splide, Components, name ) => {
 	 * @param {number} index - Current index.
 	 * @param {number} index - Current index.
 	 */
 	 */
 	function check( index ) {
 	function check( index ) {
-		index = index === undefined ? Splide.index : index;
+		index = isNaN( index ) ? Splide.index : index;
 
 
 		images = images.filter( image => {
 		images = images.filter( image => {
 			if ( image.Slide.isWithin( index, options.perPage * ( options.preloadPages + 1 ) ) ) {
 			if ( image.Slide.isWithin( index, options.perPage * ( options.preloadPages + 1 ) ) ) {
@@ -141,7 +141,7 @@ export default ( Splide, Components, name ) => {
 		} );
 		} );
 
 
 		// Unbind if all images are loaded.
 		// Unbind if all images are loaded.
-		if ( ! images.length ) {
+		if ( ! images[0] ) {
 			Splide.off( NEARBY_CHECK_EVENTS );
 			Splide.off( NEARBY_CHECK_EVENTS );
 		}
 		}
 	}
 	}

部分文件因为文件数量过多而无法显示