三、idangerous.swiper实现点击tab切换

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>Page Title</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <style type="text/css">
        body{
    
    margin:0;font-family:"microsoft yahei";font-size:13px;line-height:1.5;background:#eee;}

        .wrap{
    
    margin:100px auto 0 auto;}
        .tabs{
    
    height:40px;}
        .tabs a{
    
    display:block;float:left;width:33.33%;color:#333;text-align:center;background:#eee;line-height:40px;font-size:16px;text-decoration:none;}
        .tabs a.active{
    
    color:#fff;background:#333;border-radius:5px 5px 0px 0px;}
        .swiper-container{
    
    background:#333;height:325px;border-radius:0 0 5px 5px;width:100%;border-top:0;}
        .swiper-slide{
    
    height:325px;width:100%;background:none;color:#fff;}
        .content-slide{
    
    padding:40px;}
        .content-slide p{
    
    text-indent:2em;line-height:1.9;}
    </style>
    <link rel="stylesheet" href="css/idangerous.swiper.css">
</head>
<body>
    <div class="wrap">
        <div class="tabs">
            <a href="#" hidefocus="true" class="active">手机端</a>
            <a href="#" hidefocus="true">选项卡</a>
            <a href="#" hidefocus="true">切换效果</a>
        </div>    
        <div class="swiper-container">
            <div class="swiper-wrapper">
            <div class="swiper-slide">
                <div class="content-slide">
                <h2>AAAAAAAAAAAAAAAAAAAAA</h2>
                <p>AAAAAAAAAAAAAAAAAAAAA</p>
                <p>AAAAAAAAAAAAAAAAAAAAA</p>
                <p>AAAAAAAAAAAAAAAAAAAAA</p>
            </div>
            </div>
            <div class="swiper-slide">
                <div class="content-slide">
                <h2>BBBBBBBBBBBBBBBBBB</h2>
                <p>BBBBBBBBBBBBBBBBBB</p>
                <p>BBBBBBBBBBBBBBBBBB</p>
                <p>BBBBBBBBBBBBBBBBBB</p>
            </div>
            </div>
            <div class="swiper-slide">
                <div class="content-slide">
                <h2>CCCCCCCCCCCCCCCCCCCCCCCC</h2>
                <p>CCCCCCCCCCCCCCCCCCCCCCCC</p>
                <p>CCCCCCCCCCCCCCCCCCCCCCCC</p>
                <p>CCCCCCCCCCCCCCCCCCCCCCCC</p>
            </div>
            </div>
        </div>
    </div>
    </div>

    <script type="text/javascript" src="js/jquery-1.10.1.min.js"></script> 
    <script type="text/javascript" src="js/idangerous.swiper.min.js"></script> 
    <script type="text/javascript">
    var tabsSwiper = new Swiper('.swiper-container',{
    
    
        speed:500,
        onSlideChangeStart: function(){
    
    
            $(".tabs .active").removeClass('active');
            $(".tabs a").eq(tabsSwiper.activeIndex).addClass('active');
        }
    });

    $(".tabs a").on('touchstart mousedown',function(e){
    
    
        e.preventDefault()
        $(".tabs .active").removeClass('active');
        $(this).addClass('active');
        tabsSwiper.swipeTo($(this).index());
    });

    $(".tabs a").click(function(e){
    
    
        e.preventDefault();
    });
    </script>
</body>
</html>

猜你喜欢

转载自blog.csdn.net/weixin_42645716/article/details/102918793