i want it trigger when number is 0. when number is 1 or 2, when number is 3 or 4, when number is 5 or 6. when trigger it will change height some element. for now it always return 70px.
if(y == 0){
$('slpage').style.height = '0px';
}else if(y >= 1){
$('slpage').style.height = '70px';
}else if(y <=4){
$('slpage').style.height = '140px';
}else if(y >= 5){
$('slpage').style.height = '210px';
}
thanks
You should consider reordering your statements. So that it checks the highest first and then for lowest.
if(y == 0){
$('slpage').style.height = '0px';
}else if(y >= 5){
$('slpage').style.height = '210px';
}else if(y >=4){
$('slpage').style.height = '140px';
}else if(y >= 1){
$('slpage').style.height = '120px';
}
Otherwise, you end up triggering the lowest always before reaching the highest.
And I guess you made a type for the check in your third condition. Corrected.
switch if the integer dependent. its means it should 0,1,2,3,4,5,6. but my situation is if 0. it trigger. if 1-2. it trigger. if 3-4. it trigger. if 5-6. it trigger.
Don't restrict yourself using switch just because you have to cover 2 cases at a time. Switch
have that facility too.
switch (y) {
case 0:
$('slpage').style.height = '0px';
break;
case 1:
case 2:
$('slpage').style.height = '120px';
break;
case 3:
case 4:
$('slpage').style.height = '140px';
break;
case 5:
case 6:
$('slpage').style.height = '240px';
break;
}
Assuming you using Jquery, your selector of Jquery is wrong. You are missing #
or .
Ignore if you are not.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments