简体   繁体   English

返回顶部导致标签无法单击的按钮

[英]Back to Top button causing a tag cannot click

I'm developing website that allow user to click Back to Top when they scroll to bottom. 我正在开发一个允许用户在滚动到底部时单击“ 返回顶部”的网站。 I use jQuery, It worked well. 我使用jQuery,效果很好。 However, it has a problem with link (a tag). 但是,链接(标签)有问题。 All the link that locate on the same navigator position with Back to Top button will not able to click. 使用“返回首页”按钮位于同一导航器位置的所有链接将无法单击。 Other links beside that position can click normally. 该位置旁边的其他链接可以正常单击。

Here is jQuery code 这是jQuery代码

$(function () {
$(window).scroll(function () {
  if ($(this).scrollTop() > 200) {
    $('#back-top').fadeIn();
  } else {
    $('#back-top').fadeOut();
  }
});

// scroll body to 0px on click
$('#back-top a').click(function () {
$('body,html').animate({
  scrollTop: 0 }, 800);
  return false;
});
});

PHP + HTML PHP + HTML

<?php
echo "<td align='center'>
echo "<a href='edit_request.php?edit=$row[Req_ID]'>Edit</a> | <a href='action.php?delete=$row[Req_ID]'>Delete</a>";
echo "</td>";
?>

<p id="back-top">
<a href="#top"><span></span>Back to Top</a>
</p>

Can anyone know the problem that causing link (a tag) cannot be cliked? 谁能知道导致链接(标签)无法被点击的问题吗?

Thank in advance. 预先感谢。

This code is working fine, however the first function you have is detecting that the scrolltop is less than 200 and hiding the link at the bottom. 该代码可以正常工作,但是您拥有的第一个功能是检测滚动顶小于200,并将链接隐藏在底部。

If you comment out this function as i have done in the demo below it will work fine. 如果像我在下面的演示中所做的那样注释掉此功能,它将正常工作。

Demo: http://jsfiddle.net/WzrLM/ 演示: http//jsfiddle.net/WzrLM/

$(function () {
/*
 $(window).scroll(function () {
    console.log($(this).scrollTop());
    if ($(this).scrollTop() > 200) {
    $('#back-top').fadeIn();
  } else {
    $('#back-top').fadeOut();
  }
});
   */

// scroll body to 0px on click
$('#back-top a').click(function () {
$('body,html').animate({
  scrollTop: 0 }, 800);
  return false;
});
});

Your css should be: 您的CSS应该是:

#back-top {
    position: fixed;
    bottom: 30px;
}

#back-top a {
    width: 100px;
    display: block;
    text-align: center;
}

see Demo 演示

I guess it is because your "p" element has a 100% width (as a block element) and you specify a big z-index for it (or place it after other "a" tags), so it covers other elements on this line (including "a" tag) and you cannot click those elements. 我猜这是因为您的“ p”元素具有100%的宽度(作为块元素),并且为其指定了较大的z-index(或将其放置在其他“ a”标签之后),因此它涵盖了此元素上的其他元素行(包括“ a”标签),则无法单击这些元素。

You can give the "p" (or even its parent node) a visible attribute (background, border, etc) to detect if above situation happens. 您可以给“ p”(甚至它的父节点)一个可见属性(背景,边框等),以检测是否发生上述情况。 If so, you can just change the width of the block element to make it will not overlap with other elements. 如果是这样,您可以仅更改块元素的宽度以使其不会与其他元素重叠。

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

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