jQuery 动画边距顶部
我在 jsfiddle 上有一个脚本: http://jsfiddle.net/kX7b6/
时没有任何反应
悬停 悬停我希望绿色框与红色框重叠,并具有负边距 -50px。什么也没发生。
动画有效,但边距无效
只是为了表明动画本身有效,我向动画添加了不透明度函数。据我所知,margin-top 设置为 0px 内联。
I have a script on jsfiddle: http://jsfiddle.net/kX7b6/
Nothing happens on hover
On hover I want the green box to overlap the red box with a negative margin -50px. Nothing happens.
The animation works, but not margin
Just to show that the animation itself is working i added a opacity function to the animation. margin-top is set to 0px inline as far as I can see.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
您有
MarginTop
而不是marginTop
http://jsfiddle.net/kX7b6/1 /
如果你离开动画中间也会有很多问题,这里是更新:
http://jsfiddle.net/kX7b6/3/
注意我将其更改为
mouseenter
和mouseleave
因为我不认为其目的是当您将鼠标悬停在红色或绿色区域上时取消动画。You had
MarginTop
instead ofmarginTop
http://jsfiddle.net/kX7b6/1/
It is also very buggy if you leave mid animation, here is update:
http://jsfiddle.net/kX7b6/3/
Note I changed it to
mouseenter
andmouseleave
because I don't think the intention was to cancel the animation when you hover over the red or green area.使用
'marginTop'
而不是MarginTop
use
'marginTop'
instead ofMarginTop
使用 less 代码检查相同的效果
查看最近的小提琴
check this same effect with less code
View recent fiddle
MarginTop
应该是marginTop
。MarginTop
should bemarginTop
.不是 MarginTop。有用
Not MarginTop. It works
正如所说的 marginTop - 不是 MarginTop。
另外为什么不将其动画化回来呢? :)
看:
http://jsfiddle.net/kX7b6/2/
As said marginTop - not MarginTop.
Also why not animate it back? :)
See:
http://jsfiddle.net/kX7b6/2/
我不知道“.stop()”是必要的。
i didn't know that the ".stop()" is necessary.
使用以下代码应用一些边距
请参阅此答案: 向下滚动到 div + a一定的余量
use the following code to apply some margin
See this ans: Scroll down to div + a certain margin