javascript - Adding events to a coffeescript implementation of a grid -
i found coffeescript implementation of hexgrid uses raphael draw grid onto dom. code cell object below:
class cell constructor: (r,coords) -> [ @r, @x, @y ] = [ r, coords.x, coords.y ] @colors = "bright": "#aaaaaa" "dim": "#8d9794" "blue": "#1e725b" "bright-blue": "#3f947d" @clicked = false @draw() path: -> "m0,0 -15.373745,26.6281 -30.74749,0 -15.373745,-26.6281 15.373745,-26.6281 30.74749,0 z" draw: -> @drawcell() @attachhandlers() drawcell: -> @cell = @r.path @path() @cell.attr "fill": @colors['dim'] "stroke-width": 2 "stroke": "#5f6664" @cell.transform "t#{@x},#{@y}s1" changecolor: (c) -> @cell.attr "fill": @colors[c] doclick: => @clicked = not @clicked @hovered() hovered: => @cell.tofront() if @clicked @changecolor 'bright-blue' else @changecolor 'bright' @cell.animate transform: "t#{@x},#{@y}s1.2", 1000, 'bounce' unhovered: => if @clicked @changecolor 'blue' else @changecolor 'dim' @cell.animate transform: "t#{@x},#{@y}s1", 1000, 'bounce' attachhandlers: -> @cell.hover @hovered, @unhovered @cell.click @doclick
my aim turn cursor pointer when hovering on of individual cells. i've tried various combinations of following in hovered method, no avail:
@cell.mouseover(function(){ container.css('cursor','pointer'); } @cell.mouseout(function(){ container.css('cursor','default'); }
a working codepen here: http://codepen.io/drshoggoth/pen/nartc
changeing design of cursor part of design, not logic. suggest use css
path { &:hover {cursor:pointer} }
otherwise after line 29 add
@cell.attr('cursor','pointer');
Comments
Post a Comment