简体   繁体   English

使用引导模式作为成人内容警告的问题

[英]Issue on using bootstrap modal as adult content warning

I'm trying to make a content warning for a wordpress site project with some potentially mature contents.我正在尝试为具有一些潜在成熟内容的 wordpress 站点项目发出内容警告。 I tried using bootstrap modal which is called by jquery, but the problem is it only overlays the page when the whole page itself gets done loading.我尝试使用由 jquery 调用的引导模式,但问题是它只在整个页面本身完成加载时覆盖页面。

It kills the purpose since the page will load first unblocked by the overlay.它杀死了目的,因为页面将首先加载,不会被覆盖层阻止。

I want to ask if there is a way to load and open the bootstrap modal before the page content/body starts loading.我想问一下是否有办法在页面内容/正文开始加载之前加载和打开引导模式。 Or if there isn't any advisable ways on using the modal for such purpose, what are my possible alternatives?或者,如果出于此类目的使用模态没有任何可取的方法,我可能的替代方案是什么? Thank you.谢谢你。

One possibility with jQuery would include wrapping your current web page inside a .page-wrap class with the css property of display: none . jQuery 的一种可能性是将当前网页包装在.page-wrap类中,并使用display: none的 css 属性。

Sibling to this .page-wrap you could create the page that will appear once everything has loaded, the .mature-content-warning that will have a button to continue to view the website.与此.page-wrap兄弟姐妹,您可以创建在所有内容都加载后将出现的页面, .mature-content-warning将有一个按钮以继续查看该网站。

Once the user clicks the .continue button, the page will load in.一旦用户点击.continue按钮,页面就会加载进来。

  <div class="page-wrap" style="display: none;">
    <h1>This is your site.</h1>
  </div>

  <div class="mature-content-warning">

    <div class="modal fade" id="myModal">
      <div class="modal-dialog">
        <div class="modal-content">
          <div class="modal-header">
            <h4 class="modal-title">Mature Content Warning</h4>
          </div>
          <div class="modal-body">
            <p class="lead">Are you 18 yrs old?</p>
          </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-success continue" data-dismiss="modal">Yes</button>
          </div>
        </div><!-- /.modal-content -->
      </div><!-- /.modal-dialog -->
    </div><!-- /.modal -->

  </div>

  <!-- vendors -->
  <script src="vendors/jquery-1.11.3.min.js"></script>
  <script src="vendors/bootstrap-3.3.4-dist/js/bootstrap.min.js"></script>

  <script>
    $(document).ready(function() {

      $(window).on('load', function() {
        $('#myModal').modal('show');
      });

      $('.continue').on('click', function() {
        $('.mature-content-warning').css('display', 'none');
        $('.page-wrap').fadeIn();
      });

    });
  </script>

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

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