Height snap to grid.

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
JellyFish
DevNet Resident
Posts: 1361
Joined: Tue Feb 14, 2006 7:18 pm
Location: San Diego, CA

Height snap to grid.

Post by JellyFish »

How could I, with jQuery, have the height of a div snap to a grid of 325 when ever resized? Always rounding up never down.

For example:

Let say the height of the div is 300px round it up to 325px. Another instance: Let's say the div is 326px, round it up with jquery to 650px.

I hope you get it. I'm just lost on where to start...

Please help me wit this one. :?:
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

snapping formula is simple:

Code: Select all

$snapped = ceil($original / $snapsize) * $snapsize;
User avatar
JellyFish
DevNet Resident
Posts: 1361
Joined: Tue Feb 14, 2006 7:18 pm
Location: San Diego, CA

Post by JellyFish »

Um. Those are php functions and variables? What's the equivalent to ceil() in JavaScript? Math.ceil()?

PS: LP ROCKS!!! :twisted:
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

linkin park is terrible
User avatar
JellyFish
DevNet Resident
Posts: 1361
Joined: Tue Feb 14, 2006 7:18 pm
Location: San Diego, CA

Post by JellyFish »

The Ninja Space Goat wrote:linkin park is terrible
That's your opinion...

Anyways, I used the Math method and it works like a charm. Thanks Weirdan! :D

I'm going to go listen to some Linkin Park now. :lol:
Post Reply