本文实例讲述了jquery实现返回顶部效果的方法。分享给大家供大家参考。具体实现方法如下:
1、首先是CSS样式:
/*updown*/
#shangxia{position:fixed;top:83%;right:42%;margin-right:-543px;display:block;_display:none}
#shang,#comt,#xia{background:url(../images/sprite.png) no-repeat;position:relative;cursor:pointer;height:25px;width:29px;margin:10px 0 0}
#shang{background-position:0 -308px}#comt{background-position:0 -338px;height:32px}
#xia{background-position:0 -376px}
#comt:hover{background-position:-31px -338px}#shang:hover{background-position:-31px -308px}
#xia:hover{background-position:-31px -376px}
2、接着是jquery代码:(要引入jQuery核心库)
3、引用页面:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<style type="text/css">
/*updown*/
#shangxia{position:fixed;top:60%;right:50%;margin-right:-543px;display:block;_display:none}
#shang,#comt,#xia{background:url(images/sprite.png) no-repeat;position:relative;cursor:pointer;height:25px;width:29px;margin:10px 0 0}
#shang{background-position:0 -308px}#comt{background-position:0 -338px;height:32px}#xia{background-position:0 -376px}
#comt:hover{background-position:-31px -338px}#shang:hover{background-position:-31px -308px}#xia:hover{background-position:-31px -376px}
/*存档*/
</style>
///上面的是内部样式,上面已经有外部样式,如果不使用内部样式可以引入外部样式
<script type="text/javascript" src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script type="text/javascript" src="http://code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
<script type="text/javascript" src="js/updown/devework.js"></script>
</head>
<body>
<p>1</p>
<p>1</p>
<p>1</p>
<p>1</p>
<p>1</p>
<p>1</p>
<p>1</p>
<p>1</p>
<p>1</p>
<p>1</p>
<p>1</p>
<p>1</p>
<p>1</p>
<p>1</p>
<p>1</p>
<p>1</p>
<p>1</p>
<p>1</p>
<p>1</p>
<p>1</p>
<p>1</p>
<p>1</p>
<p>1</p>
<p>1</p>
<p>1</p>
<p>1</p>
<p>1</p>
<p>1</p>
<p>1</p>
<p>1</p>
<p>1</p>
<p>1</p>
<p>1</p>
<p>1</p>
<p>1</p>
<p>333</p>
<div class="aritcle_card">
<a class="aritcle_card_img" href="/ai/1051">
<img src="https://img.php.cn/upload/ai_manual/001/503/042/68b6cb08a59ca496.jpeg" alt="Voicepods">
</a>
<div class="aritcle_card_info">
<a href="/ai/1051">Voicepods</a>
<p>Voicepods是一个在线文本转语音平台,允许用户在30秒内将任何书面文本转换为音频文件。</p>
<div class="">
<img src="/static/images/card_xiazai.png" alt="Voicepods">
<span>93</span>
</div>
</div>
<a href="/ai/1051" class="aritcle_card_btn">
<span>查看详情</span>
<img src="/static/images/cardxiayige-3.png" alt="Voicepods">
</a>
</div>
<p>333</p>
<p>333</p>
<p>333</p>
<p>333</p>
<p>333</p>
<p>333</p>
<p>333</p>
<p>333</p>
<p>333</p>
<p>333</p>
<p>333</p>
<p>333</p>
<p>333</p>
<p>333</p>
<p>333</p>
<p>333</p>
<p>333</p>
<p>333</p>
<p>333</p>
<p>333</p>
<p>333</p>
<p>333</p>
<p>333</p>
<p>333</p>
<p>333</p>
<p>333</p>
<p>333</p>
<p>333</p>
<p>333</p>
<p>333</p>
<p>333</p>
<p>333</p>
<p>333</p>
<p>333</p>
<p>333</p>
<p>333</p>
<p>333</p>
<p>333</p>
<p>333</p>
<p>333</p>
<p>333</p>
<p>333</p>
<p>333</p>
<p>333</p>
<p>333</p>
<p>333</p>
<p>333</p>
<p>333</p>
<p>333</p>
<p>333</p>
<p>333</p>
<p>333</p>
<p>333</p>
<p>333</p>
<p>333</p>
<p>333</p>
<p>333</p>
<p>333</p>
<p>333</p>
<p>333</p>
<p>333</p>
<p>333</p>
<div id="shangxia">
<div id="shang" title="↑ 返回顶部"></div>
<div id="comt" title="沙发还没有被抢哦"></div>
<div id="xia" title="↓ 移至底部"></div>
</div>
</body>
</html>
希望本文所述对大家的jQuery程序设计有所帮助。
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号