我想使用 jQuery 根据鼠标位置自动滚动 div。
如果您在这里看到这个小提琴,您可以看到许多在可滚动的 div 中水平排列的图像:
<div id="parent">
    <div id="propertyThumbnails">
        <img src="http://www.millport.org/wp-content/uploads/2013/05/Flower-festival.jpg" />
        <img src="http://www.millport.org/wp-content/uploads/2013/05/Flower-festival.jpg" />
        <img src="http://www.millport.org/wp-content/uploads/2013/05/Flower-festival.jpg" />
        <img src="http://www.millport.org/wp-content/uploads/2013/05/Flower-festival.jpg" />
        <img src="http://www.millport.org/wp-content/uploads/2013/05/Flower-festival.jpg" />
    </div>
</div>
CSS:
#parent {
    height: 300px;
    width: 100%;
    background: #ddd;
}
#propertyThumbnails {
    background: #666;
    height: 80px;
    white-space: nowrap;
    overflow: scroll;
}
#propertyThumbnails img {
    width: 125px;
    height: 80px;
    display: inline-block;
    margin: 3px;
    margin-right: 0;
    opacity: 0.6; 
}
我发现您可以使用$("#container").scrollLeft(position)来设置滚动条的位置,但我想根据父级的鼠标位置来设置。这样当鼠标完全移到右手边时,显示最右边的图像,当鼠标完全离开时,显示最左边的图像。
我怎样才能做到这一点?