HTML CSS And JQuery 实现滑动显示框cid1034-代码设计

index.html

  1. <!DOCTYPE html>
  2. <html lang="en" dir="ltr">
  3. <head>
  4. <meta charset="utf-8">
  5. <title></title>
  6. <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js" charset="utf-8"></script>
  7. <script src="https://cdnjs.cloudflare.com/ajax/libs/OwlCarousel2/2.3.4/owl.carousel.min.js" charset="utf-8"></script>
  8. <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/OwlCarousel2/2.3.4/assets/owl.carousel.min.css">
  9. <link rel="stylesheet" href="style.css">
  10. </head>
  11. <body>
  12. <div class="blogs owl-carousel">
  13. <div class="blog">
  14. <img src="1.jpg" alt="">
  15. <div class="blog-description">
  16. <div class="categorie">Food</div>
  17. <h2 class="title">Lorem ipsum dolor sit amet</h2>
  18. <div class="date">Jan 13 2020</div>
  19. <a href="#" class="btn">Read More</a>
  20. </div>
  21. </div>
  22. <div class="blog">
  23. <img src="2.jpg" alt="">
  24. <div class="blog-description">
  25. <div class="categorie">Cars</div>
  26. <h2 class="title">Lorem ipsum dolor sit amet</h2>
  27. <div class="date">Jan 13 2020</div>
  28. <a href="#" class="btn">Read More</a>
  29. </div>
  30. </div>
  31. <div class="blog">
  32. <img src="3.jpg" alt="">
  33. <div class="blog-description">
  34. <div class="categorie">Coding</div>
  35. <h2 class="title">Lorem ipsum dolor sit amet</h2>
  36. <div class="date">Jan 13 2020</div>
  37. <a href="#" class="btn">Read More</a>
  38. </div>
  39. </div>
  40. <div class="blog">
  41. <img src="4.jpg" alt="">
  42. <div class="blog-description">
  43. <div class="categorie">Sports</div>
  44. <h2 class="title">Lorem ipsum dolor sit amet</h2>
  45. <div class="date">Jan 13 2020</div>
  46. <a href="#" class="btn">Read More</a>
  47. </div>
  48. </div>
  49. </div>
  50. <script type="text/javascript">
  51. $(".owl-carousel").owlCarousel({
  52. items: 2,
  53. margin: 20,
  54. loop: true,
  55. center: true,
  56. dots: false
  57. });
  58. </script>
  59. </body>
  60. </html>
<!DOCTYPE html>
<html lang="en" dir="ltr">
  <head>
    <meta charset="utf-8">
    <title></title>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js" charset="utf-8"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/OwlCarousel2/2.3.4/owl.carousel.min.js" charset="utf-8"></script>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/OwlCarousel2/2.3.4/assets/owl.carousel.min.css">
    <link rel="stylesheet" href="style.css">
  </head>
  <body>
    <div class="blogs owl-carousel">
      <div class="blog">
        <img src="1.jpg" alt="">
        <div class="blog-description">
          <div class="categorie">Food</div>
          <h2 class="title">Lorem ipsum dolor sit amet</h2>
          <div class="date">Jan 13 2020</div>
          <a href="#" class="btn">Read More</a>
        </div>
      </div>

      <div class="blog">
        <img src="2.jpg" alt="">
        <div class="blog-description">
          <div class="categorie">Cars</div>
          <h2 class="title">Lorem ipsum dolor sit amet</h2>
          <div class="date">Jan 13 2020</div>
          <a href="#" class="btn">Read More</a>
        </div>
      </div>

      <div class="blog">
        <img src="3.jpg" alt="">
        <div class="blog-description">
          <div class="categorie">Coding</div>
          <h2 class="title">Lorem ipsum dolor sit amet</h2>
          <div class="date">Jan 13 2020</div>
          <a href="#" class="btn">Read More</a>
        </div>
      </div>

      <div class="blog">
        <img src="4.jpg" alt="">
        <div class="blog-description">
          <div class="categorie">Sports</div>
          <h2 class="title">Lorem ipsum dolor sit amet</h2>
          <div class="date">Jan 13 2020</div>
          <a href="#" class="btn">Read More</a>
        </div>
      </div>
    </div>

    <script type="text/javascript">
      $(".owl-carousel").owlCarousel({
        items: 2,
        margin: 20,
        loop: true,
        center: true,
        dots: false
      });
    </script>
  </body>
</html>

style.css

  1. *{
  2. margin: 0;
  3. padding: 0;
  4. font-family: "Open Sans",sans-serif;
  5. }
  6. .blogs{
  7. position: absolute;
  8. top: 50%;
  9. transform: translateY(-50%);
  10. }
  11. .blog{
  12. overflow: hidden;
  13. position: relative;
  14. height: 100%;
  15. cursor: pointer;
  16. }
  17. .blog img{
  18. width: 100%;
  19. height: 100%;
  20. }
  21. .blog-description{
  22. position: absolute;
  23. bottom: -40px;
  24. background: #333333ca;
  25. width: 100%;
  26. padding: 40px;
  27. transition: .3s linear;
  28. }
  29. .blog:hover .blog-description{
  30. bottom: 0;
  31. }
  32. .categorie{
  33. display: inline-block;
  34. color: #e77f67;
  35. font-size: 18px;
  36. position: relative;
  37. padding: 0 22px;
  38. }
  39. .categorie::before{
  40. content: '';
  41. position: absolute;
  42. width: 14px;
  43. height: 2px;
  44. background: #e77f67;
  45. left: 0;
  46. top: 13px;
  47. }
  48. .categorie::after{
  49. content: '';
  50. position: absolute;
  51. width: 14px;
  52. height: 2px;
  53. background: #e77f67;
  54. right: 0;
  55. top: 13px;
  56. }
  57. .title{
  58. color: #fff;
  59. font-weight: 500;
  60. margin: 5px 0;
  61. }
  62. .date{
  63. font-style: italic;
  64. color: #e77f67;
  65. margin-bottom: 20px;
  66. }
  67. .btn{
  68. display: inline-block;
  69. color: #e77f67;
  70. text-decoration: none;
  71. border: 1px solid #e77f67;
  72. padding: 6px 20px;
  73. opacity: 0;
  74. transition: .3s linear;
  75. }
  76. .blog:hover .btn{
  77. opacity: 1;
  78. }
  79. .btn:hover{
  80. color: #fff;
  81. background: #e77f67;
  82. }
  83. .owl-stage{
  84. display: flex !important;
  85. }
*{
  margin: 0;
  padding: 0;
  font-family: "Open Sans",sans-serif;
}

.blogs{
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
}

.blog{
  overflow: hidden;
  position: relative;
  height: 100%;
  cursor: pointer;
}

.blog img{
  width: 100%;
  height: 100%;
}

.blog-description{
  position: absolute;
  bottom: -40px;
  background: #333333ca;
  width: 100%;
  padding: 40px;
  transition: .3s linear;
}

.blog:hover .blog-description{
  bottom: 0;
}

.categorie{
  display: inline-block;
  color: #e77f67;
  font-size: 18px;
  position: relative;
  padding: 0 22px;
}

.categorie::before{
  content: '';
  position: absolute;
  width: 14px;
  height: 2px;
  background: #e77f67;
  left: 0;
  top: 13px;
}

.categorie::after{
  content: '';
  position: absolute;
  width: 14px;
  height: 2px;
  background: #e77f67;
  right: 0;
  top: 13px;
}

.title{
  color: #fff;
  font-weight: 500;
  margin: 5px 0;
}

.date{
  font-style: italic;
  color: #e77f67;
  margin-bottom: 20px;
}

.btn{
  display: inline-block;
  color: #e77f67;
  text-decoration: none;
  border: 1px solid #e77f67;
  padding: 6px 20px;
  opacity: 0;
  transition: .3s linear;
}

.blog:hover .btn{
  opacity: 1;
}

.btn:hover{
  color: #fff;
  background: #e77f67;
}

.owl-stage{
  display: flex !important;
}

让链接同时具备两种打开方式

获取源码: Sliding Blogs
下载数:14人次, 文件大小: 888.1 KB, 上传日期: 2022年-12 月-21日

公众号回复:gcode  获取解压密码

qrcode_for_gh_6ea2c28a1709_258 (1)

2,888 人查阅

类似文章