javascript - Mansory/Isotope 不适用于不同宽度的元素

标签 javascript jquery jquery-isotope

正如您在下面的代码笔中看到的那样;当可以放置其他元素时,第一个图像旁边有一个未填充的空间。

我还没有找到任何以百分比定义元素宽度的解决方案。

代码笔:https://codepen.io/anon/pen/qXEMaz

HTML:

<script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>

<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>

<script src="https://unpkg.com/imagesloaded@4/imagesloaded.pkgd.min.js"></script>
     <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">

    <script src="https://unpkg.com/isotope-layout@3/dist/isotope.pkgd.min.js"></script>
<div class ="container">
<div class=" isotope row  gutter">
                    <div class="grid-sizer col-2 mosaic-item">  
                        <img class="img-responsive" src="http://via.placeholder.com/150x350"></img>   
                    </div>

                    <div class="col-1 mosaic-item ">
                        <img class="img-responsive" src="http://via.placeholder.com/150x350"></img>
                    </div>
                    <div class="col-2 mosaic-item ">
                        <img class="img-responsive" src="http://via.placeholder.com/350x150"></img>
                    </div>
                    <div class="col-2 mosaic-item ">
                        <img class="img-responsive" src="http://via.placeholder.com/150x350"></img>
                    </div>

                    <div class="col-2 mosaic-item ">
                        <img class="img-responsive" src="http://via.placeholder.com/350x150"></img>
                    </div>

                    <div class="col-2 mosaic-item ">
                        <img class="img-responsive" src="http://via.placeholder.com/150x350"></img>
                    </div>

        </div>
</div>

CSS:

.col-1 ,
.col-1 {
    width: 100%;
}

.col-2 ,
.col-2 {
    width: 49.99%;
}

@media only screen and (max-width: 992px) {
    .col-2 ,
    .col-2 {
        width: 50%;
    }
}

@media only screen and (max-width: 767px) {
    .col-2 ,
    .col-2 {
        width: 100%;
    }
}

.col-1 ,
.col-2{
    float: left;
}
.gutter>div{
  padding: 10px;
}

.gutter img{
  width: 100%;
}  

Javascript/jQuery:

 $(document).ready(function(){
   isotope();
 });
function isotope(){
var $portfolio = $('.isotope');
       $portfolio.imagesLoaded(function() {
           $portfolio.isotope({
               isOriginLeft: true,
               stagger: 30,
               masonry: {
                 percentPosition: true
               }
           });
           $portfolio.isotope();

       });
}

enter image description here

谢谢。

最佳答案

这就是你所追求的吗?我所做的只是在第一个列 block 之后添加另一个 2 列 block 。在全屏模式下检查代码以查看列的工作情况。

 $(document).ready(function(){
   isotope();
 });
function isotope(){
var $portfolio = $('.isotope');
       $portfolio.imagesLoaded(function() {
           $portfolio.isotope({
               isOriginLeft: true,
               stagger: 30,
               masonry: {
                 percentPosition: true
               }
           });
           $portfolio.isotope();

       });
}
     
.col-1 ,
.col-1 {
    width: 100%;
}

.col-2 ,
.col-2 {
    width: 49.99%;
}

@media only screen and (max-width: 992px) {
    .col-2 ,
    .col-2 {
        width: 50%;
    }
}

@media only screen and (max-width: 767px) {
    .col-2 ,
    .col-2 {
        width: 100%;
    }
}

.col-1 ,
.col-2{
    float: left;
}
.gutter>div{
  padding: 10px;
}

.gutter img{
  width: 100%;
}
         <script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>

<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
  <script src="https://unpkg.com/imagesloaded@4/imagesloaded.pkgd.min.js"></script>
	 <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">

    <script src="https://unpkg.com/isotope-layout@3/dist/isotope.pkgd.min.js"></script>
<div class ="container">
<div class=" isotope row  gutter">
                    <div class="grid-sizer col-2 mosaic-item">  
                        <img class="img-responsive" src="http://via.placeholder.com/150x350"></img>
                      
                    </div>
                   <div class="grid-sizer col-2 mosaic-item">  
                        <img class="img-responsive" src="http://via.placeholder.com/150x350"></img>
                      
                    </div>

                    <div class="col-1 mosaic-item ">
                        <img class="img-responsive" src="http://via.placeholder.com/150x350"></img>
                    </div>
                    <div class="col-2 mosaic-item ">
                        <img class="img-responsive" src="http://via.placeholder.com/350x150"></img>
                    </div>
 <div class="col-2 mosaic-item ">
                        <img class="img-responsive" src="http://via.placeholder.com/150x350"></img>
                    </div>
                  
                    <div class="col-2 mosaic-item ">
                        <img class="img-responsive" src="http://via.placeholder.com/350x150"></img>
                    </div>

                    <div class="col-2 mosaic-item ">
                        <img class="img-responsive" src="http://via.placeholder.com/150x350"></img>
                    </div>

        </div>
</div>

关于javascript - Mansory/Isotope 不适用于不同宽度的元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45315222/

相关文章:

服务器端用于扩展 Javascript 核心的 Javascript 框架?

javascript - 使用 jquery/isotope 类调用/链接 wordpress 类别

reactjs - React 组件的生命周期、状态和 redux

javascript - 如何在express js中包含静态文件

javascript - Angular $resource : Unknown Provider error, 加载依赖和 Angular 元素

javascript - 当用户滚动 jquery 时更改图像 src 值

javascript - 添加 PlusMinus 到 Accordion 菜单

javascript - 如何在 chrome 中禁用或隐藏弹出退出全屏(F11)?

twitter-bootstrap-3 - 同位素和 Bootstrap3 : Content divs disappear on sorting

javascript - SystemJS 和 CommonJS 有什么区别