【轉(zhuǎn)】angularjs無縫滾動slide-follow

html:

<ion-view view-title="Chats">

<ion-content>

<style>

*{margin: 0px;padding: 0px;}

.slide {width: 200px;height:50px;border:1px solid #dcdcdc;margin: 0 auto;margin-top: 50px;overflow: hidden;}//加粗的height可以修改高度,現(xiàn)在每次滾動僅顯示一條廣告。

.slide li {height: 49px;line-height: 49px;text-align: left;padding: 0 10px;font-size: 16px;list-style: none;border-bottom: 1px dashed #dcdcdc;cursor: pointer;}

.slide li:hover{background: #ccc;}

</style>

<div class="slide">

<ul class="slideUl">

<li ng-repeat = 'data in datasetData'>{{data.option}}</li>//指令

</ul>

</div>

</ion-content>

</ion-view>


angularjs:

.controller('ChatsCtrl', function($scope, $timeout,Chats) {

// 數(shù)據(jù)可以根據(jù)自己使用情況更換

$scope.datasetData = [

{option : "這個是第一條數(shù)據(jù)"},

{option : "這個是第二條數(shù)據(jù)"},

{option : "這個是第三條數(shù)據(jù)"},

{option : "這個是第四條數(shù)據(jù)"},

{option : "這個是第五條數(shù)據(jù)"},

{option : "這個是第六條數(shù)據(jù)"}

]

myxiaolaba();

function myxiaolaba(){

$timeout(function(){

var className = $('.slideUl');

var i = 0,sh;

var liLength = className.children("li").length;

var liHeight = className.children("li").height() + parseInt(className.children("li").css('border-bottom-width'));

className.html(className.html() + className.html());

// 開啟定時器

sh = setInterval(slide,1000);//1000毫秒滾動一次

function slide(){

if (parseInt(className.css("margin-top")) > (-liLength * liHeight)) {

i++;

className.animate({

marginTop : -liHeight * i + "px"

},"slow");

} else {

i = 0;

className.css("margin-top","0px");

}

}

// 清除定時器

className.hover(function(){

clearInterval(sh);

},function(){

clearInterval(sh);

sh = setInterval(slide,1000);

})

},0)

}

})



效果大約是這樣

當然還有別的寫法,若要使用directive,可參考這個,

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容