0
  if ($(window).width() >= 320 && $(window).width() <= 480) {
    $(".projects").slice(1, 8).css("margin", "10px");
  } else {
    $(".projects").slice(3, 6).css("margin", "10px");
  };

Its working good with default without resize finction. I try set this with:

 $(window).resize(function() {           
 })

But not working. Any idea why?

JSFIDDLE

4
  • Seems to work to me. What exactly are you expecting it to do? Commented Feb 23, 2014 at 9:03
  • I want to change the slice when window width changed? Commented Feb 23, 2014 at 9:04
  • It does do that? Perhaps the problem is that it doesn't change back if the widths change? Commented Feb 23, 2014 at 9:05
  • The problem is only use the slice 1.8 when window resized not use slice 3.6 understand? Commented Feb 23, 2014 at 9:06

1 Answer 1

2

You are never resetting the div margins. Therefore, as soon as it get to the point where slice 1 through 8 have margins, they will never get changed back. You need to reset the divs:

$(window).resize(function () {
    $(".projects").css('margin', '0px'); // reset the divs
    if ($(window).width() >= 320 && $(window).width() <= 480) {
        $(".projects").slice(1, 8).css("margin", "10px");
    } else {
        $(".projects").slice(3, 6).css("margin", "10px");
    };
});

Here is Fiddle

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.