JS实现的marquee风格代码
用到的东西,记录下,回头用的时候方便~
网页调用部分
- <script type="text/javascript">initTicker(document.getElementById("list-pmarquee"));</script>
css部分
- #list-pmarquee{ position:relative; width:864px; height:58px; overflow:hidden; border: 2px solid #F0F0F0; margin-top:10px; }
- #list-pmarquee ul{ display:inline;}
- #list-pmarquee li{ display:inline; margin:5px 5px 0 0; float:left; width:150px;}
JS部分
- function initTicker(container) {
- mover = container.getElementsByTagName("ul").item(0);
- // set
- mover.style.position = "absolute";
- mover.style.margin = "0 0 0 0";
- mover.style.left = "0px";
- mover.leftPosition = 0;
- // duplicate text
- mover.style.width = 300 * 3 * 2 + "px";
- mover.innerHTML += mover.innerHTML;
- // set action
- mover.tickerAction = window.setInterval(
- function()
- {
- if (mover.leftPosition * -1 > (300 * 3)) {
- mover.leftPosition = -1;
- } else {
- mover.leftPosition -= 1;
- }
- mover.style.left = mover.leftPosition + "px";
- }
- , 30);
- }



