if ($(window).width() >= 320 && $(window).width() <= 480) {
$(".projects").slice(0, 8).css("margin", "10px");
} else if ($(window).width() > 480){
$(".projects").slice(3, 6).css("margin", "10px");
};
How i can reset from slice 0,8 to default when windows greater than 480? Because when resized the slice 0,8 rule still active? I want to default if greater than 480 how can do that?
Try to use classes. It's much more flexible than .css. You need to remove previous class/styles before you slice and assign new:
if ($(window).width() >= 320 && $(window).width() <= 480) {
$projects.removeClass('md').slice(0, 8).addClass('sm');
} else if ($(window).width() > 480) {
$projects.removeClass('sm').slice(3, 6).addClass('md');
};
Also consider caching $('.projects'), you don't want to select it on each of resize event fire.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With