Skip to content

Instantly share code, notes, and snippets.

@Luxiyalu
Last active August 29, 2015 14:07
Show Gist options
  • Save Luxiyalu/3342baac7843e7d16ba7 to your computer and use it in GitHub Desktop.
Save Luxiyalu/3342baac7843e7d16ba7 to your computer and use it in GitHub Desktop.
AngularJS Directive: Follow Mouse Movement
# dependency: jQuery
app.directive 'followMousemove', ->
restrict: 'A'
($scope, $element, $attr) ->
$(document).mousemove (e) ->
$element.css
# specific number here could be modified
top: e.pageY
left: e.pageX
# be sure to turn off the listener on scope destroy
# because non-angular listeners needs to be manually cleaned up
$scope.$on '$destroy', ->
$(document).off('mousemove')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment