user1261245
user1261245

Reputation: 21

JQuery - Scroll div using cursor position

Is there a way for scroll a div using the position of the cursor?

Demo made with JavaScript: http://scripterlative.com/files/cursordivscroll.htm

Thanks.

Upvotes: 2

Views: 3720

Answers (1)

Giedrius
Giedrius

Reputation: 1688

well if you will use jQuery plugin http://flesler.blogspot.com/2007/10/jqueryscrollto.html than everything is possible.

Don't know the actual effect you want to achieve, but if I'm imagining right, you probably want to do something like this for image preview slider at the bottom http://www.fredrikclement.com/#/series/selected/Redbull If yes, than just check mouse position when it is on that particular div. use something like that:

$('div').mousemove(function(e){
    var mouse_x = e.pageX,
        mouse_y = e.pageY;

    // here goes calculation code where you will decide how much to you want to
    // scroll the div, basically plugin works with target, so you might need to create
    // reference object with absolute position and change its position before you
    // you can scroll

});

Upvotes: 1

Related Questions