Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fade slider type not working when using Data Attributes #659

Closed
2 tasks done
MathieuAlphamosa opened this issue Feb 14, 2022 · 6 comments
Closed
2 tasks done

Fade slider type not working when using Data Attributes #659

MathieuAlphamosa opened this issue Feb 14, 2022 · 6 comments
Labels
bug Something isn't working

Comments

@MathieuAlphamosa
Copy link

Checks

Version

v3.6.12

Description

Fade is working correctly when initialized with JS, it's not working with Data Attributes.
It's seems to be working with Splide 2.4.x, and broken since 3.1.x at least.

Reproduction Link

https://jsfiddle.net/2kmb85nh/6/

Steps to Reproduce

none

Expected Behaviour

Fade slider initialized by using Data Attributes should work.

@MathieuAlphamosa MathieuAlphamosa added the bug Something isn't working label Feb 14, 2022
@mcfarlandonline
Copy link

We're experiencing a similar issue with version 3.6.12 and this setup:

<div class="nr-splideshow nr-splideshow-home splide" data-splide='{
		"type": "fade",
		"rewind": true,
		"pagination": true,
		"pauseOnHover": false,
		"pauseOnFocus": true,
		"keyboard": true,
		"lazyLoad": "nearby",
		"autoplay": true,
		"interval": 8000,
		"speed": 4000
	}'>

And since we have multiple running on one page...

// initialize splide v3 carousel/slideshow
var elms = document.getElementsByClassName( 'splide' );
for ( var i = 0; i < elms.length; i++ ) {
new Splide( elms[ i ] ).mount();
}

@AdsonCicilioti
Copy link

Same problem here!

Thanks for nice Slide lib!

@AdsonCicilioti
Copy link

My workarround:

I'm outputting the options as a property object coming from a custom controls interface, transforming them into JSON (JSON.stringify()). So the solution I gave was to change the attribute name to data-slider (for now) and in my init script revert it to a JavaScript object.

"use-strict";

document.addEventListener(
	"DOMContentLoaded",
	function () {
		var spliders = document.querySelectorAll(".splide");
		console.log(spliders);

		for (let i = 0; i < spliders.length; i++) {
			const el = spliders[i];
			// MY HACK BELOW
			const options = JSON.parse(el.getAttribute("data-slider"));
			new Splide(el, options).mount();
		}
	},
	false
);

@AdsonCicilioti
Copy link

Maybe this helps the author for fix this bug. 👍

@NaotoshiFujita
Copy link
Collaborator

Fixed in v4.0.0

@HendrikWismans
Copy link

Thanks! Works again in v4.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants