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

angularjs實(shí)現(xiàn)文字上下無(wú)縫滾動(dòng)特效代碼

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

最近沒(méi)有項(xiàng)目做,于是閑暇之余學(xué)習(xí)了下angularjs知識(shí),然后寫(xiě)了一個(gè)文字上下無(wú)縫滾動(dòng)的例子,主要寫(xiě)的是一個(gè)小小的指令。

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)然我們的代碼都是基于頁(yè)面中已經(jīng)引入angular.js文件下來(lái)運(yùn)行的
slide-follow是我們需要實(shí)現(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 : "這個(gè)是第一條數(shù)據(jù)"},
{option : "這個(gè)是第二條數(shù)據(jù)"},
{option : "這個(gè)是第三條數(shù)據(jù)"},
{option : "這個(gè)是第四條數(shù)據(jù)"},
{option : "這個(gè)是第五條數(shù)據(jù)"},
{option : "這個(gè)是第六條數(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());
// 開(kāi)啟定時(shí)器
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");
}
}
// 清除定時(shí)器
className.hover(function(){
clearInterval(sh);
},function(){
clearInterval(sh);
sh = setInterval(slide,4000);
})
},0)
}
}
})
</script>

首先我們?cè)赾ontroller中定義了需要顯示的文字,接下來(lái)我們就可以開(kāi)始定義指令部分。

運(yùn)行效果圖:

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

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

相關(guān)文章

最新評(píng)論