移動端Ionic App 資訊上下循環(huán)滾動的實現(xiàn)代碼(跑馬燈效果)
在ionic App中遇到一個文字上下循環(huán)滾動的效果實現(xiàn),網(wǎng)上查了之后才知道有個通俗的名字-跑馬燈。
這里借助了jQuery庫的選擇器和動畫函數(shù),并且把jquery的操作封裝到指令里。先看指令代碼:
angular.module('starter')
.directive('slideScroll', function ($window, $timeout) {
return {
restrict: 'AE',
link: function (scope, element, attr) {
var _scrollHeight = 40;
var _newsLen = 3;
var index = 0;
setInterval(function () {
index += 1;
if (index > _newsLen) {
index = 0;
$(".news-right ul").css({
top: 0
})
} else {
$(".news-right ul").animate({
top: -_scrollHeight * index - 10 * index
}, 500);
}
}, 2000)
}
};
});
滾動的高度scrollHeight設(shè)置為40px,三組文字newsLen循環(huán),每組兩行文字。每隔2000ms,ul列表向上移動固定距離,top值為(_scrollHeight + 10)* index 的長度。
Html 代碼是這樣的:
<div class="news-right" ui-sref="newsList">
<ul slide-scroll>
<li class="news-box" ng-repeat="row in dataArr">
<p ng-repeat="item in row">{{item.title.length <= 19 ? item.title : item.title.slice(0, 19) + '...'}}</p>
</li>
<li>
<p ng-repeat="item1 in dataArr[0]">{{item1.title.length <= 19 ? item1.title : item1.title.slice(0, 19) + '...'}}</p>
</li>
</ul>
</div>
這里對文字做了簡單的處理,字符串超過19,會以“...”的形式顯示。
Css 樣式表是這樣的:
.news-right {
position: absolute;
height: 40px;
left: 100px;
top: 10px;
right: 0;
color: rgb(65, 65, 65);
overflow: hidden;
}
.news-right ul{
width: 100%;
position: absolute;
top: 0;
left: 0;
}
.news-right p {
padding: 0;
line-height: 15px;
text-overflow: ellipsis;
box-sizing: border-box;
white-space: nowrap;
font-size: 13px;
}
總結(jié)
以上所述是小編給大家介紹的移動端Ionic App 資訊上下循環(huán)滾動的實現(xiàn)代碼,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
相關(guān)文章
JS 兩日期相減,獲得天數(shù)的小例子(兼容IE,FF)
這篇文章介紹了兩日期相減,獲得天數(shù)的小例子,有需要的朋友可以參考一下2013-07-07
document.compatMode的CSS1compat使用介紹
這篇文章主要介紹了document.compatMode的CSS1compat使用,需要的朋友可以參考下2014-04-04

