【问题标题】:Text slideshow stacking on top of each other for first 2 seconds文本幻灯片在前 2 秒内相互叠加
【发布时间】:2016-04-15 18:22:17
【问题描述】:

我的文本幻灯片堆叠了几秒钟,然后才最终正常工作。 这是它的样子: Stacked text slideshow 我能做些什么来解决这个问题?这是文本的代码:

            <div id="textslider"> 

            <div style="position: absolute; left: 50%;">
                <p style="position: relative; left: -50%; border: none;"> 
                    <?php echo get_field('testimony1'); ?> 
                </p>
            </div>

            <div style="position: absolute; left: 50%;">
                <p style="position: relative; left: -50%; border: none;"> 
                    <?php echo get_field('testimony2'); ?> 
                </p>
            </div>

            <div style="position: absolute; left: 50%;">
                <p style="position: relative; left: -50%; border: none;"> 
                    <?php echo get_field('testimony3'); ?> 
                </p>

            </div>

            </div> 

这是 jQuery 中滑块的代码:

    <script src="http://code.jquery.com/jquery-latest.min.js"></script>

    <script>

$('#textslider > div:gt(0)').hide();

setInterval(function() { 
$('#textslider > div:first').fadeOut(500)
.next()
.fadeIn(1000)
.end()
.appendTo('#textslider');
},  3000);

      </script>

【问题讨论】:

    标签: javascript jquery css slider slideshow


    【解决方案1】:

    $('#textslider &gt; div:gt(0)').hide(); 仅在加载 jQuery 后执行。您可以通过将所有 #textslider 子项的 display 属性设置为 none 来简单地将其移动到 css,除了第一个子项,如下所示:

    #textslider div:not(:first-child) {
      display: none;
    }
    

    example

    【讨论】:

    • 谢谢@KrisD。我将您示例中的代码用于“T”并且CSS代码工作得很好(没有更多的堆叠文本,只显示第一个文本)。但是,幻灯片不再起作用。我将代码放在 header.php 中。幻灯片元素在 content.php 中。你认为这是问题所在吗?以前,jQuery 代码只有在放入 header.php(不是 content.php)时才有效(正确,但带有堆叠的文本)
    • 您需要确保加载 jQuery 库才能执行代码
    • 天啊...它突然就无缘无故地工作了,除了修改和重新保存 php 文件两次。非常感谢。你太棒了!!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-01-12
    • 1970-01-01
    • 2013-10-04
    • 1970-01-01
    • 2021-08-27
    • 2011-01-06
    • 2013-06-22
    相关资源
    最近更新 更多