简体   繁体   English

jQuery中的.animate()函数不起作用滑动图像

[英].animate() function in jQuery doesn't work sliding images

Code: 码:

$("#previous_image").click(function(){
  $("#images").animate({"right": "+=250px"}, "slow");
    return false;
});

When i run a console.log i get into the click function, so that ain't a problem. 当我运行console.log时,我进入了click函数,所以这不是问题。 It seems my div just doesn't want to get animated. 看来我的div只是不想动画。

My CSS code (SASS) 我的CSS代码(SASS)

#images_container{
  display: block;
  margin-left: 39px;
  width: 630px;
  height: 81px;
  overflow: hidden;
}

#images{
  display: block;
  width: 1500px;
  min-width: 650px;


  img{
    margin-top: 7px;
    display: inline-block;
    height: 66px;
    cursor: pointer;

    filter: url(svg/filters.svg#grayscale);
    filter: gray; /* IE6-9 */
    -webkit-filter: grayscale(100%); /* Google Chrome & Safari 6+ */

    transition: filter .3s ease-in-out;
    -moz-transition: filter .3s ease-in-out;
    -webkit-transition: filter .3s ease-in-out;
    transition: -webkit-filter .3s ease-in-out;
    -moz-transition: -webkit-filter .3s ease-in-out;
    -webkit-transition: -webkit-filter .3s ease-in-out;

    @include transition-property(-webkit-filter);
    @include transition-duration(.3s);
    @include transition-timing-function(ease-out);

    &:hover{
      filter: none;
      -webkit-filter: grayscale(0);
    }
  }

Any toughts? 有困难吗? It's freaking me out. 吓死我了

Cheers. 干杯。 W. W.

You shouldn't need the += 您不需要+=

Try this: 尝试这个:

$("#previous_image").click(function(){
    $("#images").animate({"right": "250px"}, "slow");
    return false;
});

Also to use right and left you need an absolutely positioned element. 还使用right ,并left你需要绝对定位的元素。 In order to position something absolutely you need it's container to be position relatively. 为了绝对放置某物,您需要将其相对放置。

So change your css to this: 因此,将您的CSS更改为:

#images_container{
  display: block;
  margin-left: 39px;
  width: 630px;
  height: 81px;
  overflow: hidden;
  position: relative;
}

#images{
  display: block;
  width: 1500px;
  min-width: 650px;
  position: absolute;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM