简体   繁体   English

用多个链接覆盖多个外部页面或div

[英]Overlaying multiple external pages or divs with multiple links

I have a group of images with captions (from http://www.hongkiat.com/blog/css3-image-captions/ ) and would like to be able to click on them and have them overlay either a hidden div or load an external page as an overlay (I'm not fussed on either as long as it works!). 我有一组带有标题的图像(来自http://www.hongkiat.com/blog/css3-image-captions/ ),希望能够单击它们,并使其覆盖隐藏的div或加载外部网页作为叠加层(只要工作正常,我也不为之烦恼!)。 I'd also like each image to link to a different page/div. 我还希望每个图像都链接到不同的页面/ div。 I've tried lots of things without success so much help would be appreciated. 我尝试了很多没有成功的事情,所以将不胜感激。 Here's my code for the images (and yes one appears twice for testing purposes): 这是我的图像代码(是的,出于测试目的,两次出现):

<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>

per your 2nd question in the comments "I can't even get a simple a link to bring up the popup. I'm kinda new to JQuery so how should I link to JQuery, where should I put the script and how do I implement the img and attr things you're on about?", here is a screenshot that shows everything you need. 请在注释中回答您的第二个问题:“我什至无法获得一个简单的链接来弹出弹出窗口。我对JQuery还是很陌生,所以我应该如何链接到JQuery,应该在哪里放置脚本以及如何实现您正在处理的img和attr内容?”,这是一个截图,显示了您所需的一切。

在此处输入图片说明

That is easy with CSS only. 仅使用CSS很容易。

Take a llok at this fiddle : http://jsfiddle.net/VgLVq/ 看看这个小提琴吧: http : //jsfiddle.net/VgLVq/

To make the div clickable, just wrap it in a <a> tag with the URL you want. 要使div可点击,只需将其包装在具有所需URL的<a>标记中。

Then make the .box in position: relative and every of his children in position: absolute . 然后将.boxposition: relative并将每个孩子放置在position: absolute I used the selector .box>* . 我使用了选择器.box>*

Then make the .caption in display:none and add this CSS to detecte the hover : 然后将.captiondisplay:none并添加以下CSS来检测鼠标悬停:

a:hover .caption{
    display:block;
}

I built a fiddle for you that does what you're trying to do. 我为您制作了一个小提琴,它可以做您想做的事情。 Without knowing which unique values of the images you intend to use to load the related page, i provided some sample code: 在不知道您打算用于加载相关页面的图像的哪些唯一值的情况下,我提供了一些示例代码:

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

javascript: 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: 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 CSS

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

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

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