Auto scroll div based on mouse position

前端 未结 2 1768
轮回少年
轮回少年 2021-02-04 21:41

I want to automatically scroll a div based on mouse position using jQuery.

If you see this fiddle here, you can see a number of images that are horizontally ordered in a

2条回答
  •  我在风中等你
    2021-02-04 21:46

    this should at least get you headed in the right direction.

    var parent = $('#parent');
    var img = $('img:first-child');
    
    parent.on('mousemove', function(e) {
        mouseX = e.pageX
        img.css('margin-left',-mouseX/parent.width()*100);
    
    });
    

    http://jsfiddle.net/xWcXt/4/

提交回复
热议问题