2017-09-27 2 views
0

항목이있는 섹션이 있으며 755px 미만의 슬라이더가됩니다. 그래서 창 크기 조정에서 슬라이더가 존재하는지 확인한 다음 누군가를 창 크기를 조정하면 제대로 크기가 조정됩니다.destroySlider()가 작동하지 않는 후에 removeAttr()이 작동하지 않습니다. - bxslider

HTML

<div class="wrapper"> 
    <div class="slider"> 
      <div class="item">1</div> 
      <div class="item">2</div> 
      <div class="item">3</div> 
      <div class="item">4</div> 
      <div class="item">5</div> 
      <div class="item">6</div>  
    </div> 
</div> 

JS

var slider; 
jQuery(window).on('resize', function(){ 
    if(jQuery(window).width() < 755){ 
     // slider code goes here 
     slider = jQuery(".slider").bxSlider({ 
      mode: 'horizontal', 
     }); 
    }else{ 
     if(jQuery(".wrapper .bx-wrapper").length){ 
      slider.destroySlider(); 
      jQuery(".slider").addClass('destroyed_slider'); 

      jQuery(".slider").removeAttr('style'); 
      jQuery(".slider .item").each(function(){ 
       jQuery(this).removeAttr('style'); 
      }); 
     } 
    } 
}); 

그러나 destroySlider은() 정말 (destroySlider으로 발생하지해야하는 슬라이더와 항목에 대한 몇 가지 이상한 스타일을 참조) 모든 것을 파괴해야 후, 하지만 어쨌든 그것을 해결하기 위해 스타일 속성을 제거하지만 removeAttr()은 작동하지 않습니다.

이상한 점은 jQuery(".slider").addClass('destroyed_slider');이 작동하고 removeAttr() 만 작동하지 않는다는 것입니다. 어떤 아이디어라도 제발?

+0

가 추가겠습니까 슬라이더 요소를 포함하는 부모 요소를 비 웁니다 귀하의 ** HTML ** 코드하시기 바랍니다 –

+0

예전 너 진짜하려는거야? 화면> 750 일 때 슬라이더를 제거 하시겠습니까? 현재 크기 조정시 슬라이더를 무제한으로 다시 만들고 있습니다. – Obsidian

+0

@MehdiBouzidi - HTML 코드 – aidadev

답변

0

당신은 일을 :

slider.destroySlider(); 

당신은 '스타일'을 제거하기 전에, 당신이 그렇게 할 때 :

jQuery(".slider").removeAttr('style'); 

요소가 더 이상 그러므로 존재하지 않는이 더 스타일 속성이 없습니다.

JQuery와의 innerHTML 또는 html()을 비워

시도 destroySlider 후 시도 :

jQuery("{parent id, not .slider}").html("") 

이것은

베스트

관련 문제