国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

jQuery實現返回頂部效果的方法

2019-11-20 12:23:18
字體:
來源:轉載
供稿:網友

本文實例講述了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核心庫)

復制代碼 代碼如下:
/*updown*/ 
jQuery(document).ready(function($) {$body = (window.opera) ? (document.compatMode == "CSS1Compat" ? $("html") : $("body")) : $("html,body");$("#shang").mouseover(function() {up()}).mouseout(function() {clearTimeout(fq)}).click(function() {$body.animate({scrollTop: 0},400)});$("#xia").mouseover(function() {dn()}).mouseout(function() {clearTimeout(fq)}).click(function() {$body.animate({scrollTop: $(document).height()},400)});$("#comt").click(function() {$body.animate({scrollTop: $("#comments").offset().top},400)});});function up() {$wd = jQuery(window);$wd.scrollTop($wd.scrollTop() - 1);fq = setTimeout("up()", 50)};function dn() {$wd = jQuery(window);$wd.scrollTop($wd.scrollTop() + 1);fq = setTimeout("dn()", 50)};

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>     <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程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 北宁市| 鲁山县| 丁青县| 昭平县| 永川市| 稻城县| 万盛区| 察雅县| 冕宁县| 津南区| 五大连池市| 邢台县| 松滋市| 广丰县| 柳江县| 上高县| 张北县| 砚山县| 陆丰市| 宁阳县| 津南区| 阿巴嘎旗| 汤原县| 郴州市| 富源县| 鄂温| 河西区| 鄂托克旗| 嘉善县| 祁门县| 即墨市| 明水县| 台安县| 镶黄旗| 金塔县| 明溪县| 万盛区| 黄石市| 大方县| 全州县| 铁岭县|