简体   繁体   English

如何在单击的项目下方显示详细的div /弹出框

[英]How to display a detail div / popup box just below the item clicked

I am trying to built a layout using in html like following two images. 我试图建立一个使用html的布局,例如以下两个图像。

The detail div /popup for each item should open right below the item which is clicked.. 每个项目的详细信息div / popup应该在被单击的项目的正下方打开。

In case of desktop 如果是台式机

在此处输入图片说明

And in case of mobile/tablet 如果是手机/平板电脑 在此处输入图片说明

Right now I have no Idea how to proceed further .. 现在我不知道该如何进一步..

Please point me in the right direction or give me a link to some demo website where this kind of functionalit is happening Please help me out on this .. 请为我指出正确的方向,或者给我链接到正在发生这种功能的一些演示网站,请为此提供帮助。

Do you want Do something like "google images search" section? 是否要执行“ Google图片搜索”部分?

If You want to do something like this, you can simply create your "div" with information and add some class to hidden it, when the user click on the main div you attache a "visible" class with javascript. 如果您想做这样的事情,您可以简单地用信息创建“ div”并添加一些隐藏的类,当用户单击主div时,您将使用javascript附加“可见”类。 This is all. 这就是全部。

If you need take your information with some ajax call, the logic is the same. 如果您需要通过一些ajax调用获取信息,则逻辑是相同的。 Supose, that you have this html for each image: 假设,每个图片都有这个html:

<a href="/link/for/no/js" data-id="idDivWithInformation" class="link-information">...</a>
//hidden div    ..... 
<div id="idWidthInformation class="hidden">....</div>

Then, with jQuery you can do something like this; 然后,使用jQuery,您可以执行以下操作;

$('#contentImages').on('click','a.link-information',function){
     var $this = $( this );
      // show the hidden div
     $($this.data('id')).removeClass('hidden').fadeIn()

})

The style and design, is define with css, for a "modal" view or for some view like google images search. 样式和设计是使用CSS定义的,用于“模式”视图或某些视图(例如Google图片搜索)。 The animation in showing your modal, can also be create with css and changing de "fadeIn" code for "addClass" for example, if you want to use some css library like animate.css 例如,如果要使用诸如animate.css之类的css库,也可以使用css和为“ addClass”更改de“ fadeIn”代码来创建模态动画。

You can use bootstrap modals, try to visit this links to see the documentation. 您可以使用引导程序模态,尝试访问此链接以查看文档。 http://www.w3schools.com/bootstrap/bootstrap_modal.asp http://www.w3schools.com/bootstrap/bootstrap_modal.asp

in there explained about it, you can use data-toggle="modal" and data-target="#your_model_id" bottstrap attribute. 在其中进行了说明,您可以使用data-toggle="modal"data-target="#your_model_id" bottstrap属性。

hope that can answer your questions :D 希望可以回答您的问题:D

There are couple of ways... one of them in clean javascript is to have one container that you load with data or many containers (one for each element). 有几种方法...干净的javascript中的一种是让一个容器加载数据或多个容器(每个元素一个)。

  1. create container element for information 创建容器元素以获取信息

    var someContainer = "<div id='msgContainer'>someMessage</div>" ; var someContainer = "<div id='msgContainer'>someMessage</div>" ;

  2. define onclick='elementClicked(event)' action on element or in some other way 在元素上定义onclick ='elementClicked(event)'动作或其他方式

    function elementClicked(event) { //get mouse coords where clicked //mouse X event.clientX; //mouse Y event.clientY; //get element you use as a container for messages //var msgContainer = document.getElementById("msgContainer"); //this will set //load container with any info if you're using one container element for all 'menus' //msgContainer.style.position = "absolute"; //msgContainer.style.top = event.clientY"; //msgContainer.style.left = event.clientX; }

alternatively as I said you could have one hidden container (div or any other element) per element and then you just need to show and hide them. 或者,就像我说的那样,每个元素可以有一个隐藏的容器(div或任何其他元素),然后只需要显示和隐藏它们即可。

All of this should be easier using jquery. 使用jQuery,所有这些都应该更容易。

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

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