mic*_*urk 1 html javascript css jquery
我有以下演示:http : //jsfiddle.net/NCj2u/
目前它适用于所有平台,但我更喜欢显示按钮和隐藏内容仅适用于平板电脑和移动设备。桌面会自动显示内容并隐藏按钮。
有人可以解释我如何做到这一点吗?我会使用媒体查询还是在我的 Javascript 中执行此操作?
我的jQuery:
$(document).ready(function() {
$('.nav-toggle').click(function(){
//get collapse content selector
var collapse_content_selector = $(this).attr('href');
//make the collapse content to be shown or hide
var toggle_switch = $(this);
$(collapse_content_selector).toggle(function(){
if($(this).css('display')=='none'){
//change the button label to be 'Show'
toggle_switch.html('Show');
}else{
//change the button label to be 'Hide'
toggle_switch.html('Hide');
}
});
});
});
Run Code Online (Sandbox Code Playgroud)
谢谢你。
嗯,您可以尝试的选项很少。我个人建议不要进行浏览器检测,除非您只想专门针对允许您实现的浏览器。对于您的要求,为什么不尝试媒体查询?
.nav-toggle{
display : none; // display none for everyone
}
/* Landscape phone to portrait tablet show the button */
@media (max-width: 767px) {
.nav-toggle{
display : block; // or inline-block or inline : which ever is appropriate for you.
}
Run Code Online (Sandbox Code Playgroud)
}