移动端可滑动的tab栏,并进行切换

 

HTML内容

<div class="nav">
<div class="tab border-b" id="category">
<a href="javascript:;" rel="external nofollow" rel="external nofollow" class="curr">首页</a>
<a href="javascript:;" rel="external nofollow" rel="external nofollow" >专属</a>
<a href="javascript:;" rel="external nofollow" rel="external nofollow" >定制</a>
<a href="javascript:;" rel="external nofollow" rel="external nofollow" >商城</a>
<a href="javascript:;" rel="external nofollow" rel="external nofollow" >推荐</a>
<a href="javascript:;" rel="external nofollow" rel="external nofollow" >旅游</a>
<a href="javascript:;" rel="external nofollow" rel="external nofollow" >其他</a>
</div>

<div class="content">
<ul>
<li style="display: block">
首页对应的内容
</li>
<li>
专属
</li>
<li>
定制
</li>
<li>
商城
</li>
<li>

推荐

</li>

<li>
旅游

</li>
<!-- 其他 -->
<li>
其他

</li>
</ul>
</div>
</div>

css部分

/* tab区域 */
div, input, textarea, button, a {
-webkit-tap-highlight-color: rgba(255,255,255,0.2);
}
ul, li, ol{
list-style: none;
}
ul{
margin-bottom: 0;
margin-top: 0;
}
a {
color: #323232;
outline-style: none;
text-decoration: none;
}
.border-b {
position: relative;

}
.border-b:after {
top: auto;
bottom: 0;
}
.border-t:before, .border-b:after {
content: '';
position: absolute;
left: 0;
background: #ddd;
right: 0;
height: 1px;
-webkit-transform: scaleY(0.5);
transform: scaleY(0.5);
-webkit-transform-origin: 0 0;
transform-origin: 0 0;
}

.nav {
background-color: #fff;
text-align: center;
}
/* .nav .tab {
width: 34.375rem;
height: 3.75rem;
position: absolute;
top:5.875rem;
padding: 0.625rem 0.3125rem;

}
.tab a {
float: left;
font-size: 0.875rem;
width: 13%;
height: 2.56rem;
line-height:2.56rem;
display: inline-block;
text-align: center;
color: #ffffff;
} */
/* .tab a:last-child {
border-right: 0;
} */
.tab .curr {
border-bottom: 2px solid #FFFFFF;
color: #FFFFFF;
}
.curr1 {
border-bottom: 2px solid #F8007A;
color: #E12F32;

}
.content ul{
padding: 0;
}
.content ul li {
display: none;
width: 100%;
text-align: start;
padding: 1.25rem 0;
}
#category{
width: 100%;
display: inline;
white-space: nowrap;
overflow-x: scroll;
float: left;
overflow-y: hidden;
position: absolute;
top:140px;
left: 0;
}
#category a{
display: inline-block;
font-size: 0.875rem;
width: 5rem;
height: 1.875rem;
padding-left: 0.625rem;
color: #ffffff;
}

 

js区域

$(function(){
$('.mui-icon-arrowleft').on('tap',function(){
mui.toast('返回上一层')
})

$('.guanzhu').on('tap',function(){
if (toggle) {
$(this).attr("src", "images/guanzhu.png")
toggle = false;
} else {
$(this).attr("src", "images/2019-09-17-yiguanzhu.png")
toggle = true;
}
})
$(".tab a").click(function() {
$(this).addClass('curr').siblings().removeClass('curr');
var index = $(this).index();
console.log(index)

$('.nav .content li').hide();
$('.nav .content li:eq(' + index + ')').show();
});

$('.tuangou').on('tap',function(){
mui.toast('跳转到购物车页面')
})
$('.liji').on('tap',function(){
mui.toast('立即购买')
})
var toggle = true;
$(".cang").click(function() {
if (toggle) {
$(this).attr("src", "images/cart_in.png")
toggle = false;
} else {
$(this).attr("src", "images/cart_in2.png")
toggle = true;
}
});

$('.addcart').on('tap',function(){
mui.toast('立即购买')
})
})

转载于:https://www.cnblogs.com/Progress-/p/11542674.html

[removed] $(function() { function setCurrentSlide(ele, index) { $(".swiper1 .swiper-slide").removeClass("selected"); ele.addClass("selected"); //swiper1.initialSlide=index; } var swiper1 = new Swiper('.swiper1', { // 设置slider容器能够同时显示的slides数量(carousel模式)。 // 可以设置为number或者 'auto'则自动根据slides的宽度来设定数量。 // loop模式下如果设置为'auto'还需要设置另外一个参数loopedSlides。 slidesPerView: 5.5, paginationClickable: true,//此参数设置为true时,点击分页器的指示点分页器会控制Swiper切换。 spaceBetween: 10,//slide之间的距离(单位px)。 freeMode: true,//默认为false,普通模式:slide滑动时只滑动一格,并自动贴合wrapper,设置为true则变为free模式,slide会根据惯性滑动且不会贴合。 loop: false,//是否可循环 onTab: function(swiper) { var n = swiper1.clickedIndex; } }); swiper1.slides.each(function(index, val) { var ele = $(this); ele.on("click", function() { setCurrentSlide(ele, index); swiper2.slideTo(index, 500, false); //mySwiper.initialSlide=index; }); }); var swiper2 = new Swiper('.swiper2', { //freeModeSticky 设置为true 滑动会自动贴合 direction: 'horizontal',//Slides的滑动方向,可设置水平(horizontal)或垂直(vertical)。 loop: false, // effect : 'fade',//淡入 //effect : 'cube',//方块 //effect : 'coverflow',//3D流 // effect : 'flip',//3D翻转 autoHeight: true,//自动高度。设置为true时,wrapper和container会随着当前slide的高度而发生变化。 onSlideChangeEnd: function(swiper) { //回调函数,swiper从一个slide过渡到另一个slide结束时执行。 var n = swiper.activeIndex; setCurrentSlide($(".swiper1 .swiper-slide").eq(n), n); swiper1.slideTo(n, 500, false); } }); }); [removed]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值