jQuery 기반 공고 무한 순환 스크롤 실현 코드

온라인 데모:http://demo.jb51.net/js/2012/callboard/
jQuery 코드
 
  
// :Newton
(function (win){
var callboarTimer;
var callboard = $('#callboard');
var callboardUl = callboard.find('ul');
var callboardLi = callboard.find('li');
var liLen = callboard.find('li').length;
var initHeight = callboardLi.first().outerHeight(true);
win.autoAnimation = function (){
if (liLen <= 1) return;
var self = arguments.callee;
var callboardLiFirst = callboard.find('li').first();
callboardLiFirst.animate({
marginTop:-initHeight
}, 500, function (){
clearTimeout(callboarTimer);
callboardLiFirst.appendTo(callboardUl).css({marginTop:0});
callboarTimer = setTimeout(self, 5000);
});
}
callboard.mouseenter(
function (){
clearTimeout(callboarTimer);
}).mouseleave(function (){
callboarTimer = setTimeout(win.autoAnimation, 5000);
});
}(window));
setTimeout(window.autoAnimation, 5000);

HTML 코드:
 
  

CSS :( )

#callboard { height:24px; line-height:24px; overflow:hidden;}
#callboard ul { padding:0;}
#callboard li { padding:0;}
















<br>(function (win){ <br>var callboarTimer; <br>var callboard = $('#callboard'); <br>var callboardUl = callboard.find('ul'); <br>var callboardLi = callboard.find('li'); <br>var liLen = callboard.find('li').length; <br>var initHeight = callboardLi.first().outerHeight(true); <br>win.autoAnimation = function (){ <br>if (liLen <= 1) return; <br>var self = arguments.callee; <br>var callboardLiFirst = callboard.find('li').first(); <br>callboardLiFirst.animate({ <br>marginTop:-initHeight <br>}, 500, function (){ <br>clearTimeout(callboarTimer); <br>callboardLiFirst.appendTo(callboardUl).css({marginTop:0}); <br>callboarTimer = setTimeout(self, 5000); <br>}); <br>} <br>callboard.mouseenter( <br>function (){ <br>clearTimeout(callboarTimer); <br>}).mouseleave(function (){ <br>callboarTimer = setTimeout(win.autoAnimation, 5000); <br>}); <br>}(window)); <br>setTimeout(window.autoAnimation, 5000); <br>


좋은 웹페이지 즐겨찾기