Javascript 如何在调整窗口大小时隐藏每个文档?

Javascript 如何在调整窗口大小时隐藏每个文档?,javascript,jquery,window-resize,Javascript,Jquery,Window Resize,当窗口调整到某些像素时,我试图隐藏文档的每个元素 这就是我试图编写的脚本- 当窗口的大小调整到某些像素时,每个文档都会隐藏起来,否则会显示 我试着实现这个脚本- <script type="text/javascript"> $(function () { var eachdoc=$(document).each(); var docsize = eachdoc.width(); $(wi

当窗口调整到某些像素时,我试图隐藏文档的每个元素

这就是我试图编写的脚本-

当窗口的大小调整到某些像素时,每个文档都会隐藏起来,否则会显示

我试着实现这个脚本-

    <script type="text/javascript">
        $(function () {
            var eachdoc=$(document).each();
            var docsize = eachdoc.width();
            $(window).resize(function () {
                $(document).each(function () {
                    if (docsize > $(window).width()-400) {
                        $(this).hide();
                    }
                    else {
                        $(this).show();
                    }
                });
            });
        });
    </script>

$(函数(){
var eachdoc=$(document).each();
var docsize=eachdoc.width();
$(窗口)。调整大小(函数(){
$(文档)。每个(函数(){
如果(docsize>$(窗口).width()-400){
$(this.hide();
}
否则{
$(this.show();
}
});
});
});
这个脚本不起作用,我如何改进这个脚本来隐藏窗口大小调整中的每个元素?
请建议

基本实现可以是

$(function () {
    var els=$('.mytable, .mypara');//list of elements
    var docsize = eachdoc.width();
    $(window).resize(function () {
        var cuttoff = $(window).width() - 400;
        els.each(function (idx, el) {
            var $this = $(this);
            if ($this.width() > cuttoff) {
                $this.hide();
            } else {
                $this.show();
            }
        });
    });
});

我不确定这是不是最好的解决方案,甚至不是一个好的解决方案,所以有人根据需要纠正我。。但是我认为这种方式会对你的cpu更容易一些

$.fn.filterNumberRange = function(item, low, high){
  return this.filter(function(){
      var value = +$(this).attr(item);
      return value >= low && value <= high;
  });
};

var documents = $('document-selector');

$(documents).each(function(){
  $(this).attr('data-width', $(this).width());
});

$(window).resize(function(){
  var current-width = parseInt($(window).width()) - 400;

  $(documents).filterNumberRange( 'data-width', 0, current-width ).show;
  $(documents).filterNumberRange( 'data-width', current-width + 1, 9999 ).hide;
});
$.fn.filterNumber=函数(项目、低、高){
返回此.filter(函数(){
var值=+$(此).attr(项目);

返回值>=低值(&&value)页面中是否有多个文档?是否使用css$('body')中的CPUlook up媒体查询的“窗口中的每个调整大小=硬”隐藏某些元素/文档。隐藏();---更多的上下文可能会有帮助,你为什么要这样做?@Manoz,几乎一切都是可能的,但我们不知道你想做什么。没有这些信息,我们无法给你最好的答案。。。