简体   繁体   English

在div中移动图片?

[英]Move image inside a div?

I have a div with a specific width and height. 我有一个具有特定宽度和高度的div。 And a smaller image with the same width but much less height. 较小的图像具有相同的宽度,但高度却少得多。 How could I 我怎么能

  • Position the small image to the inside top of the big div (but still all the small image to be visible in it) 将小图片定位到大div的内部顶部(但仍然要在其中看到所有小图片)
  • Animate the small image from the inside top of the big div to the inside bottom (and again, still keep it all visible) 从大div的内部顶部到内部的底部对小图像进行动画处理(再次使所有图像保持可见)
  • Inverse the process to go to the top again 逆过程再回到顶部

I 've been totally confused with this one. 我对此完全感到困惑。 All widths/heights are known, so they don't need to be calculated dynamically. 所有宽度/高度都是已知的,因此不需要动态计算。

Thank you. 谢谢。

You can see an example of the code here 您可以在此处查看代码示例

In general look at the .animate() method of jQuery. 通常来看一下jQuery的.animate()方法。

  1. Set position:relative on the containing div. 设置位置:相对于包含div的位置。
  2. Set position:absolute on the image. 设置位置:图像上的绝对位置。
  3. Use setInterval to increment the top CSS property of the image until it equals (containing div's height) - (image's height) 使用setInterval递增图像的顶部 CSS属性,直到其等于(包含div的高度)-(图像的高度)
  4. Once that is reached, do the same except decrement the top property until 0 达到目标后,执行相同的操作,除了将top属性递减至0
  5. goto 3 :) 转到3 :)

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

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