简体   繁体   English

引导轮播没有响应

[英]Bootstrap carousel no reacting when responsive

I have a carousel set up with a small box inside it to display some text that the user can fill out. 我有一个旋转木马,里面装有一个小盒子,可以显示用户可以填写的一些文本。 This box can be toggled on and off where it slides up and down as required. 您可以根据需要在此框上上下下切换此框的开和关状态。

However, in mobile devices, this box no longer appears. 但是,在移动设备中,此框不再出现。 I've checked the element and I can see that it is firing, but nothing is appearing in my browser. 我检查了元素,可以看到它正在触发,但是浏览器中什么都没显示。 Could someone take a fresh look over my code to see if I forgetting something? 有人可以重新检查一下我的代码,看看我是否忘记了什么?

I won't post the whole carousel code, just the affect area. 我不会发布整个轮播代码,而只会发布受影响的区域。

Carousel affect area: 轮播影响区域:

<div class="container-fluid slider np">
    <div class="row clearfix">
        <div class="col-md-12 column">
            <div id="carousel-733617" class="carousel slide" data-ride="carousel">

                <div class="carousel-inner" role="listbox">
                    @foreach (var slide in Model.Content.GetPropertyValue<ArchetypeModel>("carousel"))
                    {
                        var imageMedia = Umbraco.Media(slide.GetValue("slideImage")).GetCropUrl("CarouselSlide");
                        var slideHeading = slide.GetValue("heading");
                        var slideText = slide.GetValue("text");
                        string relatedLinksRaw = slide.GetValue("relatedLink");
                        dynamic relatedLinks = null;

                        if (!string.IsNullOrEmpty(relatedLinksRaw))
                        {
                            relatedLinks = Json.Decode(relatedLinksRaw);
                        }

                        if (slideCount == 0)
                        {
                            slideClass = "item active";
                        }
                        else
                        {
                            slideClass = "item";
                        }

                        <div class="@slideClass" @*role="option" aria-selected="true" tabindex="0"*@>
                            <img alt="" src="@imageMedia" />
                            <div class="carousel-caption" style="z-index:20;">
                                <div class="buttonslide">
                                    <a href="#" class="btn btn-xs btn-default pull-right openclose">
                                        <i class="glyphicon glyphicon-chevron-down"></i> Close</a>
                                </div>
                                <div class="slidecontent">
                                    <h2>@slideHeading</h2>
                                    <p>
                                        @slideText
                                        <br />

                                        @if (relatedLinks != null)
                                        {
                                            foreach (var relatedLink in relatedLinks)
                                            {                                                    
                                                if (relatedLink.newWindow == true)
                                                {                                                       
                                                    <a href="@relatedLink.link" class="btn btn-square" target="_blank">@relatedLink.caption</a>
                                                }
                                                else
                                                {
                                                    <a href="@relatedLink.link" class="btn btn-square">@relatedLink.caption</a>
                                                }
                                            }
                                        }
                                    </p>
                                </div>
                            </div>
                        </div>

                                        slideCount++;
                    }

My Javascript that controls the box opening and closing: 我的Java,用于控制框的打开和关闭:

    $('.openclose').click(function(e) { 
    if ($('.slidecontent').is(":visible")){
        $('.openclose').html('<i class="glyphicon glyphicon-chevron-up"></i> Show More');
    }
    else{
        $('.openclose').html('<i class="glyphicon glyphicon-chevron-down"></i> Close'); 
    }   

    $('.slidecontent').toggle('slow');  
    e.preventDefault();
});

在此处输入图片说明

Above is a quick MS Paint of the issue. 以上是该问题的快速MS Paint。

When I shrink down my browser, the carousel (the black box) resizes as per the responsive design. 当我缩小浏览器时,轮播(黑框)会根据响应设计调整大小。 When it reaches a certain width, the green box automatically toggles off and disappears a bar with a button for Open / Close. 当达到一定宽度时,绿色框会自动关闭,并消失带有用于打开/关闭按钮的条形图。

When the carousel is full size, the green box works just fine. 当轮播已满时,绿色框可以正常工作。 It is when the black box is shrunk that the green box no longer appears. 当黑框缩小时,绿色框不再出现。 When I inspect the element, I can see my code is firing off something, however, the green box is not visible on my screen. 当我检查元素时,我可以看到我的代码正在触发某些操作,但是,绿色框在屏幕上不可见。

You can add media queries in javascript too. 您也可以在javascript中添加媒体查询。

You just need to change the 500px to whatever you want and add the code into the if you want to use. 你只需要改变500px任何你想要的,并把代码添加到if你想使用。

// media query event handler
if (matchMedia) {
    var mq = window.matchMedia("(min-width: 500px)");
    mq.addListener(WidthChange);
    WidthChange(mq);
}

// media query change
function WidthChange(mq) {

    if (mq.matches) {
        // window width is at least 500px

    }
    else {
        // window width is less than 500px

        }
    }

}

Hope this helps, you can read more about it here . 希望对您有所帮助,您可以在此处阅读更多信息。

I believe that the code in your CSS @media property is playing a role here. 我相信CSS @media属性中的代码在这里发挥了作用。 Check and confirm. 检查并确认。

You can manually define how each screen may look. 您可以手动定义每个屏幕的外观。 For example: 例如:

@media screen and (max-width: 300px) {
    body {
        background-color: lightblue;
    }
}

This will change the screen color if screen size is less than 300. 如果屏幕尺寸小于300,则将更改屏幕颜色。

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

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