I've used this technique in the past to keep customer mini-carts in view.
I like the CSS tricks method the best:
http://css-tricks.com/scrollfollow-sidebar/
Just add the CSS to your style sheet, insert the javascript in a tpl and add the html content somewhere. I would practice this using a page outside of X-cart first, a simple html page. Then it should be simpler for you to asee how to add it to XC.
I want to warn you though, In live tests on very busy sites, I actually had customers complain about this behavior. We received so many complaints that we took it off the site.