国产探花免费观看_亚洲丰满少妇自慰呻吟_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程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 象山县| 贵州省| 东阳市| 台湾省| 深泽县| 辽阳市| 泽普县| 武宣县| 浑源县| 怀来县| 舒城县| 滨州市| 江西省| 常山县| 方山县| 离岛区| 丹凤县| 仁化县| 安丘市| 齐齐哈尔市| 论坛| 祥云县| 泰顺县| 德庆县| 佛教| 光山县| 博客| 区。| 太保市| 社旗县| 建阳市| 临湘市| 丹凤县| 定结县| 额济纳旗| 新乐市| 乐亭县| 景谷| 万全县| 九龙城区| 香港|