欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

angularjs實現(xiàn)文字上下無縫滾動特效代碼

 更新時間:2016年09月04日 15:29:21   作者:Jennry  
這篇文章主要介紹了angularjs實現(xiàn)文字上下無縫滾動特效代碼的相關(guān)資料,非常不錯,具有參考借鑒價值,需要的朋友可以參考下

最近沒有項目做,于是閑暇之余學(xué)習(xí)了下angularjs知識,然后寫了一個文字上下無縫滾動的例子,主要寫的是一個小小的指令。

css代碼:

主要控制樣式

<style type="text/css">
*{margin: 0px;padding: 0px;}
.slide {width: 200px;height:200px;border:1px solid #dcdcdc;margin: 0 auto;margin-top: 50px;overflow: hidden;}
.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>

html代碼:

<body ng-app="tip">
<div ng-controller = "TipController">
<div class="slide">
<ul class="slideUl">
<!-- 指令 -->
<slide-follow id="slide" dataset-data = "datasetData"></slide-follow>
</ul>
</div>
</div>
</body>

當(dāng)然我們的代碼都是基于頁面中已經(jīng)引入angular.js文件下來運行的
slide-follow是我們需要實現(xiàn)的指令 dataset-data = "datasetData" 是我們需要顯示的文字js代碼

<script type="text/javascript">
var app =angular.module("tip",[]);
app.controller("TipController",function($scope){
// 數(shù)據(jù)可以根據(jù)自己使用情況更換
$scope.datasetData = [
{option : "這個是第一條數(shù)據(jù)"},
{option : "這個是第二條數(shù)據(jù)"},
{option : "這個是第三條數(shù)據(jù)"},
{option : "這個是第四條數(shù)據(jù)"},
{option : "這個是第五條數(shù)據(jù)"},
{option : "這個是第六條數(shù)據(jù)"}
]
})
.directive("slideFollow",function($timeout){
return {
restrict : 'E',
replace : true,
scope : {
id : "@",
datasetData : "="
},
template : "<li ng-repeat = 'data in datasetData'>{{data.option}}</li>",
link : function(scope,elem,attrs) {
$timeout(function(){
var className = $("." + $(elem).parent()[0].className);
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,4000);
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,4000);
})
},0)
}
}
})
</script>

首先我們在controller中定義了需要顯示的文字,接下來我們就可以開始定義指令部分。

運行效果圖:

文字上下會無縫滾動,當(dāng)鼠標(biāo)移入是,會清除定時器,停止?jié)L動。

以上所述是小編給大家介紹的angularjs實現(xiàn)文字上下無縫滾動特效代碼,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!

相關(guān)文章

最新評論