覆盖多个外部页面或具有多个链接的div

时间:2013-05-07 19:39:49

标签: javascript jquery html

我有一组带有字幕的图片(来自http://www.hongkiat.com/blog/css3-image-captions/),并希望能够点击它们并让它们覆盖隐藏的div或加载外部页面作为叠加层(我不是只要它有效,就可以融合!)。我也希望每个图像链接到不同的页面/ div。我已经尝试了许多没有成功的事情,我们将非常感谢你们。这是我的图像代码(是的,出于测试目的,它出现了两次):

<div id="mainwrapper">
  <table>
    <tr>
      <td>
        <div id="box-1" class="box">  
          <img id="image-1" src="img/agent.png"/>  
          <span class="caption full-caption">  
            <h3>Agent Demo</h3>  
            <p>Java Group Project</p>
          </span>  
        </div> 
      </td>

      <td>
        <div id="box-2" class="box">  
          <img id="image-2" src="img/wizardsbook.png"/>  
          <span class="caption full-caption">  
            <h3>The Wizard's Book</h3>  
            <p>Java Game</p>  
          </span>  
        </div> 
      </td>

      <td>
        <div id="box-3" class="box">  
            <img id="image-3" src="img/wizardsbook.png"/>  
            <span class="caption full-caption">  
              <h3>The Wizard's Book</h3>  
              <p>Java Game</p>  
            </span>  
        </div> 
      </td>
    </tr>
  </table>
</div>

3 个答案:

答案 0 :(得分:1)

根据评论中的第二个问题“我甚至无法获得一个简单的链接来显示弹出窗口。我是JQuery的新手,所以我应该如何链接到JQuery,我应该在哪里放置脚本以及如何我是否实现了你所关注的img和attr?“,这是一个截图,显示了你需要的一切。

enter image description here

答案 1 :(得分:0)

仅使用CSS很容易。

抓住这个小提琴:http://jsfiddle.net/VgLVq/

要使div可点击,只需将其包含在<a>标记中,并附上您想要的网址。

然后在.boxposition: relative中的每个孩子中制作position: absolute。我使用了选择器.box>*

然后在.caption中创建display:none并添加此CSS以检测悬停:

a:hover .caption{
    display:block;
}

答案 2 :(得分:0)

我为你做了一个小提琴,做了你想要做的事情。在不知道您打算用来加载相关页面的图像的哪些唯一值的情况下,我提供了一些示例代码:

工作小提琴在这里:
http://jsfiddle.net/acturbo/YVBpj/

的javascript:

$().ready(function() {

    $("#close").on("click", function(){
        $("#popup").hide();
    });

   // uncomment this line to attach this "showWindow" to all the images
   // then, use $(this) to access the specific image that was clicked

    //$("img").on("click", function(){
    $("#showWindow").on("click", function(){

        // when you switch to images, you can access unique attributes
        // of the clicked image using attr()
        // this will let you load unique pages for each image
        // eg. can use 1 or 2
        // var value1 = $(this).attr( "src" );
        // var value2 = $(this).attr( "id" );
        //$("#popup").load( value1 );

        $("#popup").show();
    });

});

HTML:

<div id="popup">
    <p>this is hidden until the image is clicked</p>
    <a href="#" id="close">Close Window</a>
</div>    

<a href="#" id="showWindow">Show Window - mimic an image click</p>

<div id="mainwrapper">
  <table>
    <tr>
      <td>
        <div id="box-1" class="box">  
          <img id="image-1" src="img/agent.png"/>  
          <span class="caption full-caption">  
            <h3>Agent Demo</h3>  
            <p>Java Group Project</p>
          </span>  
        </div> 
      </td>

      <td>
        <div id="box-2" class="box">  
          <img id="image-2" src="img/wizardsbook.png"/>  
          <span class="caption full-caption">  
            <h3>The Wizard's Book</h3>  
            <p>Java Game</p>  
          </span>  
        </div> 
      </td>

      <td>
        <div id="box-3" class="box">  
            <img id="image-3" src="img/wizardsbook.png"/>  
            <span class="caption full-caption">  
              <h3>The Wizard's Book</h3>  
              <p>Java Game</p>  
            </span>  
        </div> 
      </td>
    </tr>
  </table>
</div>

CSS

#popup{
    top: 10px;
    left: 10px;
    width: 300px;
    height: 100px;
    position: absolute;
    background: red;
    display: none;
}