창크기에 따른 제이쿼리를 다르게 적용하고싶습니다.

창크기에 따른 제이쿼리를 다르게 적용하고싶습니다.

QA

창크기에 따른 제이쿼리를 다르게 적용하고싶습니다.

본문

https://sir.kr/g5_skin/25206?sfl=wr_subject%7C%7Cwr_content&stx=okca

에서 제공받은 게시판 소스 중 일부입니다.

 


<script>
var width_size =$(window).width();
        $(window).resize(function (){
            $('#size').val( $(window).width() + " × " + $(window).height() );
  if (width_size <= 872) {
      $(window).onload(function (){
              var owl = $('.owl-carousel');
              owl.owlCarousel({
                items:2,
                loop: true,
                margin: 10,
                autoplay: true,
                autoplayTimeout: 3000,
                autoplayHoverPause: true
              });
          });
  }
  else if (width_size > 872 || width_size < 1001) {
         var owl2 = $('.owl-carousel');
              owl2.owlCarousel({
                items:3,
                loop: true,
                margin: 10,
                autoplay: true,
                autoplayTimeout: 3000,
                autoplayHoverPause: true
              });
   }
   else if(width_size >= 1001){
       alert("1000ㅂ보다 큽니다");
           var owl3 = $('.owl-carousel');
              owl3.owlCarousel({
                items:4,
                loop: true,
                margin: 10,
                autoplay: true,
                autoplayTimeout: 3000,
                autoplayHoverPause: true
              });
    }       
                 
});
    </script>

 

소스코드 목적은 화면의 가로길이가 1001보다 크면 item부분이 4,

                      873이상 1000이하면 item이 3, 

                      872이하이면 item이 2로 처리하고싶은데 제대로 먹히지 않습니다..

 

 

 

 

이 질문에 댓글 쓰기 :

답변 1

옵션으로 제어가 가능합니다. 하단과 같이 해보세요.

참고 링크:

https://owlcarousel2.github.io/OwlCarousel2/demos/responsive.html


$('.owl-carousel').owlCarousel({
loop:true,
margin:10,
responsiveClass:true,
responsive:{
  0:{
     items:1,
     nav:true
   },
  600:{
     items:3,
     nav:false
  },
  1000:{
     items:5,
     nav:true,
     loop:false
  }
}
})
답변을 작성하시기 전에 로그인 해주세요.
전체 606
QA 내용 검색

회원로그인

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