본문 바로가기

꿈(개발)

한 줄로 스크롤링 되는 뉴스티커

#head에 들어가야 할 부분

<style type="text/css">
#pscroller1{
width: 200px;
height: 100px;
border: 1px solid black;
padding: 5px;
background-color: lightyellow;
}

#pscroller2{
width: 350px;
height: 20px;
border: 1px solid black;
padding: 3px;
}

#pscroller2 a{
text-decoration: none;
}

.someclass{ //class to apply to your scroller(s) if desired
}

</style>

<script type="text/javascript">
var pausecontent=new Array()
pausecontent[0]='여기에 스크롤링 될 글을 넣습니다.'
pausecontent[1]='여기에 스크롤링 될 글을 넣습니다.'
pausecontent[2]='여기에 스크롤링 될 글을 넣습니다.'
pausecontent[3]='여기에 스크롤링 될 글을 넣습니다.'
</script>

<script type="text/javascript">

/***********************************************
* Pausing up-down scroller- ⓒ Dynamic Drive (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for this script and 100s more.
***********************************************/

function pausescroller(content, divId, divClass, delay){
this.content=content //message array content
this.tickerid=divId //ID of ticker div to display information
this.delay=delay //Delay between msg change, in miliseconds.
this.mouseoverBol=0 //Boolean to indicate whether mouse is currently over scroller (and pause it if it is)
this.hiddendivpointer=1 //index of message array for hidden div
document.write('<div id="'+divId+'" class="'+divClass+'" style="position: relative; overflow: hidden"><div class="innerDiv" style="position: absolute; width: 100%" id="'+divId+'1">'+content[0]+'</div><div class="innerDiv" style="position: absolute; width: 100%; visibility: hidden" id="'+divId+'2">'+content[1]+'</div></div>')
var scrollerinstance=this
if (window.addEventListener) //run onload in DOM2 browsers
window.addEventListener("load", function(){scrollerinstance.initialize()}, false)
else if (window.attachEvent) //run onload in IE5.5+
window.attachEvent("onload", function(){scrollerinstance.initialize()})
else if (document.getElementById) //if legacy DOM browsers, just start scroller after 0.5 sec
setTimeout(function(){scrollerinstance.initialize()}, 500)
}

// -------------------------------------------------------------------
// initialize()- Initialize scroller method.
// -Get div objects, set initial positions, start up down animation
// -------------------------------------------------------------------

pausescroller.prototype.initialize=function(){
this.tickerdiv=document.getElementById(this.tickerid)
this.visiblediv=document.getElementById(this.tickerid+"1")
this.hiddendiv=document.getElementById(this.tickerid+"2")
this.visibledivtop=parseInt(pausescroller.getCSSpadding(this.tickerdiv))
//set width of inner DIVs to outer DIV's width minus padding (padding assumed to be top padding x 2)
this.visiblediv.style.width=this.hiddendiv.style.width=this.tickerdiv.offsetWidth-(this.visibledivtop*2)+"px"
this.getinline(this.visiblediv, this.hiddendiv)
this.hiddendiv.style.visibility="visible"
var scrollerinstance=this
document.getElementById(this.tickerid).onmouseover=function(){scrollerinstance.mouseoverBol=1}
document.getElementById(this.tickerid).onmouseout=function(){scrollerinstance.mouseoverBol=0}
if (window.attachEvent) //Clean up loose references in IE
window.attachEvent("onunload", function(){scrollerinstance.tickerdiv.onmouseover=scrollerinstance.tickerdiv.onmouseout=null})
setTimeout(function(){scrollerinstance.animateup()}, this.delay)
}


// -------------------------------------------------------------------
// animateup()- Move the two inner divs of the scroller up and in sync
// -------------------------------------------------------------------

pausescroller.prototype.animateup=function(){
var scrollerinstance=this
if (parseInt(this.hiddendiv.style.top)>(this.visibledivtop+5)){
this.visiblediv.style.top=parseInt(this.visiblediv.style.top)-5+"px"
this.hiddendiv.style.top=parseInt(this.hiddendiv.style.top)-5+"px"
setTimeout(function(){scrollerinstance.animateup()}, 50)
}
else{
this.getinline(this.hiddendiv, this.visiblediv)
this.swapdivs()
setTimeout(function(){scrollerinstance.setmessage()}, this.delay)
}
}

// -------------------------------------------------------------------
// swapdivs()- Swap between which is the visible and which is the hidden div
// -------------------------------------------------------------------

pausescroller.prototype.swapdivs=function(){
var tempcontainer=this.visiblediv
this.visiblediv=this.hiddendiv
this.hiddendiv=tempcontainer
}

pausescroller.prototype.getinline=function(div1, div2){
div1.style.top=this.visibledivtop+"px"
div2.style.top=Math.max(div1.parentNode.offsetHeight, div1.offsetHeight)+"px"
}

// -------------------------------------------------------------------
// setmessage()- Populate the hidden div with the next message before it's visible
// -------------------------------------------------------------------

pausescroller.prototype.setmessage=function(){
var scrollerinstance=this
if (this.mouseoverBol==1) //if mouse is currently over scoller, do nothing (pause it)
setTimeout(function(){scrollerinstance.setmessage()}, 100)
else{
var i=this.hiddendivpointer
var ceiling=this.content.length
this.hiddendivpointer=(i+1>ceiling-1)? 0 : i+1
this.hiddendiv.innerHTML=this.content[this.hiddendivpointer]
this.animateup()
}
}

pausescroller.getCSSpadding=function(tickerobj){ //get CSS padding value, if any
if (tickerobj.currentStyle)
return tickerobj.currentStyle["paddingTop"]
else if (window.getComputedStyle) //if DOM2
return window.getComputedStyle(tickerobj, "").getPropertyValue("padding-top")
else
return 0
}

</script>

body의 스크롤링 되어야 하는 부분

<script type="text/javascript">
new pausescroller(pausecontent, "pscroller1", "someclass", 3000)
</script>

이상 출처 - 블루비



<!-- 광고 : 한줄의 유혹 -->
            <div id="WelCont03">
              <style type="text/css">
#pscroller1{
width: 490px;
height: 22px;
padding-top:4px;
}
#pscroller1 a{
color:#4D4D4D;
font-weight:bold;
font-family:돋움;
}
.someclass{ //class to apply to your scroller(s) if desired
}
</style>
<script type="text/javascript">
var pausecontent=new Array()
</script>
<script type="text/javascript">
function pausescroller(content, divId, divClass, delay){
    this.content=content //message array content
    this.tickerid=divId //ID of ticker div to display information
    this.delay=delay //Delay between msg change, in miliseconds.
    this.mouseoverBol=0 //Boolean to indicate whether mouse is currently over scroller (and pause it if it is)
    this.hiddendivpointer=1 //index of message array for hidden div
    document.write('<div id="'+divId+'" class="'+divClass+'" style="position: relative; overflow: hidden"><div class="innerDiv" style="position: absolute; width: 100%" id="'+divId+'1">'+content[0]+'</div><div class="innerDiv" style="position: absolute; width: 100%; visibility: hidden" id="'+divId+'2">'+content[1]+'</div></div>')
    var scrollerinstance=this
    if (window.addEventListener) //run onload in DOM2 browsers
    window.addEventListener("load", function(){scrollerinstance.initialize()}, false)
    else if (window.attachEvent) //run onload in IE5.5+
    window.attachEvent("onload", function(){scrollerinstance.initialize()})
    else if (document.getElementById) //if legacy DOM browsers, just start scroller after 0.5 sec
    setTimeout(function(){scrollerinstance.initialize()}, 500)
}

pausescroller.prototype.initialize=function(){
    this.tickerdiv=document.getElementById(this.tickerid)
    this.visiblediv=document.getElementById(this.tickerid+"1")
    this.hiddendiv=document.getElementById(this.tickerid+"2")
    this.visibledivtop=parseInt(pausescroller.getCSSpadding(this.tickerdiv))
    //set width of inner DIVs to outer DIV's width minus padding (padding assumed to be top padding x 2)
    this.visiblediv.style.width=this.hiddendiv.style.width=this.tickerdiv.offsetWidth-(this.visibledivtop*2)+"px"
    this.getinline(this.visiblediv, this.hiddendiv)
    this.hiddendiv.style.visibility="visible"
    var scrollerinstance=this
    document.getElementById(this.tickerid).onmouseover=function(){scrollerinstance.mouseoverBol=1}
    document.getElementById(this.tickerid).onmouseout=function(){scrollerinstance.mouseoverBol=0}
    if (window.attachEvent) //Clean up loose references in IE
    window.attachEvent("onunload", function(){scrollerinstance.tickerdiv.onmouseover=scrollerinstance.tickerdiv.onmouseout=null})
    setTimeout(function(){scrollerinstance.animateup()}, this.delay)
}

pausescroller.prototype.animateup=function(){
    var scrollerinstance=this
    if (parseInt(this.hiddendiv.style.top)>(this.visibledivtop+5)){
        this.visiblediv.style.top=parseInt(this.visiblediv.style.top)-5+"px"
        this.hiddendiv.style.top=parseInt(this.hiddendiv.style.top)-5+"px"
        setTimeout(function(){scrollerinstance.animateup()}, 200)
    }else{
        this.getinline(this.hiddendiv, this.visiblediv)
        this.swapdivs()
        setTimeout(function(){scrollerinstance.setmessage()}, this.delay)
    }
}

pausescroller.prototype.swapdivs=function(){
    var tempcontainer=this.visiblediv
    this.visiblediv=this.hiddendiv
    this.hiddendiv=tempcontainer
}

pausescroller.prototype.getinline=function(div1, div2){
    div1.style.top=this.visibledivtop+"px"
    div2.style.top=Math.max(div1.parentNode.offsetHeight, div1.offsetHeight)+"px"
}


pausescroller.prototype.setmessage=function(){
    var scrollerinstance=this
    if (this.mouseoverBol==1) //if mouse is currently over scoller, do nothing (pause it)
        setTimeout(function(){scrollerinstance.setmessage()}, 100)
    else{
        var i=this.hiddendivpointer
        var ceiling=this.content.length
        this.hiddendivpointer=(i+1>ceiling-1)? 0 : i+1
        this.hiddendiv.innerHTML=this.content[this.hiddendivpointer]
        this.animateup()
    }

}

pausescroller.getCSSpadding=function(tickerobj){ //get CSS padding value, if any
    if (tickerobj.currentStyle)
        return tickerobj.currentStyle["paddingTop"]
    else if (window.getComputedStyle) //if DOM2
        return window.getComputedStyle(tickerobj, "").getPropertyValue("padding-top")
    else
        return 0
}
</script>

<script>
var pausecontent=new Array();
    pausecontent[0] = "<a href='http://www.kyobobook.co.kr/prom/2008/pube/01/080519_style.jsp?mallGb=KOR&orderClick=rga&clickPcode=5&clickAiCode=3468' onMouseOver='stop_5=true' onMouseOut='stop_5=false'><b>패션은 사라져도 스타일은 영원하다 - 코코 샤넬</b></a>";
        pausecontent[1] = "<a href='http://www.kyobobook.co.kr/product/detailViewKor.laf?ejkGb=KOR&barcode=9788974425036&orderClick=rga&clickPcode=5&clickAiCode=3728' onMouseOver='stop_5=true' onMouseOut='stop_5=false'><b>소득 10만 달러.......그게 웃겨???</b></a>";
        pausecontent[2] = "<a href='http://www.kyobobook.co.kr/product/detailViewKor.laf?ejkGb=KOR&barcode=9788901079288&orderClick=rga&clickPcode=5&clickAiCode=3741' onMouseOver='stop_5=true' onMouseOut='stop_5=false'><b>유재석보다 행복한 사춘기를 보낼 수 있다면?</b></a>";
        pausecontent[3] = "<a href='http://www.kyobobook.co.kr/product/detailViewKor.laf?ejkGb=KOR&barcode=9788960860995&orderClick=rga&clickPcode=5&clickAiCode=3973' onMouseOver='stop_5=true' onMouseOut='stop_5=false'><b>주식으로 엄청난 부를 거머쥔 슈퍼개미 50인의 핵심 기법과 실전 노하우!</b></a>";
        pausecontent[4] = "<a href='http://www.kyobobook.co.kr/product/detailViewKor.laf?ejkGb=KOR&barcode=9788936433635&orderClick=rga&clickPcode=5&clickAiCode=4041' onMouseOver='stop_5=true' onMouseOut='stop_5=false'><b><완득이> 단언컨대 올해 읽은 한국소설 중에서 최고다 - 중앙일보</b></a>";
        pausecontent[5] = "<a href='http://www.kyobobook.co.kr/product/detailViewKor.laf?ejkGb=KOR&barcode=9788962170030&orderClick=rga&clickPcode=5&clickAiCode=4065' onMouseOver='stop_5=true' onMouseOut='stop_5=false'><b>21세기의 주인공이 되고싶다면? 꿈꾀끼꼴깡</b></a>";
        pausecontent[6] = "<a href='http://www.kyobobook.co.kr/prom/2008/pube/01/080515_20tokyo.jsp?mallGb=KOR&orderClick=rga&clickPcode=5&clickAiCode=4088' onMouseOver='stop_5=true' onMouseOut='stop_5=false'><b>오쿠다 히데오는 중독이고 치유다!!!</b></a>";
        pausecontent[7] = "<a href='http://www.kyobobook.co.kr/product/detailViewKor.laf?ejkGb=KOR&barcode=9788990831521&orderClick=rga&clickPcode=5&clickAiCode=4097' onMouseOver='stop_5=true' onMouseOut='stop_5=false'><b>파워포인트에 목숨 거는 사람들, 이제 그만!</b></a>";
        pausecontent[8] = "<a href='http://www.kyobobook.co.kr/product/detailViewKor.laf?ejkGb=KOR&barcode=9788935702992&orderClick=rga&clickPcode=5&clickAiCode=4104' onMouseOver='stop_5=true' onMouseOut='stop_5=false'><b>깨어서 꿈꾸는 삶 - 당신은 사람이 된 놀이를 하고 있는 무한가능성입니다</b></a>";
    </script>


<!-- 한줄의 유혹 시작 -->
<table width="570" border="0" cellpadding="0" cellspacing="0" bgcolor="#F0F0F0">
  <tr>
    <td width="6"></td>
    <td height="27" style="font-size:9pt; padding-top:6px" background="http://image.kyobobook.co.kr/newimages/apps/b2c/welcome/new/todayChoice_bottom.gif">
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td width="26" height="22" align="right"><img src="http://image.kyobobook.co.kr/newimages/apps/b2c/common/i_BltArrw_Grey02.gif" align="absmiddle" /></td>
          <td width="532"><script type="text/javascript">

new pausescroller(pausecontent, "pscroller1", "someclass", 3000)

</script>          </td>
        </tr>
    </table></td>
    <td width="6"></td>
  </tr>
  <tr>
    <td height="6"></td>
    <td height="6"></td>
    <td height="6"></td>
  </tr>
</table>
<!-- 한줄의 유혹 끝 -->



            </div>

이상 출처 - 교보문고


뉴스티커 그냥 갖다 붙여서 뉴스나 보는 건줄 알았는데  쓸모가 있었다!!!!!!!
그리고 교보문고에서도 이런 활용!!!!!!!!!

스크립트는 어렵다 어려워
여기 보이는 프로토타입은 내가 아는 그 프로토타입이 맞는걸까?????

내가 썼던 스크롤링과 훨씬 다른 스크롤링!!!!!!!

소스량도 훨씬 많은 만큼 더 부드럽게 자연스럽게 스크롤링 되어서 더 좋은것 같다!!!!

많이 배워야겠습니다. 고맙습니다^^