Reputation: 1290
I've got question about width of my element which I want to divide by number 90 If this width is multiplicity of 90 set width of this element if not go to next.
For example when window width is 1000px Element is full width 100% (lets call it (EW = element width) if EW can be divided by 90 its ok , so 1000/90 = 11,1(1) we getting window smaller we comes to 990/90 = 10 and it's ok
here EXAMPLE CODEPEN
It works when you resize slowly but when you do it fast it lost.
var windowWidth = $(window).width(),
widthNumber = windowWidth / 90;
$("#EW").css({
width: windowWidth
});
if(widthNumber % 1 != 0){
console.log("dont change")
} else {
console.log("change")
}
Someone have any idea how to solve this?
Upvotes: 0
Views: 109
Reputation: 2611
From the jQuery resize
docs:
Code in a resize handler should never rely on the number of times the handler is called. Depending on implementation, resize events can be sent continuously as the resizing is in progress (the typical behavior in Internet Explorer and WebKit-based browsers such as Safari and Chrome), or only once at the end of the resize operation (the typical behavior in some other browsers such as Opera).
That is why your method is not being called when quickly resizing the window
Upvotes: 1