Warning: error_log(/data/www/wwwroot/hmttv.cn/caches/error_log.php): failed to open stream: Permission denied in /data/www/wwwroot/hmttv.cn/phpcms/libs/functions/global.func.php on line 537 Warning: error_log(/data/www/wwwroot/hmttv.cn/caches/error_log.php): failed to open stream: Permission denied in /data/www/wwwroot/hmttv.cn/phpcms/libs/functions/global.func.php on line 537 最近中文字幕最新在线视频,国产又黄又爽又猛的免费视频播放,亚洲欧洲日本天天堂在线观看

          整合營銷服務商

          電腦端+手機端+微信端=數據同步管理

          免費咨詢熱線:

          巧用CSS3-Animation動畫,實現小程序彈幕效果

          近接到公司小程序項目首頁迭代改版的工作,涉及到文章圖文布局改版。主要是精選文章,在首頁推廣入口增加評論彈幕效果,后端彈幕數據是隨文章列表接口一次性返回給前端,由前端來處理彈幕數據及相關彈幕交互效果。

          隨后,簡單分析了一下后端接口的數據結構,以及查詢了一些傳統web端彈幕的js實現方式。

          鑒于我們當前業務的后端彈幕數據非動態持續發送,而是固定的評論條目,前端處理也僅僅是把文章評論渲染成彈幕并循環滾動,于是我采用的解決方案是通過css3的Animation動畫屬性來實現。

          下面是拆分出來的部分代碼demo實現效果的動畫演示效果。



          左邊的視頻演示:有序彈幕(固定軌道式,彈幕數據劃分為三條固定軌道進行滾動顯示)

          右邊的視頻演示:無序彈幕(每條彈幕的出現位置隨機性);

          如果視頻無法播放的話,可以查看下方對比圖:




          當前代碼邏輯比較適合一些展示型的前端交互效果,比如:資訊類欄目、社交屬性圖文欄目、推廣類廣告位等。

          # 無序彈幕 wxml #

          <view class='dmGroup' wx:for="{{ dmData }}" wx:key="{{ item.id }}" style="top:{{ item.top }}%; animation: dmAnimation {{item.time}}s linear {{ index*3 }}s infinite; ">
           <view class='dmItem'>
           <view class='dm'>
           <view class='avatarBox'>
           <image src='{{ item.sex == 0 ? avatarBoy : avatarGirl }}' class='avatar' mode='aspectFit'></image>
           <image src='{{ item.sex == 0 ? iconBoy : iconGirl }}' class='sex' mode='aspectFit'></image>
           </view>
           <text class='content'>{{ item.content }}</text>
           <image src='{{ iconGood }}' class='icon good' mode='aspectFill'></image>
           <text>{{ item.zanNumber }}</text>
           </view>
           </view>
          </view>
          


          # 無序彈幕 wxss #

          @keyframes dmAnimation{
           from{ left: 100%; }
           to{ left: -100%; }
          }
          


          # 有序彈幕(軌道式) wxml #

          <!-- top -->
          <view class='dmGroup top' style="animation: dmAnimation2 35s linear infinite; ">
           <view class='dmItem' wx:for="{{ dmData }}" wx:if="{{ index < 6 }}" wx:key="{{ item.id }}">
           <view class='dm'>
           <view class='avatarBox'>
           <image src='{{ item.sex == 0 ? avatarBoy : avatarGirl }}' class='avatar' mode='aspectFit'></image>
           <image src='{{ item.sex == 0 ? iconBoy : iconGirl }}' class='sex' mode='aspectFit'></image>
           </view>
           <text class='content'>{{ item.content }}</text>
           <image src='{{ iconGood }}' class='icon good' mode='aspectFill'></image>
           <text>{{ item.zanNumber }}</text>
           </view>
           </view>
          </view>
          <!-- mid -->
          <view class='dmGroup mid' style="animation: dmAnimation2 30s linear 1s infinite; ">
           <view class='dmItem' wx:for="{{ dmData }}" wx:if="{{ index > 5 && index < 10 }}" wx:key="{{ item.id }}">
           <view class='dm'>
           <view class='avatarBox'>
           <image src='{{ item.sex == 0 ? avatarBoy : avatarGirl }}' class='avatar' mode='aspectFit'></image>
           <image src='{{ item.sex == 0 ? iconBoy : iconGirl }}' class='sex' mode='aspectFit'></image>
           </view>
           <text class='content'>{{ item.content }}</text>
           <image src='{{ iconGood }}' class='icon good' mode='aspectFill'></image>
           <text>{{ item.zanNumber }}</text>
           </view>
           </view>
          </view>
          <!-- btm -->
          <view class='dmGroup btm' style="animation: dmAnimation2 45s linear infinite; ">
           <view class='dmItem' wx:for="{{ dmData }}" wx:if="{{ index > 9 }}" wx:key="{{ item.id }}">
           <view class='dm'>
           <view class='avatarBox'>
           <image src='{{ item.sex == 0 ? avatarBoy : avatarGirl }}' class='avatar' mode='aspectFit'></image>
           <image src='{{ item.sex == 0 ? iconBoy : iconGirl }}' class='sex' mode='aspectFit'></image>
           </view>
           <text class='content'>{{ item.content }}</text>
           <image src='{{ iconGood }}' class='icon good' mode='aspectFill'></image>
           <text>{{ item.zanNumber }}</text>
           </view>
           </view>
          </view>
          


          # 有序彈幕 wxss #

          @keyframes dmAnimation2{ 
           0% { transform: translateX(0); } 
           100% { transform: translateX(-130%); } 
          }
          


          # 查看線上項目彈幕效果 #


          # 詳細代碼片段及詳解,請私信喲#

          輪事件:滾輪

          滾動(卷動)事件:滾輪、拖拽滾動條、鍵盤方向鍵

          <script type="text/javascript">
          //滾輪事件:滾輪
          //卷動事件:滾輪、拖拽滾動條、鍵盤?鍵
          
          //IE和Chrome
          gunlun.onmousewheel = function(){
          this.innerHTML += "IE和Chrome<br/>";
          }
          //Firefox
          gunlun.addEventListener("DOMMouseScroll", function(){
          this.innerHTML += "Firefox<br/>";
          })
          </script>

          判斷滾輪方向

          <script type="text/javascript">
          //滾輪事件:滾輪
          //卷動事件:滾輪、拖拽滾動條、鍵盤?鍵
          
          //IE和Chrome
          gunlun.onmousewheel = function(e){
          var ev = e || window.event;
          console.log(ev.wheelDelta);//判斷滾輪方向的
          //上120
          //下-120
          
          this.innerHTML += "IE和Chrome<br/>";
          }
          //Firefox
          gunlun.addEventListener("DOMMouseScroll",function(e){
          var ev = e || window.event;
          console.log(ev.detail);//滾輪方向
          //上-3
          //下3
          this.innerHTML += "Firefox<br/>";
          })
          </script>

          兼容性封裝

          用JavaScript實現頁面滑動到指定位置加載動畫。

          若頁面滾動到class名為group-pic的元素的位置時開始加載


          1. $(document).ready(function(){
          2. var a,b,c;
          3. a = $(window).height(); //瀏覽器窗口高度
          4. var group = $(".group-pic");
          5. $(window).scroll(function(){
          6. b = $(this).scrollTop(); //頁面滾動的高度
          7. c = group.offset().top; //元素距離文檔(document)頂部的高度
          8. if(a+b>c){
          9. ...
          10. }else{
          11. ...
          12. }
          13. });
          14. });

          原理: 1.獲取瀏覽器窗口的高度;

          2.獲取頁面滾動的高度;

          3.獲取頁面距離文檔(document)頂部的高度

          offset().top具體指的是距哪里的高度呢?

          一些獲寬高度的屬性:

          網頁可見區域寬: document.body.clientWidth;

          網頁可見區域高: document.body.clientHeight;

          網頁可見區域寬: document.body.offsetWidth (包括邊線的寬);

          網頁可見區域高: document.body.offsetHeight (包括邊線的寬);

          網頁正文全文寬: document.body.scrollWidth;

          網頁正文全文高: document.body.scrollHeight;

          網頁被卷去的高: document.body.scrollTop;

          網頁被卷去的左: document.body.scrollLeft;

          網頁正文部分上: window.screenTop;

          網頁正文部分左: window.screenLeft;

          屏幕分辨率的高: window.screen.height;

          屏幕分辨率的寬: window.screen.width;

          屏幕可用工作區高度: window.screen.availHeight;

          屏幕可用工作區寬度:window.screen.availWidth;

          obj.offsetTop 指 obj 距離上方或上層控件的位置,整型,單位像素。

          obj.offsetLeft 指 obj 距離左方或上層控件的位置,整型,單位像素。

          obj.offsetWidth 指 obj 控件自身的寬度,整型,單位像素。

          obj.offsetHeight 指 obj 控件自身的高度,整型,單位像素。

          1.offsetTop : 當前對象到其上級層頂部的距離.

          不能對其進行賦值.設置對象到頁面頂部的距離請用style.top屬性.

          2.offsetLeft : 當前對象到其上級層左邊的距離.

          不能對其進行賦值.設置對象到頁面左部的距離請用style.left屬性.

          3.offsetWidth : 當前對象的寬度.

          與style.width屬性的區別在于:如對象的寬度設定值為百分比寬度,則無論頁面變大還是變小,style.width都返回此百分比,而offsetWidth則返回在不同頁面中對象的寬度值而不是百分比值

          4.offsetHeight : 與style.height屬性的區別在于:如對象的寬度設定值為百分比高度,則無論頁面變大還是變小,style.height都返回此百分比,而offsetHeight則返回在不同頁面中對象的高度值而不是百分比值


          主站蜘蛛池模板: 久久综合亚洲色一区二区三区 | 国产一区二区三区在线影院| 搜日本一区二区三区免费高清视频| 久久亚洲中文字幕精品一区| 好吊妞视频一区二区| 亚洲国产韩国一区二区| 久久久无码精品国产一区 | 亚洲一区在线视频观看| 国产成人精品一区二三区在线观看 | 成人精品一区二区电影| 无码免费一区二区三区免费播放| 国产日韩AV免费无码一区二区三区| 精品久久综合一区二区| 福利国产微拍广场一区视频在线 | 亚洲色精品vr一区二区三区| 美女免费视频一区二区三区| 韩国女主播一区二区| 无码人妻精品一区二区三区9厂| 亚洲制服丝袜一区二区三区| 精品国产一区二区三区四区| 亚洲一区二区三区亚瑟| 国产精品夜色一区二区三区| 亚洲国产AV一区二区三区四区| 亚洲综合色一区二区三区小说| 一区二区三区四区精品视频| 亚洲图片一区二区| 91视频一区二区| 免费无码A片一区二三区| 天天综合色一区二区三区| 国产色欲AV一区二区三区| 无码精品人妻一区二区三区免费 | 亚洲欧美国产国产一区二区三区| 2022年亚洲午夜一区二区福利| 亚洲av乱码一区二区三区| 亚洲性无码一区二区三区| 精品国产区一区二区三区在线观看| av一区二区三区人妻少妇| 国产aⅴ一区二区三区| 久久99精品免费一区二区| 亚洲午夜福利AV一区二区无码| 麻豆一区二区99久久久久|