乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      使用ionic框架的<ion

       昨夜霧濃 2018-04-25

      混合app開發(fā)使用ionic框架的<ion-scroll>指令能夠方便地實現(xiàn)水平滾動和垂直滑動。比如我們想實現(xiàn)一個能夠水平滑動的畫廊,可以使用下面這段代碼。

      1. <html>  
      2.   <head>  
      3.     <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />   
      4.     <script src="jquery-1.11.1.min.js"></script>  
      5.     <script src="./1.1.1-release/js/ionic.bundle.js"></script>  
      6.     <link rel="stylesheet" type="text/css" href="./1.1.1-release/css/ionic.css" />  
      7.     <style>  
      8.     /*nowrap不讓img換行*/  
      9.     .picturesholder{  
      10.         background-color:#fff;  
      11.         margin:20px;  
      12.         width:400px;  
      13.         height:80px;  
      14.         overflow: hidden;  
      15.         white-space: nowrap;  
      16.     }  
      17.       
      18.     /**圖片占滿畫廊*/  
      19.     .picturesholder img{  
      20.         width:100px;  
      21.         height:81px;  
      22.     }  
      23.     </style>  
      24.   
      25.     <script>  
      26.     var testModule = angular.module('testApp', ['ionic']);  
      27.     testModule.controller('MyController', function($scope, $ionicScrollDelegate) {  
      28.         $scope.pictures=["imgs/1.png","imgs/2.png","imgs/3.png","imgs/4.png","imgs/5.png","imgs/6.png","imgs/7.png","imgs/8.png"];  
      29.     });  
      30.       
      31.     $(function(){  
      32.         angular.bootstrap($("#body"), ["testApp"]);   
      33.     })  
      34.     </script>  
      35. </head>  
      36.   
      37. <body id="body" ng-controller="MyController">  
      38.     
      39.     <ion-header-bar class="bar-positive">  
      40.         <h1 class="title">bar-positive</h1>  
      41.     </ion-header-bar>  
      42.     
      43.     <ion-content class="has-header" style="background-color: #ebebeb;">  
      44.       
      45.         <div class="picturesholder">  
      46.             <ion-scroll direction="x">  
      47.                 <img ng-src="{{each}}" ng-repeat="each in pictures"></img>  
      48.             </ion-scroll>           
      49.         </div>  
      50.           
      51.     </ion-content>  
      52.       
      53.     <ion-footer-bar class="bar-balanced">  
      54.         <div class="title">Footer</div>  
      55.     </ion-footer-bar>  
      56. </body>  
      57. </html>  
      58.   
      59.       


      單看這一個水平畫廊是沒有什么問題的,功能和操作都很正常。但是我們項目中遇到一個問題:一個頁面很大,有多個畫廊控件,我們的頁面很難上下滑動,滑動非常吃力,這是為什么呢?舉個例子:如果你的頁面放的全都是input輸入控件,那么這個頁面一樣很難滑動,因為當我們在手機屏幕上滑動的時候,一不小心很容易就會點中這些輸入框,當輸入框獲得焦點,頁面就不能滑動了。使用<ion-scroll>一樣有這個問題,當頁面全是畫廊控件的時候,滑動也十分費勁。


      從ionic文檔中也沒有找到好的解決辦法,最后解決方法是:不使用<ion-scroll>指令,自己實現(xiàn)左右滑動。利用HTML5中的touchmove和touchstart事件實現(xiàn)滾動:

      [javascript] view plain copy
      print?
      1. // do for left-right scroll  
      2. var startX = 0;  
      3. var startY = 0;  
      4. var $gallery = $(".picturesholder");  
      5.   
      6. $gallery.on("touchstart", function(e) {  
      7.      startX = e.originalEvent.changedTouches[0].pageX,  
      8.      startY = e.originalEvent.changedTouches[0].pageY;  
      9. });  
      10.   
      11. $gallery.on("touchmove", function(e) {  
      12.     var X = e.originalEvent.changedTouches[0].pageX - startX;  
      13.     var Y = e.originalEvent.changedTouches[0].pageY - startY;  
      14.        
      15.     if ( Math.abs(X) > Math.abs(Y) && X > 0 ) {  
      16.         var cur_scroll = $(this).scrollLeft();  
      17.         $(this).scrollLeft(parseInt(cur_scroll) - X);  
      18.         e.preventDefault();  
      19.         e.stopPropagation();  
      20.     }  
      21.     else if ( Math.abs(X) > Math.abs(Y) && X < 0 ) {  
      22.         var cur_scroll = $(this).scrollLeft();  
      23.         $(this).scrollLeft(parseInt(cur_scroll) - X);  
      24.         e.preventDefault();  
      25.         e.stopPropagation();  
      26.     }  
      27.     else if ( Math.abs(Y) > Math.abs(X) && Y > 0) {  
      28.     }  
      29.     else if ( Math.abs(Y) > Math.abs(X) && Y < 0 ) {  
      30.     }  
      31.     else{  
      32.     }  
      33. });  
      34. // do for left-right scroll  

      web瀏覽器沒有上面2個事件,我們可以用mousedown和mousemove模擬,下面代碼一樣可以左右滑動。
      1. <html>  
      2.   <head>  
      3.     <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />   
      4.     <script src="jquery-1.11.1.min.js"></script>  
      5.     <script src="./1.1.1-release/js/ionic.bundle.js"></script>  
      6.     <link rel="stylesheet" type="text/css" href="./1.1.1-release/css/ionic.css" />  
      7.     <style>  
      8.     /*nowrap不讓img換行*/  
      9.     .picturesholder{  
      10.         background-color:#fff;  
      11.         margin:20px;  
      12.         width:400px;  
      13.         height:80px;  
      14.         overflow: hidden;  
      15.         white-space: nowrap;  
      16.     }  
      17.       
      18.     /**圖片占滿畫廊*/  
      19.     .picturesholder img{  
      20.         width:100px;  
      21.         height:81px;  
      22.     }  
      23.     </style>  
      24.   
      25.     <script>  
      26.     var testModule = angular.module('testApp', ['ionic']);  
      27.     testModule.controller('MyController', function($scope, $ionicScrollDelegate) {  
      28.         $scope.pictures=["imgs/1.png","imgs/2.png","imgs/3.png","imgs/4.png","imgs/5.png","imgs/6.png","imgs/7.png","imgs/8.png"];  
      29.     });  
      30.       
      31.     $(function(){  
      32.         angular.bootstrap($("#body"), ["testApp"]);   
      33.           
      34.         // do for left-right scroll  
      35.         var startX = 0;  
      36.         var startY = 0;  
      37.         var $pictures = $(".picturesholder");  
      38.           
      39.         $pictures.on("mousedown", function(e) {  
      40.              startX = e.originalEvent.pageX,  
      41.              startY = e.originalEvent.pageY;  
      42.         });  
      43.           
      44.         $pictures.on("mousemove", function(e) {  
      45.             var X = e.originalEvent.pageX - startX;  
      46.             var Y = e.originalEvent.pageY - startY;  
      47.                
      48.             if ( Math.abs(X) > Math.abs(Y) && X > 0 ) {  
      49.                 var cur_scroll = $(this).scrollLeft();  
      50.                 $(this).scrollLeft(parseInt(cur_scroll) - X);  
      51.                 e.preventDefault();  
      52.                 e.stopPropagation();  
      53.             }  
      54.             else if ( Math.abs(X) > Math.abs(Y) && X < 0 ) {  
      55.                 var cur_scroll = $(this).scrollLeft();  
      56.                 $(this).scrollLeft(parseInt(cur_scroll) - X);  
      57.                 e.preventDefault();  
      58.                 e.stopPropagation();  
      59.             }  
      60.             else if ( Math.abs(Y) > Math.abs(X) && Y > 0) {  
      61.             }  
      62.             else if ( Math.abs(Y) > Math.abs(X) && Y < 0 ) {  
      63.             }  
      64.             else{  
      65.             }  
      66.         });  
      67.         // do for left-right scroll  
      68.     })  
      69.     </script>  
      70. </head>  
      71.   
      72. <body id="body" ng-controller="MyController">  
      73.     
      74.     <ion-header-bar class="bar-positive">  
      75.         <h1 class="title">bar-positive</h1>  
      76.     </ion-header-bar>  
      77.     
      78.     <ion-content class="has-header" style="background-color: #ebebeb;">  
      79.       
      80.         <div class="picturesholder">  
      81.             <!--<ion-scroll direction="x">-->  
      82.                 <img ng-src="{{each}}" ng-repeat="each in pictures"></img>  
      83.             <!--</ion-scroll>-->      
      84.         </div>  
      85.           
      86.     </ion-content>  
      87.       
      88.     <ion-footer-bar class="bar-balanced">  
      89.         <div class="title">Footer</div>  
      90.     </ion-footer-bar>  
      91. </body>  
      92. </html>  
      93.   
      94.       


        本站是提供個人知識管理的網(wǎng)絡存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導購買等信息,謹防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
        轉(zhuǎn)藏 分享 獻花(0

        0條評論

        發(fā)表

        請遵守用戶 評論公約