六月婷婷综合激情-六月婷婷综合-六月婷婷在线观看-六月婷婷在线-亚洲黄色在线网站-亚洲黄色在线观看网站

明輝手游網(wǎng)中心:是一個(gè)免費(fèi)提供流行視頻軟件教程、在線學(xué)習(xí)分享的學(xué)習(xí)平臺(tái)!

HTML完成移動(dòng)端固定懸浮半透明搜索框

[摘要]現(xiàn)在互聯(lián)網(wǎng)已經(jīng)有成千上百個(gè)網(wǎng)站,然而網(wǎng)站少不了的一個(gè)功能就是搜索,我們可以看到很多網(wǎng)站的搜索框各有不同,在移動(dòng)端也是如此。本文我們就和大家分享一種在移動(dòng)端固定在頁(yè)面頂部,半透明懸浮,能依稀看見(jiàn)部分輪播圖形式的搜索框。要制作這樣的搜索框,技術(shù)關(guān)鍵在于:fixed 搜索框定位opacity 設(shè)置透明度...
現(xiàn)在互聯(lián)網(wǎng)已經(jīng)有成千上百個(gè)網(wǎng)站,然而網(wǎng)站少不了的一個(gè)功能就是搜索,我們可以看到很多網(wǎng)站的搜索框各有不同,在移動(dòng)端也是如此。本文我們就和大家分享一種在移動(dòng)端固定在頁(yè)面頂部,半透明懸浮,能依稀看見(jiàn)部分輪播圖形式的搜索框。

11.jpg

要制作這樣的搜索框,技術(shù)關(guān)鍵在于:

fixed 搜索框定位

opacity 設(shè)置透明度

Solution. 解決

首先我們定義一個(gè) html 片段:

<!-- 搜索框 -->
<header class="bar">
  <form name="search" class="search" id="search" action="">
    <p class="search-row">
      <input type="search" name="word" id="word">
      <span class="placeholder "><span class="iconfont icon-sousuo"></span><span class="text">搜索</span></span>
    </p>
  </form>
</header>
<!-- 一個(gè)背景圖 實(shí)際上這里往往是輪播圖 -->
<p class="background">
  <img src="bg.jpg">
</p>

header 標(biāo)簽為搜索框,下面的 p 為一個(gè)背景圖。

同時(shí)附上 CSS 樣式:

<style type="text/css">
body {
  margin: 0;  padding: 0;
  font-size: 14px; font-family: "microsoft yahei",'Arial', 'Verdana','Helvetica', sans-serif;
}
.bar {
  position: fixed; top: 0; left: 0; right: 0; /* 決定了搜索框置頂 */
  height: 44px; padding: 0 10px;
  background-color: #fff; opacity: 0.8; /* 搜索框半透明效果 */
  z-index: 10;
}
.bar form {
  display: block; padding: 0;margin: 0;
}
.search-row {
  position: relative;
  height: 30px; padding: 7px 0;
}
.search-row input[type=search] {
  position: absolute; top: 7px;
  height: 30px; line-height: 21px; width: 100%; padding: 10px 15px 10px 30px;
  border: 0; border-radius: 6px; outline: 0; background-color: rgba(0,0,0,0.1);
  font-size: 16px; text-align: center;
  z-index: 100;
}
.search-row .placeholder {
  position: absolute; top: 2px; left: 0; right: 0;
  display: inline-block; height: 34px; line-height: 34px;
  border: 0; border-radius: 6px;
  font-size: 16px; text-align: center; color: #999;
  z-index: 1;  
}
.search-row .placeholder .iconfont {
  display: inline-block; width: 19px; line-height: 24px; padding: 10px 0; 
  font-size: 21px; color: #666;
}
.search-row .placeholder .text {
  line-height: 40px;
  vertical-align: top;
}
.background img {
  width: 100%;
}
.active:before {
  position: absolute; top: 11px; left: 5px; right: auto;
  display: block; margin-right: 0;
  font-size: 21px;
}
.active input[type=search] {
  text-align: left
}
.active .placeholder{
  display: none
}
</style>

很長(zhǎng)的一段 CSS 樣式,但是其核心就兩句話position: fixed; /* 決定了搜索框置頂 */ 和 background-color: #fff; opacity: 0.8; /* 搜索框半透明效果 */,其他的樣式均為了頁(yè)面的排版,排版的細(xì)節(jié)需要各位讀者自己寫(xiě)一遍理解,過(guò)程可能需要花費(fèi)點(diǎn)時(shí)間。

這樣我們就完成了一個(gè)靜態(tài)的搜索框:

11.jpg

備注:這里的搜索圖標(biāo)使用了 iconfont,讀者可自行到 iconfont矢量圖標(biāo)庫(kù) 下載。

至此,我們還需要通過(guò) JS 實(shí)現(xiàn)一些動(dòng)效:

201710170918224.gif

用于實(shí)現(xiàn)用戶(hù)切換輸入時(shí)「搜索」位置圖標(biāo)的切換,原理很簡(jiǎn)單,增加和移除 class 類(lèi),這些類(lèi)定義了樣式。

.active:before {
  position: absolute; top: 11px; left: 5px; right: auto;
  display: block; margin-right: 0;
  font-size: 21px;
}
.active input[type=search] {
  text-align: left
}
.active .placeholder{
  display: none
}
<script type="text/javascript">
/* 輸入框獲取到焦點(diǎn) 表示用戶(hù)正在輸入 */
$("#word").focusin(function() {
  $(".search-row").addClass("active iconfont icon-sousuo");
});
/* 輸入框失去焦點(diǎn) 表示用戶(hù)輸入完畢 */
$("#word").focusout(function() {
  /* 判斷用戶(hù)是否有內(nèi)容輸入 */
  if ($(this).val()=="") {
    /* 沒(méi)有內(nèi)容輸入 改變樣式 */
    $(".search-row").removeClass("active iconfont icon-sousuo");
  } else {
    /* 有內(nèi)容輸入 保持樣式 并提交表單 */
    $("#search").submit();
  }
});
</script>

備注:這里需要引入 jQuery,千萬(wàn)別忘了!

Extension. 擴(kuò)展

完整 html 代碼:

<!DOCTYPE html>
<html>
<head>
<title></title>
<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
<link rel="stylesheet" type="text/css" href="iconfont/iconfont.css">
<script type="text/javascript" src="jquery-1.11.1.min.js"></script>
<style type="text/css">
body {
  margin: 0;  padding: 0;
  font-size: 14px; font-family: "microsoft yahei",'Arial', 'Verdana','Helvetica', sans-serif;
}
.bar {
  position: fixed; top: 0; left: 0; right: 0; /* 決定了搜索框置頂 */
  height: 44px; padding: 0 10px;
  background-color: #fff; opacity: 0.8; /* 搜索框半透明效果 */
  z-index: 10;
}
.bar form {
  display: block; padding: 0;margin: 0;
}
.search-row {
  position: relative;
  height: 30px; padding: 7px 0;
}
.search-row input[type=search] {
  position: absolute; top: 7px;
  height: 30px; line-height: 21px; width: 100%; padding: 10px 15px 10px 30px;
  border: 0; border-radius: 6px; outline: 0; background-color: rgba(0,0,0,0.1);
  font-size: 16px; text-align: center;
  z-index: 100;
}
.search-row .placeholder {
  position: absolute; top: 2px; left: 0; right: 0;
  display: inline-block; height: 34px; line-height: 34px;
  border: 0; border-radius: 6px;
  font-size: 16px; text-align: center; color: #999;
  z-index: 1;  
}
.search-row .placeholder .iconfont {
  display: inline-block; width: 19px; line-height: 24px; padding: 10px 0; 
  font-size: 21px; color: #666;
}
.search-row .placeholder .text {
  line-height: 40px;
  vertical-align: top;
}
.background img {
  width: 100%;
}
.active:before {
  position: absolute; top: 11px; left: 5px; right: auto;
  display: block; margin-right: 0;
  font-size: 21px;
}
.active input[type=search] {
  text-align: left
}
.active .placeholder{
  display: none
}
</style>
</head>
<body>
<!-- 搜索框 -->
<header class="bar">
  <form name="search" class="search" id="search" action="">
    <p class="search-row">
      <input type="search" name="word" id="word">
      <span class="placeholder "><span class="iconfont icon-sousuo"></span><span class="text">搜索</span></span>
    </p>
  </form>
</header>
<!-- 一個(gè)背景圖 實(shí)際上這里往往是輪播圖 -->
<p class="background">
  <img src="bg.jpg">
</p>
</body>
<script type="text/javascript">
/* 輸入框獲取到焦點(diǎn) 表示用戶(hù)正在輸入 */
$("#word").focusin(function() {
  $(".search-row").addClass("active iconfont icon-sousuo");
});
/* 輸入框失去焦點(diǎn) 表示用戶(hù)輸入完畢 */
$("#word").focusout(function() {
  /* 判斷用戶(hù)是否有內(nèi)容輸入 */
  if ($(this).val()=="") {
    /* 沒(méi)有內(nèi)容輸入 改變樣式 */
    $(".search-row").removeClass("active iconfont icon-sousuo");
  } else {
    /* 有內(nèi)容輸入 保持樣式 并提交表單 */
    $("#search").submit();
  }
});
</script>
</html>

以上內(nèi)容就是HTML實(shí)現(xiàn)移動(dòng)端固定懸浮半透明搜索框的教程,希望大家在開(kāi)發(fā)中能幫助到大家。

相關(guān)推薦:

css制作好看的搜索框

如何用Js實(shí)現(xiàn)百度搜索框提示功能

分享8款CSS3搜索框

以上就是HTML實(shí)現(xiàn)移動(dòng)端固定懸浮半透明搜索框的詳細(xì)內(nèi)容,更多請(qǐng)關(guān)注php中文網(wǎng)其它相關(guān)文章!


網(wǎng)站建設(shè)是一個(gè)廣義的術(shù)語(yǔ),涵蓋了許多不同的技能和學(xué)科中所使用的生產(chǎn)和維護(hù)的網(wǎng)站。




主站蜘蛛池模板: 欧美一级片在线观看 | 欧美囗交| 亚洲视频色 | 青春草在线播放 | 色成网 | 在线视频国产一区 | 日韩v在线 | 日韩欧美区 | 中日韩国语视频在线观看 | 四虎影院免费在线播放 | 午夜影视在线视频观看免费 | 香港三级理论在线影院 | 欧美午夜a级限制福利片 | 日韩欧美一区二区三区不卡在线 | 亚洲ss| 午夜视频在线观看182tv | 天天射天 | 日韩a级片视频 | 一本草久 | 最新国语露脸精品国产 | 中文字幕欧美日韩在线不卡 | 武则天一级淫片免费放 | 亚洲欧美日韩在线播放 | 日日干夜夜操视频 | 天天操天天干天天玩 | 午夜老司机免费视频 | 伊人久久影院 | 欧美性视频在线播放黑人 | 亚洲a视频在线观看 | 日本黄色免费网址 | 日日摸夜夜添夜夜添特色大片 | 亚洲高清视频免费 | 最新精品亚洲成a人在线观看 | 欧美亚洲日本在线 | 日本成片免费高清 | 午夜毛片在线观看 | 亚洲欧美综合 | 深夜福利日韩 | 日韩一级片在线观看 | 亚洲欧美日韩国产综合久 | 四川农村女人一级毛片 |