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

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

QA

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

본문

<style>

html { overflow-y: scroll; font-family: sans-serif; font-size: 16px; min-width: 320px; line-height: 1.5em; color: #333; }

body{margin:0;padding:0;}

.snbSwiper { padding: 0 3px;box-sizing: border-box;background: powderblue; }

.swiper-wrapper { box-sizing: content-box; -webkit-box-pack: justify; -webkit-justify-content: space-between; justify-content: space-between; }

.swiper-slide { -webkit-transform-style: preserve-3d; -moz-transform-style: preserve-3d; -ms-transform-style: preserve-3d; transform-style: preserve-3d; width: auto; }

.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>

 

<div class="swiper-container snbSwiper">

<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"><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="#"><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>

</div>

<script>

$(function(){

var swiper = new Swiper('.snbSwiper', {

slidesPerView: 'auto',

preventClicks: true,

preventClicksPropagation: false,

observer: true,

observeParents: true

});

var $lankTitle = $('.snbSwiper .swiper-wrapper .swiper-slide a');

$lankTitle.click(function(){

var target = $(this).parent();

$lankTitle.parent().removeClass('on')

target.addClass('on');

muCenter(target);

})

 

function muCenter(target){

var snbwrap = $('.snbSwiper .swiper-wrapper');

var targetPos = target.position();

var winHarf = $('body').width()/2;

var pos;

var wrapWidth=0;

snbwrap.find('.swiper-slide').each(function(){

wrapWidth += $(this).outerWidth();

})

if ((targetPos.left + target.outerWidth()/2) <= winHarf) { // left

pos = 0;

}else if ((wrapWidth - targetPos.left - target.outerWidth()/2) <= winHarf) { //right

pos = wrapWidth-$('body').width();

}else {

pos = targetPos.left - winHarf + (target.outerWidth()/2);

}

setTimeout(function(){snbwrap.css({

"transform": "translate3d("+ (pos*-1) +"px, 0, 0)",

"transition-duration": "500ms"

})}, 200);

}

})

</script>



구글 서칭중 웹밤바님의 티스토리 블로그에서 스와이프 메뉴 클릭하면 가운데오기 소스를 발견했는데요

모바일 서브메뉴에 적용하려니 a링크의 #일때는 메뉴 구현이 정상적으로 되는데 링크를 넣으니 active가 안먹히더라구요.. 이런 경우에는 어떤 것을 봐야할까요? 주소값이 넘어가면서 리셋되는것 같은데...

이 질문에 댓글 쓰기 :

답변 2

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

회원로그인

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