鼠标滚动时的 JQuery 淡入/淡出

发布于 2024-08-25 00:24:48 字数 365 浏览 4 评论 0原文

我想知道 jQuery 是否可以处理以下操作:

我想在读者开始向下滚动 Blogspot 博客页面时显示 url 链接。这些链接将始终保持 100% 可见,直到读者将页面滚动到顶部位置(0% 可见)。

我找到了一个 jQuery,它是这里

但这就像滚动到网站顶部按钮一样。我希望我的 jQuery 完全像这样工作,但它不会在鼠标单击时滚动到顶部,而是将读者重定向到特定的 url 链接(在鼠标单击时)。

可以这样做吗?

谢谢。

I was wondering if jQuery can handle following action:

I would like to display url links when readers starts to scroll down Blogspot blog page. These links will stay 100% visible all the time until readers scroll the page to the top position (0% visible).

I have found one jQuery, it is here.

But this one works like scroll to the top of the website button. I would like my jQuery works exactly like this but instead of scrolling to the top on mouse click, it will redirect reader to specific url link (on mouse click).

Is it possible to do this?

Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦途 2024-09-01 00:24:48

如果您使用普通锚点,这样点击就像普通链接一样发生,您可以对淡入淡出执行此操作:

$(function() {
  $(document).scroll(function() {
    if($('body').scrollTop() == 0)
      $("a.hide:visible").fadeOut();
    else 
      $("a.hide:hidden").fadeIn();
  });
});

这个CSS,以便它们最初隐藏:

.hide { display: none; }

像这样定义您的链接:

<a class="hide" href="Http://google.com">Google Link</a>

这个脚本表示我们是否在顶部(< code>$('body').scrollTop() == 0) 淡出可见的 class="hide" 链接,如果我们不在顶部,则淡出只需将 class="hide" 分配给您希望以这种方式表现的链接即可。

If you use normal anchors so the click happens like a normal link, you can do this for the fading:

$(function() {
  $(document).scroll(function() {
    if($('body').scrollTop() == 0)
      $("a.hide:visible").fadeOut();
    else 
      $("a.hide:hidden").fadeIn();
  });
});

And this CSS so they're initially hidden:

.hide { display: none; }

Define your links like this:

<a class="hide" href="Http://google.com">Google Link</a>

This script says if we're at the top ($('body').scrollTop() == 0) fade out the class="hide" links that are visible, if we're not at the top, fade them in. Just assign class="hide" to the links you want to behave this way.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文