简体   繁体   English

触摸设备的 JavaScript 链接预览

[英]JavaScript link preview for touch devices

I have some JavaScript on a website I'm currently making which causes selected links to show a preview when moused over which works fine, however for touch devices when the links are tapped it shows the preview then sends the user to the site, I'd like it to show just the preview on the first tap, then if they tap again to send them to the page.我在我目前正在制作的网站上有一些 JavaScript,这会导致选定的链接在鼠标悬停时显示预览效果很好,但是对于触摸设备,当点击链接时它会显示预览,然后将用户发送到网站,我我希望它在第一次点击时只显示预览,然后如果他们再次点击将它们发送到页面。

How can I do this?我怎样才能做到这一点?

My Java Script that I've used:我使用过的 Java 脚本:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<link href="http://codegena.com/assets/css/image-preview-for-link.css" rel="stylesheet">     
<script type="text/javascript">
$(function() {
            $('#p1 a').miniPreview({ prefetch: 'pageload' });
            $('#p2 a').miniPreview({ prefetch: 'parenthover' });
            $('#p3 a').miniPreview({ prefetch: 'none' });
        });

And the HTML:和 HTML:

<p id="p1" align="center"><a href="http://link">link description</a><br><br><br><br><br><br><br><br></p>
<p id="p2" align="center"><a href="http://link">link description</a><br><br><br><br><br><br><br><br></p>
<p id="p3" align="center"><a href="http://link">link description</a><br><br><br><br></p>

Here is code that would prevent the first click from sending you to the page but the second click does.这里的代码会阻止第一次点击将您发送到页面,但第二次点击可以。

var click = 0;
$( "a" ).click(function( event ) {
var clickNum = ++click;
if(clickNum == 1) {
   event.preventDefault();
   //preview code
} 
});

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

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