练习题4_猫眼电影移动端.html 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Document</title>
  7. <script src="./rem.js"></script>
  8. <link rel="stylesheet" href="./css/iconfont.css">
  9. <style>
  10. body {
  11. margin: 0;
  12. }
  13. ul {
  14. margin: 0;
  15. padding: 0;
  16. }
  17. li {
  18. list-style: none;
  19. }
  20. p{
  21. margin: 0;
  22. }
  23. .container {
  24. font-size: .36rem;
  25. }
  26. /* 头部 */
  27. .top-head{
  28. position: fixed;
  29. top: 0;
  30. left: 0;
  31. width: 100vw;
  32. }
  33. .top-head header {
  34. background-color: #e54847;
  35. height: 0.7rem;
  36. text-align: center;
  37. line-height: 0.7rem;
  38. position: relative;
  39. }
  40. .top-head header span {
  41. color: #fff;
  42. }
  43. .top-head .more-btn {
  44. position: absolute;
  45. right: 20px;
  46. top: 0;
  47. }
  48. .top-head .more-btn ul {
  49. display: none;
  50. position: absolute;
  51. top: 0.5rem;
  52. left: -1.5rem;
  53. width: 2rem;
  54. z-index: 1;
  55. box-shadow: 0 .06rem .18rem 0 rgba(0, 0, 0, .1);
  56. }
  57. .top-head .more-btn .active {
  58. display: block;
  59. }
  60. .top-head .more-btn ul li {
  61. height: .9rem;
  62. line-height: .9rem;
  63. font-size: 0.3rem;
  64. text-align: center;
  65. color: #333;
  66. background-color: #fff;
  67. border-bottom: .02rem solid #f0f0f0;
  68. }
  69. .top-head .more-btn img {
  70. width: .3rem;
  71. height: .3rem;
  72. }
  73. /* 头部导航 */
  74. .top-head nav {
  75. height: .9rem;
  76. border-bottom: 0.02rem solid #e6e6e6;
  77. display: flex;
  78. justify-content: space-between;
  79. padding: 0 .2rem;
  80. align-items: center;
  81. background-color: #fff;
  82. }
  83. .top-head .nav-center {
  84. flex-grow: 3;
  85. margin: 0 .2rem;
  86. position: relative;
  87. }
  88. .top-head .nav-center ul {
  89. display: flex;
  90. justify-content: space-around;
  91. font-size: .3rem;
  92. font-weight: 700;
  93. color: #666;
  94. align-items: center;
  95. }
  96. .top-head .nav-center .bottom-line {
  97. position: absolute;
  98. bottom: -5px;
  99. width: .4rem;
  100. height: 3px;
  101. border-radius: 3px;
  102. background-color: #f03d37;
  103. transition: left .1s linear;
  104. }
  105. .top-head .nav-center[data-tab-val="one"] .bottom-line {
  106. left: 4vw;
  107. }
  108. .top-head .nav-center[data-tab-val="two"] .bottom-line {
  109. left: 18vw;
  110. }
  111. .top-head .nav-center[data-tab-val="three"] .bottom-line {
  112. left: 32vw;
  113. }
  114. .top-head .nav-center[data-tab-val="four"] .bottom-line {
  115. left: 49vw;
  116. }
  117. .top-head .nav-center .active {
  118. color: #333;
  119. font-size: .34rem;
  120. }
  121. .top-head .nav-right {
  122. flex-grow: 1;
  123. display: flex;
  124. align-items: center;
  125. justify-content: center;
  126. }
  127. .top-head .nav-right img {
  128. width: .4rem;
  129. height: .4rem;
  130. }
  131. .top-head .nav-left {
  132. display: flex;
  133. align-items: center;
  134. }
  135. .top-head .nav-left span {
  136. color: #666;
  137. font-size: .3rem;
  138. }
  139. .top-head .nav-left i {
  140. border-top: 5px solid #666;
  141. border-left: 5px solid transparent;
  142. border-right: 5px solid transparent;
  143. border-bottom: 5px solid transparent;
  144. transform: translate(3px, 3px);
  145. }
  146. /* 底部导航 */
  147. .bottom-nav{
  148. height: 1rem;
  149. width: 100vw;
  150. border-top: .01rem solid #d8d8d8;
  151. position: fixed;
  152. bottom: 0;
  153. left: 0;
  154. background-color: #fff;
  155. }
  156. .bottom-nav ul{
  157. display: flex;
  158. }
  159. .bottom-nav ul li{
  160. flex-grow: 1;
  161. height: 1rem;
  162. display: flex;
  163. flex-direction: column;
  164. align-items: center;
  165. justify-content: center;
  166. color: #696969;
  167. }
  168. .bottom-nav ul .active{
  169. color: #f03d37;
  170. }
  171. .bottom-nav ul li span{
  172. font-size: .2rem;
  173. }
  174. .bottom-nav li i{
  175. font-size: .5rem;
  176. }
  177. /* 中间内容区域 */
  178. .center-content{
  179. padding-top: 1.6rem;
  180. padding-bottom: 1rem;
  181. }
  182. .center-content .love-move{
  183. padding: 12px 15px;
  184. }
  185. .center-content .love-move .move-box{
  186. width: 85px;
  187. height: 115px;
  188. }
  189. .center-content .love-move img{
  190. width: 100%;
  191. height: 100%;
  192. }
  193. .center-content .love-move .cc-title{
  194. font-size: 14px;
  195. color: #333;
  196. margin-bottom: 12px;
  197. }
  198. .center-content .love-move .move-box{
  199. position: relative;
  200. margin-bottom: 6px;
  201. }
  202. .center-content .love-move .rating-content{
  203. position: absolute;
  204. bottom: 0;
  205. left: 0;
  206. height: 35px;
  207. width: 100%;
  208. font-size: 11px;
  209. color: #faaf00;
  210. background-image: linear-gradient(-180deg,rgba(77,77,77,0),#000);
  211. }
  212. .center-content .rating-content span{
  213. position: absolute;
  214. left: 4px;
  215. bottom: 2px;
  216. }
  217. .center-content .love-move .move-title{
  218. font-size: 13px;
  219. color: #222;
  220. }
  221. .center-content .love-move ul{
  222. display: flex;
  223. overflow: scroll;
  224. }
  225. .center-content .love-move li{
  226. margin-right: 10px;
  227. }
  228. ::-webkit-scrollbar{
  229. display: none;
  230. width: 0;
  231. height: 0;
  232. }
  233. </style>
  234. </head>
  235. <body>
  236. <div class="container">
  237. <div class="top-head">
  238. <header>
  239. <span>猫眼电影</span>
  240. <div class="more-btn">
  241. <img id="list-btn" src="./img/list.png" alt="list">
  242. <ul class="">
  243. <li>首页</li>
  244. <li>榜单</li>
  245. <li>热点</li>
  246. <li>商城</li>
  247. </ul>
  248. </div>
  249. </header>
  250. <nav>
  251. <div class="nav-left">
  252. <span>哈尔滨</span>
  253. <i></i>
  254. </div>
  255. <div class="nav-center" data-tab-val="one">
  256. <ul>
  257. <li data-tab="one" class="active">热播</li>
  258. <li data-tab="two">影院</li>
  259. <li data-tab="three">待映</li>
  260. <li data-tab="four">经典电影</li>
  261. </ul>
  262. <div class="bottom-line"></div>
  263. </div>
  264. <div class="nav-right">
  265. <img src="./img/search.png" alt="img">
  266. </div>
  267. </nav>
  268. </div>
  269. <div class="center-content">
  270. <div class="love-move">
  271. <p class="cc-title">最受好评电影</p>
  272. <ul>
  273. <li>
  274. <div class="move-box">
  275. <img src="./img/move.jpg" alt="move">
  276. <div class="rating-content">
  277. <span>观众评分 8.9</span>
  278. </div>
  279. </div>
  280. <p class="move-title"> 神偷奶爸4</p>
  281. </li>
  282. <li>
  283. <div class="move-box">
  284. <img src="./img/move.jpg" alt="move">
  285. <div class="rating-content">
  286. <span>观众评分 8.9</span>
  287. </div>
  288. </div>
  289. <p class="move-title"> 神偷奶爸4</p>
  290. </li>
  291. <li>
  292. <div class="move-box">
  293. <img src="./img/move.jpg" alt="move">
  294. <div class="rating-content">
  295. <span>观众评分 8.9</span>
  296. </div>
  297. </div>
  298. <p class="move-title"> 神偷奶爸4</p>
  299. </li>
  300. <li>
  301. <div class="move-box">
  302. <img src="./img/move.jpg" alt="move">
  303. <div class="rating-content">
  304. <span>观众评分 8.9</span>
  305. </div>
  306. </div>
  307. <p class="move-title"> 神偷奶爸4</p>
  308. </li>
  309. <li>
  310. <div class="move-box">
  311. <img src="./img/move.jpg" alt="move">
  312. <div class="rating-content">
  313. <span>观众评分 8.9</span>
  314. </div>
  315. </div>
  316. <p class="move-title"> 神偷奶爸4</p>
  317. </li>
  318. <li>
  319. <div class="move-box">
  320. <img src="./img/move.jpg" alt="move">
  321. <div class="rating-content">
  322. <span>观众评分 8.9</span>
  323. </div>
  324. </div>
  325. <p class="move-title"> 神偷奶爸4</p>
  326. </li>
  327. <li>
  328. <div class="move-box">
  329. <img src="./img/move.jpg" alt="move">
  330. <div class="rating-content">
  331. <span>观众评分 8.9</span>
  332. </div>
  333. </div>
  334. <p class="move-title"> 神偷奶爸4</p>
  335. </li>
  336. <li>
  337. <div class="move-box">
  338. <img src="./img/move.jpg" alt="move">
  339. <div class="rating-content">
  340. <span>观众评分 8.9</span>
  341. </div>
  342. </div>
  343. <p class="move-title"> 神偷奶爸4</p>
  344. </li>
  345. </ul>
  346. </div>
  347. <div class="move-list"></div>
  348. </div>
  349. <div class="bottom-nav">
  350. <ul>
  351. <li class="active">
  352. <i class="iconfont icon-dianying"></i>
  353. <span>电影/影院</span>
  354. </li>
  355. <li>
  356. <i class="iconfont icon-shipin-"></i>
  357. <span>视频</span>
  358. </li>
  359. <li>
  360. <i class="iconfont icon-yanchu"></i>
  361. <span>演出</span>
  362. </li>
  363. <li>
  364. <i class="iconfont icon-yonghu"></i>
  365. <span>我的</span>
  366. </li>
  367. </ul>
  368. </div>
  369. </div>
  370. <script>
  371. let listBtn = document.querySelector("#list-btn");
  372. //控制顶部菜单栏的显示和隐藏
  373. listBtn.ontouchstart = function () {
  374. //toggle 切换 菜单 ul 上面active类 如果有就移除 如果没有就添加
  375. this.nextElementSibling.classList.toggle("active");
  376. }
  377. let navCenter = document.querySelector(".nav-center");
  378. let navList = navCenter.querySelectorAll("li");
  379. // 循环为列表按钮添加点击事件
  380. for (let i = 0; i < navList.length; i++) {
  381. navList[i].ontouchstart = function (e) {
  382. // 循环消除所有按钮的选中状态
  383. for (let j = 0; j < navList.length; j++) {
  384. navList[j].classList.remove("active")
  385. }
  386. // 为当前按钮添加选中状态
  387. this.classList.add("active");
  388. // 获取当前按钮dataset值
  389. let thisTab = e.target.dataset.tab
  390. // 为父元素添加data-tab-val值以控制下划线的移动位置
  391. navCenter.setAttribute("data-tab-val", thisTab)
  392. // 向前地址中添加选中按钮的hash值
  393. location.hash = thisTab;
  394. }
  395. }
  396. // 监听hash值变化修改选中项
  397. window.onhashchange = function () {
  398. let thisHash = location.hash.substr(1).trim();
  399. if (thisHash) {
  400. navCenter.setAttribute("data-tab-val", thisHash);
  401. for (let i = 0; i < navList.length; i++) {
  402. if (navList[i].dataset.tab == thisHash) {
  403. navList[i].classList.add("active");
  404. } else {
  405. navList[i].classList.remove("active");
  406. }
  407. }
  408. }else{
  409. navCenter.setAttribute("data-tab-val", "one");
  410. for (let i = 0; i < navList.length; i++) {
  411. navList[i].classList.remove("active");
  412. }
  413. navList[0].classList.add("active");
  414. }
  415. }
  416. /**
  417. * 底部导航点击事件
  418. */
  419. let bottomNavLi = document.querySelector(".bottom-nav").querySelectorAll("li");
  420. for(let i=0;i<bottomNavLi.length;i++){
  421. bottomNavLi[i].ontouchstart = function(){
  422. for(let j=0;j<bottomNavLi.length;j++){
  423. bottomNavLi[j].classList.remove("active");
  424. }
  425. this.classList.add("active");
  426. }
  427. }
  428. </script>
  429. </body>
  430. </html>