4

对齐它以正确显示的最佳方法是什么,如下图所示:封闭式布局

HTML 标记:

<div id="main">
  <div id="article-thumbnail-1" class="article-thumbnail">
    <div class="article-open"><img src=".../article-open.png" /></div>
    <div class="article-close"><img src=".../artcle-close.png" /></div>
  </div>
  <article id="article-1" class="article-entry">
    <header class="article-header">
      <h2>This is the article 1 text</h2>
    </header>
    <div class="article-body">
      <p>This is the article 1 body</p>
    </div>
  </article>

  <div id="article-thumbnail-2" class="article-thumbnail">
    <div class="article-open"><img src=".../article-open.png" /></div>
    <div class="article-close"><img src=".../artcle-close.png" /></div>
  </div>
  <article id="article-2" class="article-entry">
    <header class="article-header">
      <h2>This is the article 2 text</h2>
    </header>
    <div class="article-body">
      <p>This is the article 2 body</p>
    </div>
  </article>

  <div id="article-thumbnail-3" class="article-thumbnail">
    <div class="article-open"><img src=".../article-open.png" /></div>
    <div class="article-close"><img src=".../artcle-close.png" /></div>
  </div>
  <article id="article-3" class="article-entry">
    <header class="article-header">
      <h2>This is the article 3 text</h2>
    </header>
    <div class="article-body">
      <p>This is the article 3 body</p>
    </div>
  </article>

  <div id="article-thumbnail-4" class="article-thumbnail">
    <div class="article-open"><img src=".../article-open.png" /></div>
    <div class="article-close"><img src=".../artcle-close.png" /></div>
  </div>
  <article id="article-4" class="article-entry">
    <header class="article-header">
      <h2>This is the article 4 text</h2>
    </header>
    <div class="article-body">
      <p>This is the article 4 body</p>
    </div>
  </article>

  <div id="article-thumbnail-5" class="article-thumbnail">
    <div class="article-open"><img src=".../article-open.png" /></div>
    <div class="article-close"><img src=".../artcle-close.png" /></div>
  </div>
  <article id="article-5" class="article-entry">
    <header class="article-header">
      <h2>This is the article 5 text</h2>
    </header>
    <div class="article-body">
      <p>This is the article 5 body</p>
    </div>
  </article>

  <div id="article-thumbnail-6" class="article-thumbnail">
    <div class="article-open"><img src=".../article-open.png" /></div>
    <div class="article-close"><img src=".../artcle-close.png" /></div>
  </div>
  <article id="article-6" class="article-entry">
    <header class="article-header">
      <h2>This is the article 6 text</h2>
    </header>
    <div class="article-body">
      <p>This is the article 6 body</p>
    </div>
  </article>
</div>

所以基本上如果你点击一个img缩略图文章应该出现在它下面,就像这张图片一样:这张照片

当文章被打开并显示在其下方时,我遇到了保持缩略图布局的问题。

基本上,当您单击缩略图时,文章应出现在单击的缩略图所在的缩略图行下方。

请注意,我正在为 WordPress 主题执行此操作。

JSFiddle:http: //jsfiddle.net/PkZrZ/

4

2 回答 2

1

这是最简单的解决方案。这取决于缩略图的数据属性。因此,如果将数据属性添加到缩略图标签是不可接受的,请告诉我,我会尝试做其他事情。 http://jsfiddle.net/d3D9p/

我改变了元素的顺序。三篇文章之后是三个缩略图。(第四至第六相同)

<div id="main">
<div class="article-thumbnail" data-num="1">
    <div class="article-open"><img src="" /></div>
    <div class="article-close"><img src="" /></div>
</div>


<div class="article-thumbnail" data-num="2">
    <div class="article-open"><img src="" /></div>
    <div class="article-close"><img src="" /></div>
</div>
<div class="article-thumbnail" data-num="3">
    <div class="article-open"><img src="" /></div>
    <div class="article-close"><img src="" /></div>
</div>
<article id="article-1" class="article-entry">
    <header class="article-header">
        <h2>This is the article 1 text</h2>     
    </header>
    <div class="article-body">
        <p>This is the article 1 body</p>       
    </div>
</article>
<article id="article-2" class="article-entry" >
    <header class="article-header">
        <h2>This is the article 2 text</h2>     
    </header>
    <div class="article-body">
        <p>This is the article 2 body</p>       
    </div>
</article>
<article id="article-3" class="article-entry">
    <header class="article-header">
        <h2>This is the article 3 text</h2>     
    </header>
    <div class="article-body">
        <p>This is the article 3 body</p>       
    </div>
</article>

还有新的jquery:

隐藏每篇文章,然后仅显示与所选缩略图对应的文章。

$('.article-thumbnail').click(function() {
    $('.article-entry').css({"display": "none"});
    $('#article-'+$(this).data("num")).css({"display": "block"});
});

UPD:现在无法自己测试。但是您可以尝试以下内容:首先阅读有关WP_Query的内容,如果还没有的话。您可以抓取所有帖子:

&get_posts()

然后结合简单的php循环和

next_post() 

您可以在添加缩略图之前显示您想要的确切帖子数量。希望它能以某种方式帮助你。

如果这没有帮助,您可以嵌套循环,该循环将在循环中显示文章,该循环将显示缩略图,并且在每第三次运行 tumbnail_loop 运行articles_loop 后将显示其中的三个并返回到 tumbnail_loop。

于 2013-04-11T07:59:49.617 回答
1

你有这样的标记:

<div id="article-thumbnail-1" class="article-thumbnail">
        <div class="article-open"><img src=".../article-open.png" /></div>
        <div class="article-close"><img src=".../artcle-close.png" /></div>
    </div>
    <article id="article-1" class="article-entry">
        <header class="article-header">
            <h2>This is the article 1 text</h2>     
        </header>
        <div class="article-body">
            <p>This is the article 1 body</p>       
        </div>
    </article>

因此,您已将任何缩略图的内容(即article直接与块相邻)放置。这就是为什么当您单击给定块即 div 时。article-thumbnail,相关的article元素会在那里呈现它自己,即与其相邻。因此流程,即您的布局发生变化。

你需要改变你的标记。

做这个。

将所有缩略图分开,将它们的文章对应分开。

就像是

|<Upper Thumbnails Section>|
^^^^^^^^^^^^^^^^^^^^^^^^^^^
|<upper article container>| //invisible by default

|<Lower Thumbnails Section>|
^^^^^^^^^^^^^^^^^^^^^^^^^^^
|<lower article container>| //invisible by default

看到这个工作小提琴

IE

<div class="article-thumbnail" data-target="article-1" >
     ..
     ..
</div>
<div class="article-thumbnail" data-target="article-2" >
     ..
     ..
</div>
<div class="article-thumbnail" data-target="article-3" >
     ..
     ..
</div>

<div class="container">
   <article id="article-1" class="article-entry">
   </article>
   <article id="article-2" class="article-entry">
   </article>
   <article id="article-3" class="article-entry">
   </article>
 </div>

并使用如下脚本切换您的内容:

var prev;
$('.article-thumbnail').click(function() {
    var _target= $(this).data("target");
    var _current=$('#'+_target);
    var hideCss={'height':'0px'};
    var showCss={'height':'200px'};

    if(prev){
        prev.hide();
        prev.parent().stop().animate(hideCss,1000);
    }
    _current.show();
    _current.parent().stop().animate(showCss,1000);

    prev= _current
});
于 2013-04-11T08:26:26.450 回答