Jquery 如何在方向更改时重新加载。(Bxslider)

Jquery 如何在方向更改时重新加载。(Bxslider),jquery,orientation,bxslider,Jquery,Orientation,Bxslider,我正在使用Bxslider,在纵向上显示1张幻灯片,在横向上显示2张幻灯片 问题是当方向改变(纵向/横向)时,我需要重新加载 有人知道怎么做吗 if (window.matchMedia("(orientation: portrait)").matches) { $(document).ready(function(){ // Special Slider $('.wrap_mSpecial_list .bxslider').bxSlider({

我正在使用Bxslider,在纵向上显示1张幻灯片,在横向上显示2张幻灯片

问题是当方向改变(纵向/横向)时,我需要重新加载

有人知道怎么做吗

if (window.matchMedia("(orientation: portrait)").matches) {

    $(document).ready(function(){
    // Special  Slider   
        $('.wrap_mSpecial_list .bxslider').bxSlider({  
            minSlides: 1,
            maxSlides: 1, 
            auto:true,
            infiniteLoop: true,
            controls:false 
        }); 
    });
}

if (window.matchMedia("(orientation: landscape)").matches) {

    $(document).ready(function(){

        // Special  Slider   
        $('.wrap_mSpecial_list .bxslider').bxSlider({ 
            minSlides: 2,
            maxSlides: 2, 
            slideWidth: 5000,  
            auto:true,
            controls:false,
            infiniteLoop: true 
        });
    });
} 

使用jQuery Mobile,您可以使用此活页夹收听方向更改:

$(window).on("orientationchange",function(){
   alert("The orientation has changed!");
   if (window.matchMedia("(orientation: landscape)").matches) {
       //landscape slider
   }
});
对于纯js,您可以使用:

window.addEventListener('deviceorientation', function(event) {
   console.log(event.alpha + ' : ' + event.beta + ' : ' + event.gamma);
});
查看更多