jQuery實(shí)現(xiàn)滑動(dòng)tab選項(xiàng)卡
本文實(shí)例為大家分享了jQuery實(shí)現(xiàn)滑動(dòng)tab選項(xiàng)卡的具體代碼,供大家參考,具體內(nèi)容如下
先上最終效果:
需求分析:
1.選項(xiàng)卡菜單數(shù)量不固定,菜單內(nèi)容不固定,導(dǎo)致了單個(gè)菜單和整體的寬度都是未知的,
2.第一個(gè)需求導(dǎo)致滑塊寬度也是不固定的
3.為了讓交互效果更好,滑塊需要添加過(guò)度動(dòng)畫(huà)
對(duì)滑塊的需求導(dǎo)致滑塊和菜單的html結(jié)構(gòu)必須分離,并使用了jQuery的offset方法獲取并設(shè)置位置,所有的div都使用了相對(duì)定位。
本案例的TAB選項(xiàng)卡可以比較方便的拓展、重復(fù)使用,只需修改少量值就可以直接食用
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>0908</title> <script src="http://lib.sinaapp.com/js/jquery/1.7.2/jquery.min.js"></script> <style> /*container容器只是為了水平居中,如不需要可以去掉這層嵌套*/ .container{ left: 50%; margin-top: 100px; float: left; cursor:pointer; position: relative; } .BG{ right: 50%; font-size: 0; background-color: #f2f2f2; border-radius: 30px; position: relative; } .container div{ font-size: 16px; line-height: 60px; } .list{ float: left; display: inline-block; padding: 0 50px; transition: color 0.5s; position: relative; z-index: 1; } /*這里的listH和listA順序不能換,有優(yōu)先級(jí),當(dāng)listA被使用時(shí)listH不起作用*/ .listH{ color: #ff8300; } .listA{ color: #fff; } /*滑塊*/ #active{ width: 100px; height: 60px; border-radius: 30px; background-color: #ff8300; box-shadow: 0 5px 16px 0 rgba(255, 144, 0, 0.58); position: relative; z-index: 0; transition: left 0.5s,width 1s; } </style> <script> $(document).ready(function () { /*設(shè)置默認(rèn)激活的選項(xiàng)卡eq(i)*/ var aL = $(".list:eq(1)"); $("#active").width(aL.innerWidth()); $("#active").offset(aL.offset()); aL.addClass("listA"); /*為每個(gè)按鈕添加點(diǎn)擊事件*/ $(".list").click(function() { $("#active").width($(this).innerWidth()); //設(shè)置寬度 $("#active").offset($(this).offset()); //設(shè)置位置 $(this).addClass("listA"); $(".list").not(this).removeClass("listA"); }); /*hover效果*/ $(".list").hover(function () { $(this).addClass("listH") },function () { $(this).removeClass("listH") }) }); </script> </head> <body> <div class="container"> <div class="BG"> <div class="list">one</div> <div class="list">twotwo</div> <div class="list">threethreethree</div> <div class="list">four</div> <div class="list">fivefivefive</div> <div id="active"></div> </div> </div> </body> </html>
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
jquery 圖片縮放拖動(dòng)的簡(jiǎn)單實(shí)例
本篇文章只要是對(duì)jquery 圖片縮放拖動(dòng)的簡(jiǎn)單實(shí)例進(jìn)行了介紹,需要的朋友可以過(guò)來(lái)參考下,希望對(duì)大家有所幫助2014-01-01基于jquery的大眾點(diǎn)評(píng),分類(lèi)導(dǎo)航實(shí)現(xiàn)代碼
基于jquery的大眾點(diǎn)評(píng),分類(lèi)導(dǎo)航實(shí)現(xiàn)代碼,需要的朋友可以參考下。2011-08-08jQuery實(shí)現(xiàn)移動(dòng)端下拉展現(xiàn)新的內(nèi)容回彈動(dòng)畫(huà)
這篇文章主要介紹了jQuery實(shí)現(xiàn)移動(dòng)端下拉展現(xiàn)新的內(nèi)容回彈動(dòng)畫(huà),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-06-06jQuery實(shí)現(xiàn)的縱向下拉菜單實(shí)例詳解【附demo源碼下載】
這篇文章主要介紹了jQuery實(shí)現(xiàn)的縱向下拉菜單,結(jié)合實(shí)例形式分析了jQuery動(dòng)態(tài)操作頁(yè)面元素實(shí)現(xiàn)縱向下拉菜單的步驟與相關(guān)實(shí)現(xiàn)技巧,需要的朋友可以參考下2016-07-07jquery實(shí)現(xiàn)的代替?zhèn)鹘y(tǒng)checkbox樣式插件
這篇文章主要介紹了jquery實(shí)現(xiàn)的代替?zhèn)鹘y(tǒng)checkbox樣式插件,可實(shí)現(xiàn)滑動(dòng)選擇的效果,需要的朋友可以參考下2015-06-06jQuery操作checkbox選擇(list/table)
本文將介紹下checkbox list選擇及checkbox table選中附效果圖,感興趣的朋友可以參考下哈,希望可以幫助到你2013-04-04jquery通過(guò)closest選擇器修改上級(jí)元素的方法
這篇文章主要介紹了jquery通過(guò)closest選擇器修改上級(jí)元素的方法,實(shí)例分析了jQuery中closest選擇器的使用技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-03-03簡(jiǎn)單的jQuery banner圖片輪播實(shí)例代碼
這篇文章主要介紹了簡(jiǎn)單的jQuery banner圖片輪播實(shí)例代碼的相關(guān)資料,需要的朋友可以參考下2016-03-03基于jquery實(shí)現(xiàn)點(diǎn)擊左右按鈕圖片橫向滾動(dòng)
點(diǎn)擊左右按鈕圖片橫向滾動(dòng)jquery,一次滾動(dòng)四個(gè),圖片滾動(dòng)完成,自動(dòng)回到第一個(gè)版面,效果相當(dāng)不錯(cuò),感興趣的前端工程師們可以參考下2013-04-04