Skip to content

Instantly share code, notes, and snippets.

@pilt
Created July 24, 2011 19:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pilt/1102970 to your computer and use it in GitHub Desktop.
Save pilt/1102970 to your computer and use it in GitHub Desktop.
Numerical input field enhancer in Coffeescript
<input type="text" class="num gte0">
$(document).ready ->
$('input[type="text"].num').bind 'mousewheel', (ev, delta) ->
ev.preventDefault()
limit = (val) -> val
if $(@).hasClass 'gte0'
limit = (val) -> Math.max val, 0
val = parseInt $(@).val(), 10
val = 0 if isNaN val
val = limit(val + delta)
$(@).val(''+val).focus()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment