jQuery“循环”插件导致内容不居中,我该如何解决这个问题?

发布于 2024-09-25 11:26:43 字数 1549 浏览 8 评论 0原文

我正在尝试使用 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 技术交流群。

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

发布评论

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

评论(1

慢慢从新开始 2024-10-02 11:26:43

如果没有代码,这不容易调用,但我假设推荐位于某种块元素内。如果您将 position:relative 应用于该元素,绝对定位的 将包含在其中。您不应该真正将任何定位样式应用于跨度本身 - 而是将其留给插件。

希望有帮助


编辑

好的,试试这个:

.slideshow {
    width:940px;
    height:64px;
    background-image:url(../images/quotes.png);
    position:relative;
    }

.slideshow span {
    display:block;
    }

您可能还需要手动设置 的宽度以匹配 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:

.slideshow {
    width:940px;
    height:64px;
    background-image:url(../images/quotes.png);
    position:relative;
    }

.slideshow span {
    display:block;
    }

You may need to manually set the width of the <spans>s as well to match the width of the div.slideshow

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