jquery 摇动效果和 margin-auto
有一点烦恼这个... Firefox 中的抖动效果示例
如果我省略该行
$this.css({'margin-left':$this.position().left});
,则该框将向左动画的在中心。如果我保留这行代码来修复 Firefox,那么 chrome 也会出现同样的问题。
任何解决这个问题的建议都会很棒。
提前致谢
Having a spot of bother with this...
shake effect example
in firefox if I omit the line
$this.css({'margin-left':$this.position().left});
then the box is animated over to the left instead of in the centre. If I keep that line of code to fix firefox then chrome has the same problem.
Any tips on getting round this would be grand.
thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
解决方案(不是一个令人愉快的解决方案,但它可以跨浏览器工作 - 我说的是跨浏览器,有 ie9 并且我的工作机器无法运行虚拟 PC!!!);
the solution (not a happy one but it 'works' cross browser - I say cross browser, got ie9 and my work machine can't run virtual PC!!!!);
最简单的解决方案可能是引入一个额外的内部 div 来抖动。例如,如果您想要摇动的 div(并且具有“margin 0 auto”)的 id 为“centered”,则不要摇动此 div,而是添加一个内部 div“摇动”并摇动该 div。
http://jsfiddle.net/yAjHa/
The easiest solution is probably to introduce an additional inner div to shake. For example, if the div you want to shake (and that has "margin 0 auto") has the id "centered", then do not shake this div, but add an inner div "shake" and shake that div.
http://jsfiddle.net/yAjHa/
您可以在 jQuery 中使用
$.browser
检测 Firefox 或 Chrome。然后您可以决定是否应用该 CSS。
You can detect Firefox or Chrome with
$.browser
in jQuery.You could then decide whether or not to apply that CSS.
我想我得到了你所问的,是这个吗?
http://jsfiddle.net/mwVkm/3/
根据上面的评论,这是我更改的内容:
jQuery:
$this .css({'margin-left':$this.position().center});
CSS - 对包含的
进行了一些调整:
#box { 宽度:20px;高度:20px; margin:auto auto;}
希望有帮助吗?
Think i got what you were asking, is this it?
http://jsfiddle.net/mwVkm/3/
As per the above comment here is what i changed:
jQuery:
$this.css({'margin-left':$this.position().center});
CSS - Made some tweeks to the containing
<div>
:#box{ width: 20px; height: 20px; margin:auto auto;}
Hope that helps?