| <! DOCTYPE html> <! -- [If lt IE 7]> <! -- [If IE 7]> <! -- [If IE 8]> <! -- [If IE 9]> <! -- [If (gt IE 9) |! (IE)]> <! --> <Html lang = "zh-CN"> <! -- <! [Endif] --> <Head> <Title> text scrolling </title> <Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/> <Style type = "text/css"> * {Margin: 0; padding: 0 ;} Body {padding: 20px ;} . Textbox {border: 1px solid # ddd; width: auto; overflow: hidden ;} . Textbox ul {list-style: none; position: relative ;} . Textbox ul li {padding: 5px 0 ;} </Style> </Head> <Body class = "home-page"> <Div id = "textbox" class = "textbox"> <Ul> <Li> automobile | Sports Class B cars drop by 30 thousand 5 </li> <Li> Home | a woman with such great decoration really cannot sit down </li> <Li> Education | RMB 0.1 million/person for the China (Shanghai) University of California (Shanghai) </li> <Li> automobile | Sports Class B cars drop by 30 thousand 5 parallel imported cars increase by 0.11 million </li> <Li> healthy | 14-year-old boy suffering from Hormone Abuse cannot grow for 10 years </li> <Li> digital | what is the latest mobile phone price to say about the acceleration of broadband fee reduction? </Li> <Li> auto | additional price of parallel imported vehicles: 0.11 million </li> <Li> automobile | Sports Class B cars drop by 30 thousand 5 </li> <Li> auto | additional price of parallel imported vehicles: 0.11 million </li> <Li> sports | Evergrande AFC Champions League wins genuine jerseys by guessing scores </li> </Ul> <A href = "#" class = "btnPrev"> left </a> <A href = "#" class = "btnNext"> right </a> </Div> <Br> <Br> <Div id = "textbox2" class = "textbox"> <Ul> <Li> automobile | Sports Class B cars drop by 30 thousand 5 </li> <Li> Home | a woman with such great decoration really cannot sit down </li> <Li> Education | RMB 0.1 million/person for the China (Shanghai) University of California (Shanghai) </li> <Li> automobile | Sports Class B cars drop by 30 thousand 5 parallel imported cars increase by 0.11 million </li> <Li> healthy | 14-year-old boy suffering from Hormone Abuse cannot grow for 10 years </li> <Li> digital | what is the latest mobile phone price to say about the acceleration of broadband fee reduction? </Li> <Li> auto | additional price of parallel imported vehicles: 0.11 million </li> <Li> automobile | Sports Class B cars drop by 30 thousand 5 </li> <Li> auto | additional price of parallel imported vehicles: 0.11 million </li> <Li> sports | Evergrande AFC Champions League wins genuine jerseys by guessing scores </li> </Ul> <A href = "#" class = "btnPrev"> up </a> <A href = "#" class = "btnNext"> down </a> </Div> <Script type = "text/javascript" src = "scripts/jquery-1.11.1.min.js"> </script> <Script type = "text/javascript"> // Scrolled seamlessly from the left-side Navigation Pane Scroll ('# textbox', {vis: 2, btnHidden: false, dir: 'prev', type: 'H '}); Scroll ('# textbox2', {vis: 3, btnHidden: false, dir: 'prev', type: 'V '}); Function scroll (container, options ){ Var box = $ (container ); Var boxUl = box. find ('ul '). eq (0 ); Var LiHeight = 0; // The height of the cloned li list is not included. Var cloneLiHeight = 0; // contain the height of the cloned li list Var LiWidth = 0; // The width of the cloned li list is not included. Var cloneLiWidth = 0; // contains the width of the cloned li list Var Lis = boxUl. children (); Var btnPrev = box. find ('. btnprev '); Var btnNext = box. find ('. btnNext '); // Default parameter Var defult = { Vis: 2, // display number AutoPlay: true, // automatic playback Speed: 50, // scroll speed Dir: 'prev', // scroll direction BtnHidden: false, // whether the button is hidden Type: 'V' // horizontal or vertical }; Var opt = $. extend ({}, defult, options ); // Construct the DOM Structure Var lastClone = 0; // The last cloned Element Var lastCloneHeight = 0; // The height of the last cloned Element Var allCloneHeight = 0; // total height of all cloned Elements Var lastCloneWidth = 0; Var allCloneWidth = 0; Var visHeight = 0; // visible height Var visWidth = 0; Var boxUl_wrap; If (opt. type = "v") {// vertical direction Lis. each (function (){ $ (This). height ($ (this). height ()); LiHeight + = $ (this). outerHeight (true ); }); LastClone = boxUl. children (': last'). clone (). addClass ('clone'). prependTo (boxUl ); LastCloneHeight = lastClone. outerHeight (true ); AllCloneHeight = lastClone. outerHeight (true ); For (var I = 0; I <opt. vis; I ++ ){ Lis. eq (I). clone (). addClass ('clone '). appendTo (boxUl ); AllCloneHeight + = Lis. eq (I). outerHeight (true ); } VisHeight = allCloneHeight-lastCloneHeight; CloneLiHeight = LiHeight + allCloneHeight; BoxUl_wrap = $ ('<div> </div> 'privacy .css ({'width': '000000', 'height': visHeight, 'overflow': 'hidd ', 'position': 'relative '}). attr ('id', 'ulwre '); BoxUl.css ({'height': cloneLiHeight, 'top':-lastCloneHeight}). wrap (boxUl_wrap ); } Else if (opt. type = "h") {// horizontal direction Lis.css ({'white': 'nowre', 'float': 'left', 'paddingright': '10px '}); Lis. each (function (){ $ (This). width ($ (this). width ()); LiWidth + = $ (this). outerWidth (true ); }); LastClone = boxUl. children (': last'). clone (). addClass ('clone'). prependTo (boxUl ); LastCloneWidth = lastClone. outerWidth (true ); AllCloneWidth = lastClone. outerWidth (true ); For (var j = 0; j <opt. vis; j ++ ){ Lis. eq (j). clone (). addClass ('clone '). appendTo (boxUl ); AllCloneWidth + = Lis. eq (j). outerWidth (true ); } VisHeight = Lis. eq (0). outerHeight (true ); VisWidth = allCloneWidth-lastCloneWidth; CloneLiWidth = LiWidth + allCloneWidth; BoxUl_wrap = $ ('<div> </div> 'privacy .css ({'width': visWidth, 'height': visHeight, 'overflow': 'hidd', 'position ': 'relative '}). attr ('id', 'ulwre '); BoxUl.css ({'width': cloneLiWidth, 'left':-lastCloneWidth}). wrap (boxUl_wrap ); Box.css ({'width': visWidth }); } // Add event processing Var timer = null; Var scrollTop = function (){ ClearInterval (timer ); Timer = setInterval (function (){ Var tmp = parseInt(boxUl.css ('top'). replace ('px ',"")); Tmp --; BoxUl. animate ({'top': tmp}, 0, function (){ If (tmp <=-(LiHeight + lastCloneHeight )){ BoxUl.css ('top',-lastCloneHeight ); } }); }, Opt. speed ); }; Var scrollDown = function (){ ClearInterval (timer ); Timer = setInterval (function (){ Var tmp = parseInt(boxUl.css ('top'). replace ('px ',"")); Tmp ++; BoxUl. animate ({'top': tmp}, 0, function (){ If (tmp> = 0 ){ BoxUl.css ('top',-(LiHeight )); } }); }, Opt. speed ); }; Var scrollLeft = function (){ ClearInterval (timer ); Timer = setInterval (function (){ Var tmp = parseInt(boxUl.css ('left'). replace ('px ',"")); Tmp --; BoxUl. animate ({'left': tmp}, 0, function (){ If (tmp <=-(LiWidth + lastCloneWidth )){ BoxUl.css ('left',-(lastCloneWidth )); } }); }, Opt. speed ); }; Var scrollRight = function (){ ClearInterval (timer ); Timer = setInterval (function (){ Var tmp = parseInt(boxUl.css ('left'). replace ('px ',"")); Tmp ++; BoxUl. animate ({'left': tmp}, 0, function (){ If (tmp> = 0 ){ BoxUl.css ('left',-(LiWidth )); } }); }, Opt. speed ); }; Var scrollType = function (type, dir ){ If (Lis. length> = opt. vis) {// The number of displays cannot exceed the number of lists; otherwise, the results are not displayed. Var sdir = typeof dir! = "Undefined "? Dir: opt. dir; Switch (type ){ Case "v ": If (sdir = "prev") {scrollTop () ;}else {scrollDown ();} Break; Case "h ": If (sdir = "prev") {scrollLeft () ;}else {scrollRight ();} } } }; If (opt. autoPlay ){ ScrollType (opt. type ); } // Add event processing Box. find ('# ulWrap'). hover (function (){ ClearInterval (timer ); }, Function (){ ScrollType (opt. type ); }); // Hide the button If (! Opt. btnHidden ){ BtnPrev. unbind ('mouseover '); BtnNext. unbind ('mouseover '); BtnPrev. mouseover (function (){ ScrollType (opt. type, "prev "); }); BtnNext. mouseover (function (){ ScrollType (opt. type, "next "); }); } Else { BtnPrev. hide (); BtnNext. hide (); } } </Script> </Body> </Html> |