jQuery“循环”插件导致内容不居中,我该如何解决这个问题?
我正在尝试使用 jQuery“Cycle”插件(http://jquery.malsup.com/cycle/)来旋转位于 内的推荐信...但是该插件是导致我的内容不居中。昨天早上,有人指出
元素被插件绝对定位:
$slides.css({position: 'absolute', top:0, left:0} ).hide()
我不懂 JS,而且我仍在处理 HTML/CSS,所以我希望这里有人知道这个问题的解决方法并可以帮助我。如果不是哦:/
我尝试添加 left:50%
,虽然它居中,但幻灯片已损坏,并且我的所有 立即出现。
[编辑]
这是 HTML 和CSS:
<div class="slideshow">
<span style="font-size:12px; color:#333333; font-family:Lucida Grande,Lucida Sans Unicode,Calibri,Arial,sans-serif;">Hi</span>
<span style="font-size:12px; color:#333333; font-family:Lucida Grande,Lucida Sans Unicode,Calibri,Arial,sans-serif;">Goodbye</span>
</div><br />
.slideshow {
width:940px;
height:64px;
text-align:center;
background-image:url(../images/quotes.png);
}
独自一人,一切都按计划进行。然后我添加 jQuery/Cycle 插件:
// set position and zIndex on all the slides
$slides.css({position: 'absolute', top:0, left:0}).hide().each(function(i) {
var z;
if (opts.backwards)
z = first ? i <= first ? els.length + (i-first) : first-i : els.length-i;
else
z = first ? i >= first ? els.length - (i-first) : first-i : els.length-i;
$(this).css('z-index', z)
});
这就是搞砸的原因。按照原样, 一次显示一个,并像预期的那样淡入淡出,只是由于绝对定位,文本不再居中。所以我将
left:0
更改为 left:50%
- 哇啦!问题解决的文本居中,但现在跨度全部同时显示,并且没有淡入/淡出。
I'm trying to use the jQuery "Cycle" plugin (http://jquery.malsup.com/cycle/) to rotate testimonials located within <span>
s ... however the plugin is causing my content to not be centered. Yesterday morning someone here pointed out the <span>
elements are being absolutely positioned by the plugin: $slides.css({position: 'absolute', top:0, left:0}).hide()
I don't know JS and I'm still working on my HTML/CSS, so I was hoping someone here knew a fix for this and could help me. If not oh well :/
I've tried adding left:50%
and although it centers, the slide is broken and all my <span>
s appear at once.
[Edit]
Here's the HTML & CSS:
<div class="slideshow">
<span style="font-size:12px; color:#333333; font-family:Lucida Grande,Lucida Sans Unicode,Calibri,Arial,sans-serif;">Hi</span>
<span style="font-size:12px; color:#333333; font-family:Lucida Grande,Lucida Sans Unicode,Calibri,Arial,sans-serif;">Goodbye</span>
</div><br />
.slideshow {
width:940px;
height:64px;
text-align:center;
background-image:url(../images/quotes.png);
}
Alone, everything works as planned. Then I add the jQuery/Cycle plugin:
// set position and zIndex on all the slides
$slides.css({position: 'absolute', top:0, left:0}).hide().each(function(i) {
var z;
if (opts.backwards)
z = first ? i <= first ? els.length + (i-first) : first-i : els.length-i;
else
z = first ? i >= first ? els.length - (i-first) : first-i : els.length-i;
$(this).css('z-index', z)
});
This is what screws it all up. As is, the <span>
s are shown one at a time and fade in and out like they're supposed to, except the text isn't centered anymore due to the absolute positioning. So I changed left:0
to left:50%
- wha la! Problem solved text is centered, except NOW the spans are all shown at the same time and there's no fading in/out.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果没有代码,这不容易调用,但我假设推荐位于某种块元素内。如果您将
position:relative
应用于该元素,绝对定位的将包含在其中。您不应该真正将任何定位样式应用于跨度本身 - 而是将其留给插件。
希望有帮助
编辑
好的,试试这个:
您可能还需要手动设置
的宽度以匹配div 的宽度。幻灯片放映
Without the code this isn't easy to call but I assume the testimonials are within a block element of some sort. If you apply
position:relative
to that element the absolutely positioned<span>
s will be contained within. You shouldn't really apply any positioning styles to the spans themselves - rather leave that to the plugin.Hope that helps
EDIT
Okay try this:
You may need to manually set the width of the
<spans>
s as well to match the width of thediv.slideshow