Newsticker / scroller (c#)
WizzKidd | Posted 6:07pm 17. October 2007 Server Time |
Hey guys,
Do any of you happen to have bumped into some code that does scrolling text like a news ticker? vertically (eg. bottom scrolling to the top)?
I'm looking for a ticker code (most likely some DHTML methods unless it can be done purley in c#?). I've particularly after just a few preferences such as being able to view 4 articles on the screen at once before it scrolls, which also means that i dont want it to continueously scroll, i'd like it to pause when an article got to the top.
I've seen various code all over the place, but none of which can cater for my simple needs? So here I am asking you guys if you can help?
My aim will be to use it in a .net page and generate the content from a backend, so in an ideal world, if you find a user control that can do all this, i owe ya a keg'o'beer!
- WizzKidd |
cbgis | Posted 9:40am 25. October 2007 Server Time |
Here is some java script that I found. It can be set up to pause, but I am not sure about the 4 articles. Maybe set up 4 instances of it.
this is the newsticker.js
// NewsTicker Object
// an animated news ticker
// 19990623
// Copyright (C) 1999 Dan Steinman
// Distributed under the terms of the GNU Library General Public License
// Available at http://www.dansteinman.com/dynapi/
function NewsTicker(x,y,width,height) {
this.name = 'NewsTicker'+(NewsTicker.count++)
this.x = x
this.y = y
this.w = width
this.h = height
this.obj = this.name + "Object"
eval(this.obj + "=this")
this.items = new Array()
this.scrollCount = 0
this.pauseLength = 5000
this.inc = 2
this.speed = 2
this.fromX = 0
this.fromY = this.h
this.bgColor = null
this.addItem = NewsTickerAddItem
this.activate = NewsTickerActivate
this.build = NewsTickerBuild
this.start = NewsTickerStart
this.stop = NewsTickerStop
this.slide = NewsTickerSlide
}
function NewsTickerAddItem(text) {
var i = this.items.length
this.items[i] = new Object()
this.items[i].text = text
}
function NewsTickerBuild() {
this.css = css(this.name,this.x,this.y,this.w,this.h)
this.div = '<div id="'+this.name+'">'
for (var i=0;i<this.items.length;i++) {
this.css += css(this.name+'Item'+i,0,0,this.w,this.h,this.bgColor,'hidden')
this.div += '<div id="'+this.name+'Item'+i+'">'+this.items[i].text+'</div>'
}
this.div += '</div>'
}
function NewsTickerActivate(autostart) {
for (var i=0;i<this.items.length;i++) {
this.items[i].lyr = new DynLayer(this.name+'Item'+i)
this.items[i].lyr.moveTo(this.fromX,this.fromY)
this.items[i].lyr.show()
}
this.items[0].lyr.moveTo(0,0)
this.lyr = new DynLayer(this.name)
var num = Math.sqrt(Math.pow(this.fromX,2) + Math.pow(this.fromY,2))/this.inc
this.dx = this.fromX/num || 0
this.dy = this.fromY/num || 0
if (autostart!=false) setTimeout(this.obj+'.start()',this.pauseLength)
}
function NewsTickerStart() {
if (!this.started) {
this.started = true
var t = this.scrollCount
var b = (this.scrollCount==this.items.length-1)? 0 : this.scrollCount+1
var obj1 = this.items[t].lyr.obj
var obj2 = this.items[b].lyr.obj
this.timer = setInterval(this.obj+'.slide('+obj1+','+obj2+')',this.speed)
}
}
function NewsTickerStop() {
clearInterval(this.timer)
this.started = false
}
function NewsTickerSlide(obj1,obj2) {
obj1.moveBy(-this.dx,-this.dy)
obj2.moveBy(-this.dx,-this.dy)
if ((this.dx!=0 && Math.floor(obj2.x)==0) || (this.dy!=0 && Math.floor(obj2.y)==0)) {
clearInterval(this.timer)
obj1.moveTo(this.fromX,this.fromY)
obj2.moveTo(0,0)
this.scrollCount = (this.scrollCount==this.items.length-1)? 0 : this.scrollCount+1
this.timer = setTimeout(this.obj+'.started=false;'+this.obj+'.start()',this.pauseLength)
}
}
NewsTicker.count = 0
This is what I put on my page.
<script lanuage="JavaScript" src="js/newsticker.js"></script>
<script lanuage="JavaScript">
<!--
onload = init
function init() {
ticker.activate()
}
var i0 = 'Place your ticker message here'
var i1 = 'Place your ticker message here'
ticker = new NewsTicker(500,220,250,100)
ticker.addItem(i0)
ticker.addItem(i1)
ticker.build()
writeCSS(
ticker.css
)
<script language="JavaScript">
document.write(ticker.div)
</script>
I hope that helps
Chris
Reply to Post Newsticker / scroller (c#)
|
|
|