As you move the mouse around on your desk a ball that sticks out from the bottom of the mouse follows the action. The ball, in turn, activates 2 or 3 rollers connected to mechanisms that convert the movements into electrical signals. These signals show up on your screen as position coordinates for the pointer. All these parts move whenever you scoot the mouse along your mouse pad. Everything works fine as long as nothing gums up the works.
Stuff does have a tendency to collect on computer desks.
Mouse pads seem to work as gunk magnets collecting every bit of dust, dirt, and grime that happens to even be remotely close by. Your our own body contributes to the collection with a collection of dead skin cells and the oil from your hands. And, if you smoke it gets even worse. After a while all this gunk and grime ends up clogging up the mouse works. As a result your mouse pointer starts jumping around uncontrollably on the screen.