简体   繁体   English

基于屏幕宽度的Javascript函数

[英]Javascript function based on screen width

Hey I'm trying to decrease the column width of masonry when you get to screen size with: max-width: 450px; 嘿,当您使用以下尺寸调整屏幕尺寸时,我正在尝试减小砖石结构的列宽:max-width:450px;

var $container = $('#container');
$container.imagesLoaded(function(){
  $container.masonry({
    itemSelector : '.box',
    columnWidth: 220,
    isAnimated: !Modernizr.csstransitions,
    isFitWidth: true
  });
});

Here is my Javascript code. 这是我的Javascript代码。 What do I add to make it decrease the column width at that screen size?? 我要添加什么以使其在该屏幕尺寸下减小列宽?

Or how do I target screen size with an IF statement...if screen size is less than 450 then 'xyz' else the function above... 或者我该如何使用IF语句指定屏幕尺寸...如果屏幕尺寸小于450,则为“ xyz”,否则上述功能...

A shorthand IF statement should do the trick. 速记IF语句应该可以解决问题。 Essentially, you are saying if document width is less than 450 than columnWidth is set to 220, else columnWidth is set to 110. 本质上,您说的是如果文档宽度小于450且columnWidth设置为220,否则columnWidth设置为110。

var $container = $('#container');
      $container.imagesLoaded(function(){
      $container.masonry({
                          itemSelector : '.box',
                          columnWidth: ( $(document).width() < 450 ? 220 : 110 ),
                          isAnimated: !Modernizr.csstransitions,
                          isFitWidth: true
                        });
       });
if(window.screen.availWidth < 450)
{
    // alternative configuration here
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM