2016-04-04 28 views
0

我要開兩個側面板(panel_Left和panel_Right)只有如果(window.innerWidth> 800)但始終是打開的面板只有一個開放左右側面板,如果(window.innerWidth> 800)

window.onresize = function (event) { 
    if (window.innerWidth > 800) { 
     window.setTimeout(openPanel, 1); 
    } 
    if (window.innerWidth < 800) { 
     window.setTimeout(closePanel, 1); 
    } 
}; 


function closePanel() { 
    $("Panel_left").panel("close"); 
    $("#Panel_right").panel("close"); 
} 

function openPanel() { 
    $("#Panel_left").panel("open"); 
    $("#Panel_right").panel("open"); 
} 


$("#Panel_left").on("panelcreate", function (event, ui) { 
    if (window.innerWidth > 800) { 
     openPanel(); 
    } 
    if (window.innerWidth < 800) { 
     closePanel(); 
    } 
}); 

知道 我用(jquery.mobile-1.4.5.min.js)

+0

可以在此添加HTML? –

+0

文本重新排序和格式改進 – iberbeu

回答

0

window.onresize = function(event) { 
 
    if (window.innerWidth > 800) { 
 
     console.log("hi"); 
 
     document.getElementById("left").style.display = "block"; 
 
     document.getElementById("right").style.display = "block"; 
 
     // window.setTimeout(openPanel, 1); 
 
    } else { 
 
     document.getElementById("right").style.display = "none"; 
 
     document.getElementById("left").style.display = "none"; 
 
     console.log("hello"); 
 
     // window.setTimeout(closePanel, 1); 
 
    } 
 
}; 
 
window.onload = function() { 
 
    if (window.innerWidth > 800) { 
 
     console.log("hi"); 
 
     document.getElementById("left").style.display = "block"; 
 
     document.getElementById("right").style.display = "block"; 
 
     // window.setTimeout(openPanel, 1); 
 
    } else { 
 
     document.getElementById("right").style.display = "none"; 
 
     document.getElementById("left").style.display = "none"; 
 
     console.log("hello"); 
 
     // window.setTimeout(closePanel, 1); 
 
    } 
 
}
#left, 
 
#right { 
 
    width: 10%; 
 
    display: inline-block; 
 
} 
 

 
#left { 
 
    float: left; 
 
} 
 

 
#right { 
 
    float: right; 
 
}
<!DOCTYPE html> 
 
<html> 
 

 
<head> 
 
    <title>stack</title> 
 
    
 
    <link rel="stylesheet" type="text/css" href="style.css"> 
 
</head> 
 

 
<body> 
 
    <div id="left">hi</div> 
 
    <div id="right">hello</div> 
 
    <script type="text/javascript" src="controller.js"></script> 
 
</body> 
 

 
</html>

你需要這個?@mo雙

+0

**是**真的 這是我想要做**所以,感謝您的幫助。** –

+0

歡迎您:)。你可以點擊我的答案旁邊的向上箭頭按鈕? – Batman

+0

不客氣... 好的 –