angularjs實(shí)現(xiàn)文字上下無(wú)縫滾動(dòng)特效代碼
最近沒(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)文章
BootStrap+Angularjs+NgDialog實(shí)現(xiàn)模式對(duì)話框
在完成一個(gè)后臺(tái)管理系統(tǒng)時(shí),需要用表格顯示注冊(cè)用戶的信息。但是用戶地址太長(zhǎng)了,不好顯示。所以想做一個(gè)模式對(duì)話框,點(diǎn)擊詳細(xì)地址按鈕時(shí),彈出對(duì)話框,顯示地址。下面小編給大家分享下實(shí)現(xiàn)方法,一起看下吧2016-08-08AngularJS 模型詳細(xì)介紹及實(shí)例代碼
本文主要介紹 AngularJS模型,這里詳細(xì)介紹了AngularJS 模型中的知識(shí)點(diǎn),并提供實(shí)例代碼,有需要的小伙伴可以參考下2016-07-07AngularJS創(chuàng)建一個(gè)上傳照片的指令實(shí)例代碼
這篇文章主要介紹了AngularJS創(chuàng)建一個(gè)上傳照片的指令實(shí)例代碼,需要的朋友可以參考下2018-02-02利用VS Code開(kāi)發(fā)你的第一個(gè)AngularJS 2應(yīng)用程序
這篇文章主要給大家介紹了關(guān)于利用VS Code如何開(kāi)發(fā)你的第一個(gè)AngularJS 2應(yīng)用程序的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友下面來(lái)一起看看吧。2017-12-12快速解決angularJS中用post方法時(shí)后臺(tái)拿不到值的問(wèn)題
今天小編就為大家分享一篇快速解決angularJS中用post方法時(shí)后臺(tái)拿不到值的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-08-08AngularJs學(xué)習(xí)第八篇 過(guò)濾器filter創(chuàng)建
這篇文章主要介紹了AngularJs學(xué)習(xí)第八篇 過(guò)濾器filter創(chuàng)建的相關(guān)資料,非常不錯(cuò)具有參考借鑒價(jià)值,需要的朋友可以參考下2016-06-06Angular中自定義Debounce Click指令防止重復(fù)點(diǎn)擊
本篇文章主要介紹了Angular中自定義Debounce Click指令詳解,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-07-07angularJS與bootstrap結(jié)合實(shí)現(xiàn)動(dòng)態(tài)加載彈出提示內(nèi)容
這篇文章主要介紹了angularJS與bootstrap結(jié)合實(shí)現(xiàn)動(dòng)態(tài)加載彈出提示內(nèi)容,通過(guò)bootstrp彈出提示。感興趣的朋友可以參考下本篇文章2015-10-10angularjs實(shí)現(xiàn)首頁(yè)輪播圖效果
這篇文章主要為大家詳細(xì)介紹了angularjs實(shí)現(xiàn)首頁(yè)輪播圖效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-04-04