jQuery和CSS3变形全屏网站搜索框

  • 源码大小:5.12KB
  • 所需积分:1积分
  • 源码编号:19JP-3683
  • 浏览次数:804次
  • 最后更新:2023年07月10日
  • 所属栏目:表单
本站默认解压密码:19jp.com 或 19jp_com

简介

在过去的几年里,网页设计的一个新趋势是创造全屏网站搜索体验。

这是一个搜索框,它充分利用了网页及其提供的所有房地产,展示了搜索功能和一些非常酷的全屏效果。

这可以使用css3转换和转换属性来完成,并且只需要一点jquery来帮助清理我们的html代码。

如何使用它:

1.为全屏网站搜索框创建HTML。请注意,我们在搜索/关闭图标时使用了字体真棒的标志性字体。

  1. <!-- Close Button -->
  2. <div class="close-btn">
  3. <span class="fas fa-times"></span>
  4. </div>
  5.  
  6. <!-- Search Wrapper -->
  7. <div class="wrapper">
  8. <!-- Search Button -->
  9. <div class="search-btn">
  10. <span class="fas fa-search"></span>
  11. </div>
  12. <!-- Search Box -->
  13. <div class="search-data">
  14. <input type="text" required>
  15. <div class="line"></div>
  16. <label>Type to search..</label>
  17. <span class="fas fa-search"></span>
  18. </div>
  19. </div>

2.必要的CSS和CSS3样式。

  1. .wrapper, .search-data{
  2. top: 50%;
  3. left: 50%;
  4. transform: translate(-50%, -50%);
  5. }
  6. .wrapper{
  7. position: fixed;
  8. height: 0px;
  9. width: 0px;
  10. border-radius: 100%;
  11. background: linear-gradient(-135deg, #c850c0, #4158d0);
  12. transition: all 0.4s linear;
  13. }
  14. .wrapper.active{
  15. height: 4000px;
  16. width: 4000px;
  17. }
  18. .search-btn{
  19. position: absolute;
  20. top: 50%;
  21. left: 50%;
  22. transform: translate(-50%, -50%);
  23. height: 60px;
  24. width: 60px;
  25. text-align: center;
  26. cursor: pointer;
  27. border-radius: 50%;
  28. background: linear-gradient(-135deg, #c850c0, #4158d0);
  29. }
  30. .search-btn span{
  31. color: #fff;
  32. font-size: 22px;
  33. line-height: 60px;
  34. }
  35. .search-data{
  36. position: absolute;
  37. height: 50px;
  38. width: 400px;
  39. display: flex;
  40. text-align: center;
  41. /* display: none; */
  42. }
  43. .search-data input{
  44. height: 100%;
  45. width: 100%;
  46. background: none;
  47. border: none;
  48. outline: none;
  49. font-size: 22px;
  50. font-weight: 500;
  51. color: #fff;
  52. }
  53. .search-data .line{
  54. position: absolute;
  55. height: 3px;
  56. width: 100%;
  57. background: #fff;
  58. bottom: 0;
  59. transform: scaleX(0);
  60. transition: transform 0.4s 0.3s linear;
  61. }
  62. .search-data .line.active{
  63. transform: scaleX(1);
  64. }
  65. .search-data label{
  66. position: absolute;
  67. top: 50%;
  68. left: 0;
  69. font-size: 20px;
  70. transform: translateY(-50%);
  71. pointer-events: none;
  72. color: rgba(255,255,255,0.7);
  73. }
  74. .search-data input:valid ~ label{
  75. opacity: 0;
  76. }
  77. .search-data span{
  78. color: #fff;
  79. position: absolute;
  80. width: 50px;
  81. font-size: 25px;
  82. right: 0;
  83. top: 0;
  84. line-height: 45px;
  85. cursor: pointer;
  86. }
  87. .close-btn{
  88. position: absolute;
  89. z-index: 99;
  90. right: 25px;
  91. top: 25px;
  92. font-size: 25px;
  93. color: #fff;
  94. cursor: pointer;
  95. }
  96. .search-data, .search-data span,
  97. .search-data label, .close-btn{
  98. display: none;
  99. }

3.在结束body标记之前加载最新的jQuery库。

  1. <script src="/path/to/cdn/jquery.min.js"></script>

4.启用全屏搜索框的主JavaScript(jQuery脚本)。

  1. $(".search-btn").click(function(){
  2. $(".wrapper").addClass("active");
  3. $(this).css("display", "none");
  4. $(".search-data").fadeIn(500);
  5. $(".close-btn").fadeIn(500);
  6. $(".search-data .line").addClass("active");
  7. setTimeout(function(){
  8. $("input").focus();
  9. $(".search-data label").fadeIn(500);
  10. $(".search-data span").fadeIn(500);
  11. }, 800);
  12. });
  13.  
  14. $(".close-btn").click(function(){
  15. $(".wrapper").removeClass("active");
  16. $(".search-btn").fadeIn(800);
  17. $(".search-data").fadeOut(500);
  18. $(".close-btn").fadeOut(500);
  19. $(".search-data .line").removeClass("active");
  20. $("input").val("");
  21. $(".search-data label").fadeOut(500);
  22. $(".search-data span").fadeOut(500);
  23. });

预览截图