How to start the slider with a specific slide listed in the variable?

there is a variable x , how to make a function StartAt took it?
$( document ).ready(function() {
$('.btn-slider').on('click', function() {
var x = 12,
$('.sliderPop').show();
$('.ct-sliderPop-container').addClass('open');
$('.sliderPop' ).addClass('flexslider');
$('.ct-sliderPop-container').addClass('slides');
});
$('.sliderPop').flexslider({

selector: '.ct-sliderPop-container > .ct-sliderPop',
slideshow: false,
controlNav: false,
startAt: x
controlsContainer: '.ct-sliderPop-container'
});
April 7th 20 at 15:51
2 answers
April 7th 20 at 15:53
In the click handler you need to register:
var x = 12;
$('.sliderPop').flexslider(x)
April 7th 20 at 15:55
var x; // declare a variable here, you can let x;
$( document ).ready(function() {
$('.btn-slider').on('click', function() {
x = 12, // change the value of the variable here
$('.sliderPop').show();
$('.ct-sliderPop-container').addClass('open');
$('.sliderPop' ).addClass('flexslider');
$('.ct-sliderPop-container').addClass('slides');
});
$('.sliderPop').flexslider({

selector: '.ct-sliderPop-container > .ct-sliderPop',
slideshow: false,
controlNav: false,
startAt: x
controlsContainer: '.ct-sliderPop-container'
});


most likely the problem is that when you initialize a variable x inside Kabaka clique, then its scope will be limited to this albacom and after its execution the variable will be destroyed. To have access to the variable anywhere in your code, try to declare it in a global context.
I declared, inside the function changed, but after the function the global variable still doesn't change the meaning - Bettye.Beah commented on April 7th 20 at 15:58
@Clair_Blanda, here is a simple example, which shows that the variable is modified. If in Your case this does not happen, it is likely that something else went wrong. if possible, please provide the updated code and see what the problem is. - darius.Morisset commented on April 7th 20 at 16:01
@cortney.Waters,

var x;

$(".btn-slider").click(function(x){
x = 0;
$('.sliderPop').flexslider({

selector: '.ct-sliderPop-container > .ct-sliderPop',
slideshow: false,
controlNav: false,
startAt: x
controlsContainer: '.ct-sliderPop-container'
});

$('.ct-sliderPop-close').on('click', function() {
$('.sliderPop').hide();
$('.ct-sliderPop-container').removeClass('open');
$('.sliderPop').removeClass('flexslider');
$('.sliderPop .ct-sliderPop-container').removeClass('slides');
});
});

$(".btn-slider1").click(function(x){
x = 11;

$('.sliderPop').flexslider({

selector: '.ct-sliderPop-container > .ct-sliderPop',
slideshow: false,
controlNav: false,
startAt: x
controlsContainer: '.ct-sliderPop-container'
});

$('.ct-sliderPop-close').on('click', function() {
$('.sliderPop').hide();
$('.ct-sliderPop-container').removeClass('open');
$('.sliderPop').removeClass('flexslider');
$('.sliderPop .ct-sliderPop-container').removeClass('slides');
});

});



});



$(".btn").click(function(){
$('.sliderPop').show();
$('.ct-sliderPop-container').addClass('open');
$('.sliderPop' ).addClass('flexslider');
$('.ct-sliderPop-container').addClass('slides');

});


Here is the code on clicking the button should change x, and the function at the end needs to take this x for StartAT.
When I first hit the slider start with the correct slide, but then all the buttons start slider with one slide. - Bettye.Beah commented on April 7th 20 at 16:04
@Clair_Blanda, try not to pass x in kolbek click - it it and so are a great find. when passed the argument x another, that's another variable. - darius.Morisset commented on April 7th 20 at 16:07

Find more questions by tags CSSHTMLjQuery