如何显示“返回顶部”按钮使用jQuery只有浏览器的高度比页面? [英] How to show "back to top" button using jquery only if browser height is shorter than page?

查看:67
本文介绍了如何显示“返回顶部”按钮使用jQuery只有浏览器的高度比页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 div 中在底部添加/显示back to top按钮使用jquery 仅当浏览器高度小于网页时,隐藏?

How to add/show "back to top" button at bottom in a div using jquery only if height browser height is shorter than page, other wise it should be hidden?

<p><a href="#mainwrapper">Back to top</a></p>

到此

<div id="mainwrapper">

<p> Paragraph 1 </p>

<p> Paragraph 1 </p>

<p> Paragraph 1 </p>

<p> Paragraph 1 </p>

<p><a href="#mainwrapper">Back to top</a></p>

</div>

我需要几乎相同的像我的这个问题,但条件是不同的如何检测链接的PDF使用jquery下载Adobe Reader?

i need almost same like my this question but condition is different How to detect linked PDF on a page and show message to download Adobe reader using jquery?

我需要轻量级的简单解决方案

I need lightweight simple solution

推荐答案

像:

var wrapper = $('#mainwrapper');
if (wrapper.outerHeight(true) > $(window).height()) {
   wrapper.append('<p><a href="#' + wrapper.attr('id') + '">Back to top</a></p>');
}

这篇关于如何显示“返回顶部”按钮使用jQuery只有浏览器的高度比页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆