简体   繁体   English

实现带有图像的轮播消失

[英]Materialize Carousel with Images disappears

I am using Materialize.js for some of the components and JS libraries they have available.我将 Materialize.js 用于它们可用的一些组件和 JS 库。 One that I have been using is the 'carousel' component.我一直在使用的一个是“轮播”组件。 I have it set up with three slides each with an <h5> and a <p> element in the slide container.我在幻灯片容器中设置了三张幻灯片,每张幻灯片都有一个<h5>和一个<p>元素。 This shows up exactly how it's expected.这完全符合预期。 Once I add an <img> element into the slide, the entire carousel disappears.一旦我将<img>元素添加到幻灯片中,整个轮播就会消失。 Here is what I am talking about:这就是我要说的:

working Carousel code:工作轮播代码:

<div class="carousel carousel-slider center z-depth-5" data-indicators="true">
    <div class="carousel-fixed-item center">
        <paper-button raised class="carousel_button" id="top_button">Download Now</paper-button>
    </div>
    <div class="carousel-item white-text" href="#one" id="c_one">
        <div class="carousel_item_inner">
            <h5>Plan</h5>
            <p class="white-text">This is your first panel</p>
        </div>
    </div>
    <div class="carousel-item white-text" href="#two" id="c_two">
        <div class="carousel_item_inner">
            <h5>Create</h5>
            <p class="white-text">This is your second panel</p>
        </div>
    </div>
    <div class="carousel-item white-text" href="#three" id="c_three">
        <div class="carousel_item_inner">
            <h5>Generate</h5>
            <p class="white-text">This is your third panel</p>
        </div>
    </div>
</div>

and JS:[EDITTED]和 JS:[编辑]

$(document).ready(function() {
                $('.parallax').parallax();
                $('.carousel.carousel-slider').carousel({full_width: true});
                $('.scrollspy').scrollSpy();
                $('.stat_circles').addClass('animate');
            });

Here is what it looks like:这是它的样子:

在此处输入图片说明

Once I add an <img> element into one of the .carousel_item_inner <div> 's, the carousel completely disappears.一旦我将<img>元素添加到 .carousel_item_inner <div> ,轮播完全消失。 Here is one of the carousel-item's with the <img> :这是带有<img>的旋转木马项目之一:

<div class="carousel-item white-text" href="#one" id="c_one">
    <div class="carousel_item_inner">
        <h5>Plan</h5>
        <p class="white-text">This is your first panel</p>
        <img src="images/plan.PNG">
    </div>
</div>

And here it is after that <img> element is there:这是在<img>元素之后:

在此处输入图片说明

Really confused as to why the entire carousel disappears with an <img> in the slide container.真的很困惑为什么整个轮播会在幻灯片容器中以<img>消失。 All help is very appreciated, thanks in advance!非常感谢所有帮助,提前致谢!

Here is a link to the Materialize Carousel as well: http://materializecss.com/carousel.html这里也是 Materialize Carousel 的链接: http : //materializecss.com/carousel.html

EDIT:编辑:
Here is a jsfiddle这是一个jsfiddle

https://jsfiddle.net/5cjaduwv/9/ https://jsfiddle.net/5cjaduwv/9/

just for a sanity check can you try wrapping that js in a document ready.只是为了进行完整性检查,您可以尝试将该 js 包装在准备好的文档中吗? It may be that the js is called before your image is loading.可能是在加载图像之前调用了 js。 Also be sure you are loading those scripts at the bottom of your page as you may have images taking too long to load which are dependent on the libs.还要确保您正在页面底部加载这些脚本,因为您可能需要很长时间才能加载依赖于库的图像。

        // Load your JS files here in order of dependencies 
        // such as: jQuery, Bootstrap, other libs and lastly your custom js files
        // KEEP your CSS files in the head of your template.
        <script>
            $(function(){
                $('.carousel.carousel-slider').carousel({full_width: true});
            });
        </script>
    </body>
</html>

I was able to reproduce your error in a fiddle and it came down to JS dependencies with jQuery and materialize.我能够在小提琴中重现您的错误,它归结为 jQuery 和物化的 JS 依赖关系。 Can you share your list of scripts and where they are located.你能分享你的脚本列表和它们的位置吗? I usually keep them at the end of body so the DOM loads first.我通常将它们放在 body 的末尾,以便首先加载 DOM。 jQuery should be the first lib with the others following below it. jQuery 应该是第一个库,其他库在它下面。

您是否尝试将<img>元素放在<p>元素之间?

Materialize's default carousel doesn't seem to be designed to hold img and text in a same container, they simply display one after another. Materialise 的默认轮播似乎并不是为了将 img 和文本保存在同一个容器中,它们只是一个接一个地显示。

Instead, try out the slider : http://materializecss.com/media.html相反,请尝试滑块: http : //materializecss.com/media.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM