我想在一组功能上使用大于768px的屏幕尺寸,另一组使用小于此尺寸的一切。我需要.resize()
,这样我就可以知道用户何时在横向和纵向视图之间转动他们的平板电脑或手机。
.resize()
事件内部的代码工作正常,如果我刷新页面,但它就好像事件没有被触发。有什么想法吗?
<script>
jQuery(document).ready(function($){
function mobileFilterMenu(){
var screenTest = $(window).width();
if (screenTest >= 769){
$(window).on('scroll', function() {
var scrollTop = $(window).scrollTop(),
elementOffset = $('.inventory-search > .col-md-9').offset().top,
distance = (elementOffset - scrollTop);
if(distance <= 0){
$('.filter-form').css('top', Math.abs(distance));
}else{
$('.filter-form').css('top', 0);
}
});
}else{
var vHeight = $(window).height() - $('#switch').height() - $('#primary-menu-toggle').height();
$('.filter-form').css('height', vHeight + 'px');
vTextHeight = vHeight - 20;
$('.wpv-filter-form').css('height', vTextHeight + 'px');
objNegHeight = (vHeight * -1) + 50;
$('.filter-form').css('top', objNegHeight + 'px');
var i;
$('#switch').click(function(){
if (i === 0){
$('.filter-form').css('top', objNegHeight + 'px');
i++;
}else{
$('.filter-form').css('top', '50px');
i = 0;
}
});
}
}
mobileFilterMenu();
$(window).resize(mobileFilterMenu());
});
</script>
你做错了! [这是什么响应式设计'媒体查询'照顾没有错误的JavaScript。](https://developers.google.com/web/fundamentals/layouts/rwd-fundamentals/use-media-queries?hl=en#apply -media查询基础上,视大小)! –
'mobileFilterMenu()'调用函数。你想要通过它。 '$(窗口)。在( '调整',mobileFilterMenu);' –