swiper 스와이프 메뉴 클릭하면 가온데 오기 중 a링크 넘어가면 on 안먹힘

매출이 오르면 내리는 수수료! 지금 수수료센터에서 전자결제(PG)수수료 비교견적 신청해 보세요!
swiper 스와이프 메뉴 클릭하면 가온데 오기 중 a링크 넘어가면 on 안먹힘

QA

swiper 스와이프 메뉴 클릭하면 가온데 오기 중 a링크 넘어가면 on 안먹힘

본문

a.html
<div class="swiper-slide on"><a href="a.html"><span class="text">딸기</span></a></div>
<div class="swiper-slide"><a href="b.html"><span class="text">수박</span></a></div>

 

b.html
<div class="swiper-slide"><a href="a.html"><span class="text">딸기</span></a></div>
<div class="swiper-slide on"><a href="b.html"><span class="text">수박</span></a></div>

a.html b.html 처럼 했는데 안 되는 것 같아요 도와주세요

 



<style>


.snbSwiper { padding: 0 3px;box-sizing: border-box;background: powderblue; }
.swiper-slide { width: auto !important; }
.swiper-slide a { display: block; text-align: center; }
.swiper-slide .text { margin: 0 5px; padding: 16px 5px 8px 5px; box-sizing: border-box; position: relative; display: inline-block; height: 47px; white-space: nowrap; font-size: 1rem; line-height: 1em; color: #333; }
.on .text { color: #1b64bc; font-weight: bold; }
.on .text:after { content: ''; display: block; position: absolute; bottom: 0; left: 0; width: 100%; height: 2px; background: #1b64bc; }


</style>


<script>


var swiper = new Swiper('.snbSwiper', {
            slidesPerView: 'auto',
            preventClicks: true,
            preventClicksPropagation: false,
            observer: true,
            observeParents: true
        });
        var $snbSwiperItem = $('.snbSwiper .swiper-wrapper .swiper-slide a');
        $snbSwiperItem.click(function(){
            var target = $(this).parent();
            $snbSwiperItem.parent().removeClass('on')
            target.addClass('on');
            muCenter(target);
        })

        function muCenter(target){
            var snbwrap = $('.snbSwiper .swiper-wrapper');
            var targetPos = target.position();
            var box = $('.snbSwiper');
            var boxHarf = box.width()/2;
            var pos;
            var listWidth=0;
            
            snbwrap.find('.swiper-slide').each(function(){ listWidth += $(this).outerWidth(); })
            
            var selectTargetPos = targetPos.left + target.outerWidth()/2;
            if (selectTargetPos <= boxHarf) { // left
                pos = 0;
            }else if ((listWidth - selectTargetPos) <= boxHarf) { //right
                pos = listWidth-box.width();
            }else {
                pos = selectTargetPos - boxHarf;
            }
            
            setTimeout(function(){snbwrap.css({
                "transform": "translate3d("+ (pos*-1) +"px, 0, 0)",
                "transition-duration": "500ms"
            })}, 200);
        }


</script>


<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/Swiper/3.3.1/css/swiper.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Swiper/3.3.1/js/swiper.min.js"></script>

<div class="swiper-container snbSwiper" style="max-width:420px">
    <div class="swiper-wrapper">
        <div class="swiper-slide"><a href="#"><span class="text">포도</span></a></div>
        <div class="swiper-slide"><a href="#"><span class="text">블루베리</span></a></div>
        <div class="swiper-slide on"><a href="a.html"><span class="text">딸기</span></a></div>
        <div class="swiper-slide"><a href="#"><span class="text">자두수박</span></a></div>
        <div class="swiper-slide"><a href="#"><span class="text">바나나</span></a></div>
        <div class="swiper-slide"><a href="#"><span class="text">망고스틴레드</span></a></div>
        <div class="swiper-slide"><a href="#"><span class="text">사과</span></a></div>
        <div class="swiper-slide"><a href="b.html"><span class="text">천도복숭아</span></a></div>
        <div class="swiper-slide"><a href="#"><span class="text">수박</span></a></div>
        <div class="swiper-slide"><a href="#"><span class="text">용과</span></a></div>
    </div>
</div>

이 질문에 댓글 쓰기 :

답변 1

<div class="swiper-slide<?php if(strpos($_SERVER['REQUEST_URI'],"a.html") !== false) echo "on"; ?>"><a href="a.html"><span class="text">딸기</span></a></div>

답변을 작성하시기 전에 로그인 해주세요.
전체 93
QA 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT