所以我正在尝试将我的显示隐藏功能用于移动 View 和平板电脑 View ,但我不确定如何实现它。这是我的显示隐藏功能:
$(function() {
$('h2 + p').hide();
$('h2').click(function(e) {
var para = $(this).next('p');
para.toggle();
if (para.css('display') == 'none') {
$(this).css('background-image', 'url(images/arrow-r.png)');
} else {
$(this).css('background-image', 'url(images/arrow-down.png)');
}
})
.css('cursor', 'pointer');
});
我想将此代码用于我的标题 2,但仅限于移动 View 和平板电脑 View ,因为我有一个隐藏视频,直到您单击标题。关于如何实现它有什么想法吗?
从第一个答案开始,我现在有了这段代码,但它似乎仍然无法正常工作? ;
<script>
$(function () {
if($(window).width() < 768 ) {
$('h2 + p').hide();
$('h2').click(function(e) {
var para = $(this).next('p');
para.toggle();
if (para.css('display') == 'none') {
$(this).css('background-image', 'url(images/arrow-r.png)');
} else {
$(this).css('background-image', 'url(images/arrow-down.png)');
}
})
.css('cursor', 'pointer');
});
</script>
最佳答案
决定一个断点然后做如下的事情
$(function () {
if($(window).width() < 768 ) { // 768 represents break-point measure
// Do whatever you want here
}
});
768px
通常覆盖 Ipad(纵向)到其他小型设备。
关于jquery - 在移动 View 和平板电脑 View 中使用我的显示/隐藏 JQuery 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40551185/