Javascript 基于鼠标位置在div中自动滚动图标

Javascript 基于鼠标位置在div中自动滚动图标,javascript,jquery,html,css,Javascript,Jquery,Html,Css,我让它工作了,但它正在移动页面上的每一张图片,而不仅仅是我想要的图片 <script type='text/javascript'>//<![CDATA[ $(window).load(function(){ var parent = $('#parent'); var img = $('img:first-child'); parent.on('mousemove', function(e) { mouseX = e.pageX console.log(m

我让它工作了,但它正在移动页面上的每一张图片,而不仅仅是我想要的图片

<script type='text/javascript'>//<![CDATA[ 
$(window).load(function(){
var parent = $('#parent');
var img = $('img:first-child');

parent.on('mousemove', function(e) {
    mouseX = e.pageX
    console.log(mouseX/parent.width()*100);
    img.css('margin-left',-mouseX/parent.width()*100);

});
});//]]>  

</script>
//
图标代码为:

<div id="parent">

      <div id="propertyThumbnails">

  <a href="#"><img src= "icons/Facebook.png" width="24" height="24"></a>
  <a href="#"><img src= "icons/Twitter.png" width="24" height="24"></a>
  <a href="#"><img src= "icons/Google.png" width="24" height="24"></a>
  <a href="#"><img src= "icons/Digg.png" width="24" height="24"></a>
  <a href="#"><img src= "icons/LinkedIn.png" width="24" height="24"></a>
  <a href="#"><img src= "icons/Tumblr.png" width="24" height="24"></a>
    <a href="#"><img src= "icons/Pinterest.png" width="24" height="24"></a>
    <a href="#"><img src= "icons/YouTube.png" width="24" height="24"></a>
    <a href="#"><img src= "icons/OtherSite.png" width="24" height="24"></a>
</div></div>

你知道如何滚动我想要的图片而不是页面上的所有图片吗?

使用

var parent = $('#parent');
var img = parent.find('a > img:first-child');

jquery将选择所有图像,因为所有的
标记都是
的第一个子项。您需要使用更具体的选择,如:

$('a:first child>img')