简体   繁体   English

链接弹出页面?

[英]Link popping up on page?

<li><a href="#"><img src="img/example.jpg"></a></li>

So the above code is an image link. 所以上面的代码是一个图像链接。 I'm trying to get it so when a user clicks on this image, instead of it leading them to another page for the content. 我正在尝试获取它,以便当用户单击此图像时,而不是将其引导到内容的另一个页面。 It will bring up a box with the content in keeping everything on the same page? 它将弹出一个带有内容的框,以使所有内容都在同一页面上吗? anyone know how you can do this? 有人知道你该怎么做吗?

Thanks 谢谢

You could create a div that has an initial css value of visibility:hidden, then use javascript or jquery to change the value to 'visible' on a click event. 您可以创建一个具有初始CSS值的“ dividibility:hidden”的div,然后在单击事件中使用javascript或jquery将其值更改为“ visible”。

$('#yourpicturelink').on('click', function(){
  $('#hiddendiv').css('visibility', 'visible');
}

that could be expanded into more of a toggle function, but it should get you on the right path 可以扩展为更多的切换功能,但它应该使您走上正确的道路

听起来你想做这样的事情

 <li><a href="http:/blahblah.com" target="_blank" onclick="window.open(this.href,'targetWindow','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=320,height=568');return false;"><img src="img/example.jpg"></a></li>

Something like this is what you want. 这样的东西就是您想要的。 This is very basic, and doesn't have logic for closing the box or styling for the box, but hopefully you get the idea. 这是非常基本的操作,没有关闭框或框的样式的逻辑,但希望您能理解。

Basically, you have a div with the full size image you want to show that is hidden by default using css. 基本上,您有一个要显示完整尺寸图像的div,默认情况下会使用css将其隐藏。 Then, in the visible document, you have an image that shows the box using jQuery when it is clicked. 然后,在可见的文档中,您有一个图像,该图像显示了单击jQuery时使用的框。

 $(function() { $(".clickable").click(function() { $("#box").show(); }); }); 
 img.clickable { cursor: pointer; width: 10%; height:10%; } div#box { position: absolute; display: none; top: 0; left: 0; } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <img class="clickable" src="http://i.imgur.com/LULHwuJ.jpg" /> <div id="box"> <img src="http://i.imgur.com/LULHwuJ.jpg" /> </div> 

Or, as an alternative, you can simply learn how to use libraries already coded up for you to accomplish this. 或者,作为替代方案,您可以简单地学习如何使用已经为您编码的库来完成此任务。 Look at the comment by @Nillervision for some examples. 请查看@Nillervision的评论以获取一些示例。

Misread, you could do something like this as well. 误读,您也可以执行类似的操作。

Hide the Content you want to display using some css. 使用某些CSS隐藏要显示的内容。

On click add a class to slide the hidden content into view. 单击时,添加一个类以将隐藏的内容滑入视图。

here's a JS fiddle 这是一个JS小提琴

css CSS

.contentBox {
display:block;
position:absolute;
top:0;
left:0;
width:100%;
height:100%;
color:#fff;
background: rgba(0,0,0, 0.7);
-moz-transform:translateX(-100%) translateY(0px);
-webkit-transform:translateX(-100%) translateY(0px);
-o-transform:translateX(-100%) translateY(0px);
-ms-transform:translateX(-100%) translateY(0px);
transform:translateX(-100%) translateY(0px);
-webkit-transition:200ms ease;
-moz-transition:200ms ease;
-ms-transition:200ms ease;
-o-transition:200ms ease;
 transition:200ms ease;
}

.slideLeft {
 -moz-transform:translateX(0px) translateY(0px);
-webkit-transform:translateX(0px) translateY(0px)!important;
-o-transform:translateX(0px) translateY(0px);
-ms-transform:translateX(0px) translateY(0px);
transform:translateX(0px) translateY(0px)!important;
}

markup 标记

<img class="clickthis" src="http://i.imgur.com/LULHwuJ.jpg" />

<div class="contentBox">
   The Content
</div>

js JS

$('.clickthis').on('click', function(){
  $('.contentBox').addClass('slideLeft');
});

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

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