当前位置: 首页 > 知识库问答 >
问题:

在mobile view中,我们希望显示每个div的div底部

杜成和
2023-03-14

在桌面视图中,输出是正确的,但在移动视图中,我们希望生成每个div都有自己的描述。

现在我的问题是描述显示在所有四个元素之后,我们希望在移动视图中显示每个div的底部。

任何人都可以通过jQuery帮助我。我试图在jQuery的帮助下使用偏移量和高度,但这是行不通的。

null

$(".trust-datail").hide();
$(".trust-wrap").each(function (i) {
    $(this).attr('id', +i);
});

$(".trust-datail").each(function (i) {
    $(this).addClass("tab_" + i);
});

$(".trust-wrap").click(function () {
    $(".trust-datail").slideUp();
    var id = $(this).attr('id');

    if ($(".tab_" + id).is(':visible')) {
        $(".tab_" + id).slideUp();
    }
    else {
        $(".tab_" + id).slideDown();
    }
});
$(".close-new").click(function () {
    $(this).parent(".trust-datail").slideUp();
});
.trust-wrap {
  border-radius: 5px;
  box-shadow: 0 0 20px 0 rgba(0, 0, 0, 0.1);
  margin-bottom: 30px;
  text-align: center;
  transition: all 0.2s ease 0s;
}
.trust-wrap img {
  border-top-left-radius: 5px;
  border-top-right-radius: 5px;
  margin:0 auto;
}
.trust-wrap h4 {
  font-weight: bold;
  margin: 25px 0;
  font-size:15px;
}
.trust-datail {
  background: #000;
  border-radius: 5px;
  margin: auto auto 50px;
  padding: 20px;
  position: relative;
  width: 100%;
}
.close-new {
  cursor: pointer;
  position: absolute;
  right: 20px;
  text-align: right;
}
.trust-datail h5 {
  color: #fff;
  font-size: 18px;
  font-weight: bold;
  margin: 0 0 15px;
}
.trust-datail p {
  color: #fff;
  margin: 0;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<div class="container">
  <div class="member_wrap">
    <div class="member_box">
      <div class="row">
        <div class="col-sm-3 chand">
          <div class="trust-wrap" id="8">
            <img src="http://lorempixel.com/output/people-q-c-250-250-9.jpg" alt="" class="img-responsive">
            <h4>Lorem Ipsum1</h4>
            <div class="clearfix"></div>
          </div>
        </div>
        <div class="col-sm-3 chand">
          <div class="trust-wrap" id="9">
            <img src="http://lorempixel.com/output/city-q-c-250-250-4.jpg" alt="" class="img-responsive">
            <h4>Lorem Ipsum2</h4>
            <div class="clearfix"></div>
          </div>
        </div>
        <div class="col-sm-3 chand">
          <div class="trust-wrap" id="10">
            <img src="http://lorempixel.com/output/people-q-c-250-250-9.jpg" alt="" class="img-responsive">
            <h4>Lorem Ipsum3</h4>
            <div class="clearfix"></div>
          </div>
        </div>
        <div class="col-sm-3 chand">
          <div class="trust-wrap" id="11">
            <img src="http://lorempixel.com/output/city-q-c-250-250-4.jpg" alt="" class="img-responsive">
            <h4>Lorem Ipsum4</h4>
            <div class="clearfix"></div>
          </div>
        </div>
      </div>
  </div>
    <div class="trust-datail tab_8" style="display: none;">
      <div class="close-new">
          <img src="images/close-new.png">
      </div>
      <h5>Lorem Ipsum1</h5>
      <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries</p>
    </div>
    <div class="trust-datail tab_9" style="display: none;">
      <div class="close-new">
          <img src="images/close-new.png">
      </div>
      <h5>Lorem Ipsum2</h5>
      <p> Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries</p>
    </div>
    <div class="trust-datail tab_10" style="display: none;">
      <div class="close-new">
          <img src="images/close-new.png">
      </div>
      <h5>Lorem Ipsum3</h5>
      <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries</p>
    </div>
    <div class="trust-datail tab_11" style="display: none;">
      <div class="close-new">
          <img src="images/close-new.png">
      </div>
      <h5>Lorem Ipsum4</h5>
      <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries</p>
    </div>
  </div>
</div>

null

共有1个答案

王辉
2023-03-14

为您更新了答案

这对你管用。

我所做的是为您创建一个函数,并在$(window).load$(window).resize中调用它-

var cloneFun = function() {
  if ($(window).width() <= 420) {
    $(".trust-datail").each(function(i) {
      var clonId = "#" + i,
        clon = $(this).clone();
      $(clonId).find('.clearfix').before(clon);
      $(this).addClass('mob-none');
    });
  } else {

    $(".trust-datail").removeClass('mob-none');
  }
};

$(window).load(function() {
  cloneFun();
});

$(window).resize(function() {
  cloneFun();
});

此函数检查窗口大小,如果小于420px,它将复制您的div并将其粘贴到.trust-wrap

并且我使用.mob-none在移动视图中隐藏您的详细信息。

null

$(".trust-datail").hide();
$(".trust-wrap").each(function(i) {
  $(this).attr('id', +i);
});

$(".trust-datail").each(function(i) {
  $(this).addClass("tab_" + i);
});


$(".trust-wrap").click(function() {
  $(".trust-datail").slideUp();
  var id = $(this).attr('id');

  if ($(".tab_" + id).is(':visible')) {
    $(".tab_" + id).slideUp();
  } else {
    $(".tab_" + id).slideDown();
  }
});
$(".close-new").click(function() {
  $(this).parent(".trust-datail").slideUp();
});

var cloneFun = function() {
  if ($(window).width() <= 420) {
    $(".trust-datail").each(function(i) {
      var clonId = "#" + i,
        clon = $(this).clone();
      $(clonId).find('.clearfix').before(clon);
      $(this).addClass('mob-none');
    });
  } else {

    $(".trust-datail").removeClass('mob-none');
  }
};

$(window).load(function() {
  cloneFun();
});

$(window).resize(function() {
  cloneFun();
});
.trust-wrap {
  border-radius: 5px;
  box-shadow: 0 0 20px 0 rgba(0, 0, 0, 0.1);
  margin-bottom: 30px;
  text-align: center;
  transition: all 0.2s ease 0s;
}

.trust-wrap img {
  border-top-left-radius: 5px;
  border-top-right-radius: 5px;
  margin: 0 auto;
}

.trust-wrap h4 {
  font-weight: bold;
  margin: 25px 0;
  font-size: 15px;
}

.trust-datail {
  background: #000;
  border-radius: 5px;
  margin: auto auto 50px;
  padding: 20px;
  position: relative;
  width: 100%;
}

.close-new {
  cursor: pointer;
  position: absolute;
  right: 20px;
  text-align: right;
}

.trust-datail h5 {
  color: #fff;
  font-size: 18px;
  font-weight: bold;
  margin: 0 0 15px;
}

.trust-datail p {
  color: #fff;
  margin: 0;
}

.mob-none {
  display: none !important;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<div class="container">
  <div class="member_wrap">
    <div class="member_box">
      <div class="row">
        <div class="col-sm-3 chand">
          <div class="trust-wrap" id="8">
            <img src="http://lorempixel.com/output/people-q-c-250-250-9.jpg" alt="" class="img-responsive">
            <h4>Lorem Ipsum1</h4>
            <div class="clearfix"></div>
          </div>
        </div>
        <div class="col-sm-3 chand">
          <div class="trust-wrap" id="9">
            <img src="http://lorempixel.com/output/city-q-c-250-250-4.jpg" alt="" class="img-responsive">
            <h4>Lorem Ipsum2</h4>
            <div class="clearfix"></div>
          </div>
        </div>
        <div class="col-sm-3 chand">
          <div class="trust-wrap" id="10">
            <img src="http://lorempixel.com/output/people-q-c-250-250-9.jpg" alt="" class="img-responsive">
            <h4>Lorem Ipsum3</h4>
            <div class="clearfix"></div>
          </div>
        </div>
        <div class="col-sm-3 chand">
          <div class="trust-wrap" id="11">
            <img src="http://lorempixel.com/output/city-q-c-250-250-4.jpg" alt="" class="img-responsive">
            <h4>Lorem Ipsum4</h4>
            <div class="clearfix"></div>
          </div>
        </div>
      </div>
    </div>
    <div class="trust-datail tab_8" style="display: none;">
      <div class="close-new">
        <img src="images/close-new.png">
      </div>
      <h5>Lorem Ipsum1</h5>
      <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.
        It has survived not only five centuries</p>
    </div>
    <div class="trust-datail tab_9" style="display: none;">
      <div class="close-new">
        <img src="images/close-new.png">
      </div>
      <h5>Lorem Ipsum2</h5>
      <p> Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.
        It has survived not only five centuries</p>
    </div>
    <div class="trust-datail tab_10" style="display: none;">
      <div class="close-new">
        <img src="images/close-new.png">
      </div>
      <h5>Lorem Ipsum3</h5>
      <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.
        It has survived not only five centuries</p>
    </div>
    <div class="trust-datail tab_11" style="display: none;">
      <div class="close-new">
        <img src="images/close-new.png">
      </div>
      <h5>Lorem Ipsum4</h5>
      <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.
        It has survived not only five centuries</p>
    </div>
  </div>
</div>
 类似资料:
  • 问题内容: 在隐藏其父级Div的同时如何显示子Div?能做到吗? 我的代码如下: 问题答案: 我认为这是不可能的。 您可以使用javascript将元素拉出,或复制元素然后显示。 在jQuery中,您可以复制一个元素 然后附加到任何适当的可见元素。

  • 如何在行flex父级的开头显示两个div容器,在末尾显示第三个div容器?在下面的示例中,child-3应该位于右侧。 下面是一个包含所有孩子的快速示例,位于父项jsfiddle的开头

  • 我正在CodeIgniter上开发一个测验应用程序。 随机从数据库中挑选25个问题并显示给用户。 以下是我的代码: 我想在一个div上显示前10个结果。 当用户单击下一个按钮时,它会显示下一个10个结果。 (隐藏当前div并显示下一个) 我只想知道我如何打破结果,并限制每个分区10个问题。

  • 好的,我目前正在一个网站上工作,对于网站的一部分,我试图显示一些来自SQL数据库的数据。我希望数据以如下所示的方式显示: 本质上,这应该显示一条记录,但是,我的问题是,我的样式表的设置方式是,每个项目列表/行只允许显示三个项目div。我不太明白怎么做,所以每个div只能显示3条记录,然后用PHP重置。

  • 我需要帮助创建一个div,当你点击一个按钮时,里面有自定义超文本标记语言的div会被创建。 如果这是可能的(很可能是),我正在制作一个邮箱。 谢谢!!!

  • 问题内容: 我正在为我的女友开发这款游戏,而现在我在同一个问题上停留了几天。基本上,我希望她能够按5次“ Gather Wood”按钮,然后在她第五次按该按钮后立即弹出“ Create Fire”按钮。 1.问题是,无论我尝试以哪种方式编程要显示在第五个按钮上的方法,它都不会显示。 我将不胜感激任何编码技巧或大家认为我可以做的任何清理当前代码的事情。 这是收集木纽扣 这是创建按钮 问题答案: 基本