SlideDown() 使包装器中的所有内容发生移位

发布于 2024-09-01 00:04:28 字数 579 浏览 2 评论 0原文

我目前正在创建一个简单的菜单,其中有多个服务名称,用户可以单击其中一个,然后 jQuery 将在其下方显示描述它的相应段落。我的 jQuery 代码很好,并且完全符合我的要求,但是,我有一个尚未解决的错误。

每当我单击其中一个标题并显示其描述时,在 Firefox 中,页面包装器中的所有内容都会向左移动约 7 个像素,在 Google Chrome 中也会做同样的事情,但我还没有测量过该数量,但我确信它是无关紧要。

无论如何,我使用 SlideToggle() 命令来显示隐藏的段落。我认为发生这种情况是因为当发生 SlideDown 时,它会以某种方式改变所有内容的宽度和“margin:0 auto;”我的 css 中包装器规则的设置是为了补偿此更改。有谁有什么办法可以解决这个问题吗?我尝试了在互联网上找到的其他几个修复方法,但没有成功。

这是我的代码的样子,我将其放在 jsFiddle 上以便更容易查看: http://jsfiddle.net /vcH7m/ 如果您愿意,请随意编辑它,或者在此处发布需要修复的内容。哪个更方便。非常感谢您的帮助!

I am currently creating a simple menu where there are several names of services and a user can click on one and jQuery will show it's corresponding paragraph describing it below it. My jQuery code is fine and does exactly what I want, however, I have one bug I have yet to iron out.

Whenever I click one of these headings and it's description displays, everything in the wrapper for the page shifts to the left about 7 pixels in Firefox, it does the same thing is Google Chrome however I have not measured the amout but I am sure it is irrelevant.

Anyways, I am using the slideToggle() command to show the hidden parragraph. I assume this is occuring because when the slideDown occurs it is somehow changing the width of everything and the "margin: 0 auto;" setting for the wrapper rule in my css is compensating for this change. Does anyone have any way I can remedy this problem? I have tried several other fixes I've found around the internet but to no avail.

Here is what my code looks like, I put it on jsFiddle to make it easier to view: http://jsfiddle.net/vcH7m/ Feel free to edit it there if you like, or post what needs to be fixed here. Whatever is more convenient. Thank you very much for the help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

北方。的韩爷 2024-09-08 00:04:28

这种移动可能是由垂直滚动条引起的。如果页面太大,则会显示垂直滚动条并将段落的宽度向左推一点。当您将浏览器视口缩小到大约 1000x600 时,您可以在给定 jsfiddle 页面的第一段中看到这一点。

要解决此问题,您可以考虑放置固定的垂直滚动条。

html {
    overflow-y: scroll;
}

This shifting is likely caused by the vertical scrollbar. If the page gets too large, then the vertical scrollbar will show up and push the paragraph's width a bit more to the left. You can see this good in the 1st paragraph of the given jsfiddle page when you shrink the browser viewport to about 1000x600.

To fix this, you may consider to position a fixed vertical scrollbar.

html {
    overflow-y: scroll;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文