简体   繁体   English

如何从框中的链接而不是 HTML5 中的新选项卡或新窗口打开新页面?

[英]how to open a new page from link in a box instead of new tab or new window in HTML5?

I was searching for a tutorial or code that will help to show data with image in a box "instead of new window" or "instead of same window" .我正在寻找有助于在“而不是新窗口”或“而不是同一个窗口”的框中显示带有图像的数据的教程或代码。

  1. Hyper link will open the page in a box or frame but parent html will be remain in background, when the box will be closed the parent window of HTML will be shown again instead of reloading.超链接将在框或框架中打开页面,但父 html 将保留在后台,当框关闭时,HTML 的父窗口将再次显示而不是重新加载。

I do not know what is called this process and I have searched for tutorials but failed to find as I wanted.我不知道这个过程叫什么,我已经搜索了教程,但没有找到我想要的。

I want to do something like this link http://photoswipe.com/ shows when image is clicked.当单击图像时,我想做类似此链接http://photoswipe.com/显示的操作。 I am new and help please.我是新来的,请帮忙。 Thank you.谢谢你。

It's called a modal or overlay.它被称为模态或叠加。 When used for images it's often called a lightbox .当用于图像时,它通常被称为灯箱

Here is a rough demo using jQuery.这是一个使用 jQuery 的粗略演示。 Basically you have an element that contains thumbnails of your images.基本上,您有一个包含图像缩略图的元素。 Those elements have a data- attribute that points to a larger sized image.这些元素具有指向更大尺寸图像的data-属性。 When the user clicks a thumbnail you use JavaScript to read the value of the data- attribute, create an image element and insert it into the modal/overlay.当用户单击缩略图时,您使用 JavaScript 读取data-属性的值,创建一个图像元素并将其插入到模态/覆盖中。 The modal/overlay will be a positioned element using fixed or absolute positioning.模态/覆盖将是使用fixedabsolute定位的定位元素。 When the user closes the modal the container element for the image is emptied so you do not have two images in the modal the next time an image is clicked and the modal/overlay is opened.当用户关闭模态时,图像的容器元素被清空,因此下次单击图像并打开模态/叠加层时,模态中不会有两个图像。

 var $overlay = $( '.photo-box-overlay' ); var $overlayIMG = $( '.photo-box-img' ); $( '.photo-box' ).on( 'click', 'img', function ( e ) { var $target = $( e.target ); var $img = $( '<img/>', { src: $target.attr( 'data-large' ) } ); $overlayIMG.append( $img ); $overlay.css( 'display', 'block' ); } ); $( '.photo-box-close' ).on( 'click', function ( e ) { $overlay.css( 'display', 'none' ); $overlayIMG.empty(); } );
 .photo-box-overlay { display: none; position: fixed; top: 0; right: 0; bottom: 0; left: 0; height: 100%; padding: 2rem; background-color: rgba( 0, 0, 0, 0.8 ); } .photo-box-close { position: absolute; top: 10px; right: 10px; height: 30px; width: 30px; font-size: 30px; line-height: 30px; color: #f1f1f1; cursor: pointer; } .photo-box-overlay img { max-width: 100%; display: block; height: auto; position: absolute; left: 50%; top: 50%; transform: translate( -50%, -50% ); }
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="photo-box"> <img src="https://unsplash.it/300/150?image=85" data-large="https://unsplash.it/900/450?image=85"> <img src="https://unsplash.it/300/150?image=100" data-large="https://unsplash.it/900/450?image=100"> <img src="https://unsplash.it/300/150?image=125" data-large="https://unsplash.it/900/450?image=125"> </div> <div class="photo-box-overlay"> <div class="photo-box-close">&times;</div> <div class="photo-box-img"></div> </div>

This is a quick demo aimed at illustrating what is required to create the functionality you're looking for.这是一个快速演示,旨在说明创建您正在寻找的功能所需的条件。 It most likely is not production ready and can/should be improved upon.它很可能没有做好生产准备,可以/应该改进。

I'm changing my answer sorry.对不起,我正在改变我的答案。 As you want to dynamicly show the picture, you are goin to create data- attr to element that includes links and then do jquery do put them into the box as you suggesting.当您想动态显示图片时,您将创建包含链接的元素的数据属性,然后按照您的建议执行 jquery 将它们放入框中。 Here is the link of DEMO这是DEMO的链接

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

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