I am build something using the royalSlider jQuery slider plugin.
It has an API that let’s you pull in various slide data. Per the documentation, the slider data is set as a variable with
var sliderInstance = $(".royalSlider").data('royalSlider');
When I type that into the browser console manually, it pulls in the slider data as a var like it should (I can see it via console.log(siderInstance).
BUT when I just add the same code as a script in the markup, it doesn’t set that as a var…
So, somehow I guess I am delcaring this too early? Before the slider is initialized, perhaps?
I don’t know how much I would avoid that…
The js markup on the page. The first script is how the slider is initialized.
<script id="addJS">jQuery(document).ready(function($) {
$('#gallery-1').royalSlider({
fullscreen: {
enabled: true,
nativeFS: false,
},
controlNavigation: 'thumbnails',
autoScaleSlider: true,
autoScaleSliderWidth: 960,
autoScaleSliderHeight: 750,
fitInViewport:true,
loop: false,
imageScaleMode: 'fit-if-smaller',
navigateByClick: true,
numImagesToPreload:2,
arrowsNav:true,
arrowsNavAutoHide: true,
arrowsNavHideOnTouch: true,
keyboardNavEnabled: true,
fadeinLoadedSlide: true,
globalCaption: true,
globalCaptionInside: true,
thumbs: {
appendSpan: true,
firstMargin: true,
paddingBottom: 4,
orientation:'horizontal',
}
});
});
</script>
<script>
var sliderInstance = $(".royalSlider").data('royalSlider');
function slideDynamics() {
var theCaption = sliderInstance.currSlide.caption.text()
document.getElementById("slide-caption").innerHTML = theCaption;
}
sliderInstance.ev.on('rsAfterSlideChange', slideDynamics);
slideDynamics();
</script>