开发者

Looking for a jQuery gallery script which moves elements depending on mouse position (ie. for a sliding gallery)

开发者 https://www.devze.com 2023-01-04 21:49 出处:网络
I want to make a gallery which scrolls left and right depending on the mouse position. So you move the mouse right and the gallery scrolls left sort of开发者_StackOverflow中文版 thing.

I want to make a gallery which scrolls left and right depending on the mouse position. So you move the mouse right and the gallery scrolls left sort of开发者_StackOverflow中文版 thing.

Thanks,

Henry.


I think this shouldn't be too hard. If you set up a scrolling area to contain the image you can move this left and right using function animate. Then you can get the position of the mouse in relation to the div you want to scroll and caluclate how much you want it to move depending on where the mouse is. This doesn't do what you want but is does something similar:

$().mousemove( function(e) {

    var pos = $("#holder").offset()
    mouseX = e.pageX - pos.left; 
    mouseY = e.pageY - pos.right;
    if(mouseX > 332 || mouseY > 528 || mouseX < 0 || mouseY < 0) return false;

    posx = Math.round(mouseX/10)*332;
    posy = Math.round(mouseY/10)*10;



    $("#holder").css({'backgroundPosition': posx+'px 0'});




 });
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号