jquery load new vars

為{幸葍}努か 提交于 2019-12-13 09:10:53

问题


It´s posible , if i have one var , use jquery for load news vars and change these

For example if i have :

var activate_auto="yes";



$("#play").click(function() {

/// load vars
activate_auto="yes";


});


$("#stop").click(function() {

/// load vars
activate_auto="no";


});

COMPLETE CODE

<script>

var w_ac="900";
var h_ac="295";
var w_ac_col="64";
var n_cols="5";
var margin="3";
var time_ac_change=5000;
var time_ac_effects=2000;
var time_ac_hide_effects=1000;

var ac_activate_auto="si";
var ac_activate_auto_random="no";

var margin=margin*n_cols;
var result=w_ac_col*n_cols+margin;
var final=w_ac-result;


$(function(){




$("#ac_play").click(function() 
{
ac_activate_auto="si";
ac_activate_auto_random="no";
time_ac_change=2000;
});


$("#ac_stop").click(function() 
{
ac_activate_auto="no";
ac_activate_auto_random="no";
time_ac_change=2000000;
});


for (i=1;i<=n_cols;i++)
{

$(".ac_"+i+"").css("width",""+w_ac_col);

}

});


function acordeon(id)
{

$(function(){

for (i=1;i<=n_cols;i++)
{

if (+id==i)
{}
else
{
$(".ac_"+i+"_inf").hide(time_ac_hide_effects);
}

}

$(".ac_"+id+"_inf").css("width",""+final);
$(".ac_"+id+"_inf").show(time_ac_effects).fadeIn(time_ac_effects);

$(".ac_im").css("width",""+final);
$(".ac_im").css("height",""+h_ac);








});





}

</script>


<script>









var starting_slide = n_cols;

function setSlide(i) 
{


acordeon(i);















if (i > 0) {
i--;   
setTimeout( function(){setSlide(i)}, time_ac_change);

}

else 
{
setTimeout( function(){setSlide(starting_slide)}, 1000);
} 

}






if (ac_activate_auto=="si")
{
setSlide(starting_slide);
}






if (ac_activate_auto_random=="si")
{

$(document).ready(function(){

acordeon(1);

var refreshId = setInterval(function(){

var r=Math.floor(Math.random()*n_cols)    

if (r==0)
{
acordeon(1)
}
else
{
acordeon(+r)
}


}, time_ac_change);
});





}

</script>

In this case works always when i push over pay or stop but only one time , if i push over play works play but no works before stop and the same when the first i push it´s play

I want push stop load new var and play and other time load the other var , i don´t know if it´s possible , thank´s !


回答1:


You should only create your var and don't set a value to it, and then, only set its values inside your functions. Ex.:

var activate_auto; // this is outside your click functions

Ok, now I'm not sure what you want to do... will edit it later if necessary =\



来源:https://stackoverflow.com/questions/11759394/jquery-load-new-vars

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!