<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12
      Fork me on GitHub

      jQuery實(shí)現(xiàn)在線文檔

      1.1.1 摘要

      現(xiàn)在,許多網(wǎng)站都提供在線圖片和圖書閱讀的功能,這種方式比下載后閱讀來的直觀和人性化,要實(shí)現(xiàn)該功能涉及到點(diǎn)擊處理和圖片動(dòng)態(tài)加載。

      在接下來的博文中,我們將通過Javascript方式實(shí)現(xiàn)在線閱讀這一功能。

      1.1.2 正文

      Index頁面

      首先,我們創(chuàng)建index.html頁面,它包含三個(gè)div元素分別是content、controls和doccontainer,其中controls用來顯示翻頁控件(前/后翻),而doccontainer用于顯示圖片,具體定義如下:

      <!doctype html>
      <html lang="en-US">
      <head>
          <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
          <title>Online Document Viewer Demo</title>
          <meta name="author" content="JK_Rush">
          <link rel="stylesheet" type="text/css" media="all" href="css/style.css">
          <script type="text/javascript" src="js/jquery-1.9.1.min.js"></script>
          <script type="text/javascript" src="js/jquery.onlinedocview.js"></script>
          <script type="text/javascript">
              $(document).ready(function () {
                      $("#controls").viewer();
              });
          </script>
      </head>
      <body>
          <div>
              <div id="Div1">
                  <h1>Online Document Viewer Demo</h1>
                  <div id="controls">
                      <div id="backpage" class="ios-arrow-left">Back</div>
                      <div id="forwardpage" class="ios-arrow-right">Forward</div>
                  </div>
                  <div id="doccontainer">
                      <img src="img/1.jpg" data-page="1" title="click for next page"></div>
              </div><!-- END #content -->
          </div><!-- END # -->
      </body>
      

       onlineviewer0

      圖1 index頁面

      上面,我們定義了index.html頁面,引用了jQuery庫文件,在controls元素中包含backpage和forwardpage控件元素,它用于表示前或后翻頁的操作;而doccontainer中img的元素用于顯示文檔,每當(dāng)用戶點(diǎn)擊前或后翻頁就會(huì)加載相應(yīng)的內(nèi)容到img元素中。

      Javascript

      接下來,我們需要實(shí)現(xiàn)在線文檔的翻頁功能和內(nèi)容的動(dòng)態(tài)加載,我們定義jQuery插件方法viewer(),當(dāng)用戶點(diǎn)擊#backpage和#forwardpage控件元素時(shí)實(shí)現(xiàn)向前或后翻頁并且動(dòng)態(tài)地加載相應(yīng)的文檔,具體定義如下:

      /*****
      * The viewer function, when user click #forwardpage, #backpage or image directly,
      * load the corrosponding image.
      ******/
      $.fn.viewer = function(options) {
          'use strict';
      
          var opts = $.extend(true, {}, $.fn.viewer.defaults, options);
      
          var $docImage = $('#doccontainer > img');
      
          // Implements the image click function.
          $docImage.on('click', function(e) {
              e.preventDefault();
              var currentId = $(this).attr('data-page'),
              // Gets next page id.
                      nextImgId = parseInt(currentId) + 1,
                      nextImgSrc = opts.imgDirectory;
      
              if (currentId == opts.lastDocNum) {
                  // If the last page, then do nothing
                  return false;
              }
      
              nextImgSrc += getFile(nextImgId);
              $(this).attr('data-page', nextImgId);
              $(this).attr('src', nextImgSrc);
          })
      
          // Implements #forwardpage and #backpage control click function.
          $('#controls > #forwardpage, #controls > #backpage').on('click', function(e) {
              e.preventDefault();
      
              var currentId = $docImage.attr('data-page'),
                      nextImgSrc = opts.imgDirectory;
      
              if ($(this).attr('id') == 'backpage') {
                  var nextImgId = parseInt(currentId) - 1;
              } else if ($(this).attr('id') == 'forwardpage') {
                  var nextImgId = parseInt(currentId) + 1;
              }
      
              if ((currentId == opts.lastDocNum && $(this).attr('id') == 'forwardPage') ||
                      (currentId == 1 && $(this).attr('id') == 'backpage')) {
                  // If the last page or the first page, then do nothing.
                  return false;
              }
      
              // Loads corresponding image file.
              nextImgSrc += getFile(nextImgId);
              $docImage.attr('data-page', nextImgId);
              $docImage.attr('src', nextImgSrc);
      
          })
      
          // Constructs the image file name.
          function getFile(n) {
              return n + '.' + opts.fileType;
          }
      
      };

      上面,我們定義了jQuery方法viewer(),我們實(shí)現(xiàn)了#forwardpage、#backpage和#doccontainer的點(diǎn)擊事件處理方法,當(dāng)用戶點(diǎn)擊#forwardpage、#backpage或#doccontainer動(dòng)態(tài)地加載相應(yīng)的文檔,我們通過修改img元素的src屬性來動(dòng)態(tài)加載文檔,并且通過data-page屬性保存當(dāng)前文檔的頁碼。

      CSS樣式

      最后,我們給#forwardpage和#backpage控件元素添加CSS樣式,具體化定義如下:

      /*Back and Forward button style*/
      .ios-arrow-left {
          cursor:pointer;
          display : block; 
          position:absolute;
          z-index : 0;
          left:50px;
          top:50px;    
          height:30px;
          width:auto;
          padding: 0 10px 0 6px;
          background-repeat:repeat-x;
          background-size : 100% 30px;
          background-position :0;
          background-image : -webkit-linear-gradient(
              bottom,
              rgba(0,0,0,0) 0%,
              rgba(0,0,0,0) 50%,
              rgba(255,255,255,0.1) 50%,
              rgba(255,255,255,0.3) 100%
              );
          border-radius: 5px;
          border-bottom: 1px solid rgba(255,255,255,0.4);
          box-shadow :0 -1px 1px rgba(0,0,0,0.2)inset,
                      0 1px 2px rgba(0,0,0,0.8)inset;
          font-family : HelveticaNeue;
          font-weight: 400;
          font-size : 12px;
          line-height : 30px;
          text-align:center;
          color:#fff;
          text-shadow : 0px -1px 0px rgba(0,0,0,0.8);
      }
      .ios-arrow-left:before{
          position:absolute;
          content : ' ';
          left:-8px;
          top:3.5px;
          height : 24px;
          width: 24px;
          z-index : 1;
          background-repeat:repeat-x;
          background-size : 20px 20px;
          background-position :-1px -0.5px;
          background-image :  
              -webkit-gradient(linear, left bottom, right top, 
                  from(rgba(0,0,0,0)), 
                  color-stop(0.5, rgba(0,0,0,0)), 
                  color-stop(0.5, rgba(255,255,255,0.1)), 
                  to(rgba(255,255,255,0.3))); 
          -webkit-transform : rotate(-45deg) skew(-10deg, -10deg);
          border-top-right-radius : 10px;
          border-top-left-radius :0px;
          border-bottom-right-radius : 0px;
          border-bottom-left-radius : 10px;
          border-left : 1.5px solid rgba(255,255,255,0.4);
          box-shadow :  1px 1px 1px rgba(0,0,0,0.4) inset,
              -1px 1px 1px rgba(0,0,0,0.5) inset;
          -webkit-mask-image : 
              -webkit-gradient(linear, left top, right bottom,
                  from(#000000), 
                  color-stop(0.4,#000000), 
                  color-stop(0.5, transparent), 
                  to(transparent));
      }
      
      .ios-arrow-right {
          cursor:pointer;
          display : block; 
          position:absolute;
          z-index : 0;
          right:50px;
          top:50px;    
          height:30px;
          width:auto;
          padding: 0 6px 0 10px;
          background-repeat:repeat-x;
          background-size : 100% 30px;
          background-position :0;
          background-image : -webkit-linear-gradient(
              bottom,
              rgba(0,0,0,0) 0%,
              rgba(0,0,0,0) 50%,
              rgba(255,255,255,0.1) 50%,
              rgba(255,255,255,0.3) 100%
              );
          border-radius: 5px;
          border-bottom: 1px solid rgba(255,255,255,0.4);
          box-shadow :0 -1px 1px rgba(0,0,0,0.2)inset,
                      0 1px 2px rgba(0,0,0,0.8)inset;
          font-family : HelveticaNeue;
          font-weight: 400;
          font-size : 12px;
          line-height : 30px;
          text-align:center;
          color:#fff;
          text-shadow : 0px -1px 0px rgba(0,0,0,0.8);
      }
      .ios-arrow-right:after{
          position:absolute;
          content : ' ';
          right:-7.5px;
          top:3px;
          height : 24px;
          width: 24px;
          z-index : 1;
          background-repeat:repeat-x;
          background-size : 20px 20px;
          background-position :-1px -0.5px;
          background-image :  
              -webkit-gradient(linear, left bottom, right top, 
                  from(rgba(255,255,255,0.3)), 
                   color-stop(0.5, rgba(255,255,255,0.1)), 
                 color-stop(0.5, rgba(0,0,0,0)), 
                  to(rgba(0,0,0,0))); 
          -webkit-transform : rotate(135deg) skew(-10deg, -10deg);
          border-top-right-radius : 10px;
          border-top-left-radius :0px;
          border-bottom-right-radius : 0px;
          border-bottom-left-radius : 10px;
          border-top : 1.5px solid rgba(255,255,255,0.4);
          box-shadow :  1px 1px 1px rgba(0,0,0,0.5) inset,
              -1px 1px 1px rgba(0,0,0,0.4) inset;
          -webkit-mask-image : 
              -webkit-gradient(linear, left top, right bottom,
                  from(#000000), 
                  color-stop(0.4,#000000), 
                  color-stop(0.5, transparent), 
                  to(transparent));
      }
      
      .ios-arrow-right,
      .ios-arrow-right:after,
      .ios-arrow-left,
      .ios-arrow-left:before {
          background-color: rgba(33,33,33,1);/*normalcolor*/
      }
      
      .ios-arrow-right:hover,
      .ios-arrow-right:hover:after,
      .ios-arrow-left:hover,
      .ios-arrow-left:hover:before {
          background-color: rgba(0,0,0,1);/*hovercolor*/
      }
      
      /*************************************************
      

      onlineviewer2

      圖2在線文檔

      現(xiàn)在,我們已經(jīng)實(shí)現(xiàn)了在線查看文檔的功能了,由于我們使用Javascript動(dòng)態(tài)地加載文檔內(nèi)容,所以無需刷新頁面,我們只需替換相應(yīng)的文檔鏈接地址就好了,這樣不但減少了Http請(qǐng)求的次數(shù)減輕了網(wǎng)站的負(fù)載,而且無刷新用戶體驗(yàn)更好。

      1.1.3 總結(jié)

      本文我們通過一個(gè)在線文檔查看程序,介紹了通過jQuery實(shí)現(xiàn)動(dòng)態(tài)加載數(shù)據(jù)的功能,通過使用jQuery動(dòng)態(tài)加載數(shù)據(jù)無需刷新頁面,只需替換相應(yīng)的文檔鏈接地址就好了,并且減少了網(wǎng)站的Http請(qǐng)求次數(shù),減輕網(wǎng)絡(luò)負(fù)載和加載延遲。

      參考

      [1] http://designshack.net/articles/javascript/coding-an-ajax-style-paged-document-viewer-with-jquery/

      Demo

      posted @ 2013-11-29 22:01  JK_Rush  閱讀(13743)  評(píng)論(6)    收藏  舉報(bào)
      主站蜘蛛池模板: 国产人成精品一区二区三| 朝鲜女子内射杂交bbw| 国产精品无遮挡猛进猛出| 国产高清精品在线一区二区| 国产啪视频免费观看视频| 成人自拍小视频免费观看| 久久精品国产99国产精品澳门| 亚洲不卡一区三区三区四| 国产精品日日摸夜夜添夜夜添2021 | 久久精品亚洲国产成人av| 济阳县| 亚洲国产精品综合久久20| 欧美视频精品免费覌看| 国产精品久久久久AV福利动漫 | 欧美极品色午夜在线视频| 久久国产成人精品国产成人亚洲| 亚洲AV无码破坏版在线观看| 国产乱码精品一区二区三| 午夜福利片1000无码免费| 忘忧草在线社区www中国中文| 久久av高潮av喷水av无码| 亚洲国产高清第一第二区| 又大又粗又硬又爽黄毛少妇| 亚洲精品国产电影| 日韩av在线一卡二卡三卡| 中文字幕国产精品资源| 久久五月丁香激情综合| 99久久无色码中文字幕| 久久精品伊人狠狠大香网| 国产中文99视频在线观看| 国产中文成人精品久久久| 欧洲精品色在线观看| 亚洲精品入口一区二区乱| 手机在线看片不卡中文字幕| 熟妇无码熟妇毛片| 老司机精品成人无码AV| 欧美一区二区三区性视频| 成人又黄又爽又色的视频| 中文字幕日韩精品国产| 在线免费播放av观看| 人妻av一区二区三区av免费|