fidgen
04-20-2005, 01:46 PM
Hiya,
You'll have to excuse me, I'm just learning javascript and this is really bugging me now!
I have a newscroller.js which contains amongst lots of other stuff the following:
function NewsScroller ()
{
if (window.NewsScrollerInstance != null)
{
window.alert("Only one NewsScroller control is allowed on a page.");
return;
}
window.NewsScrollerInstance = this;
this.LoadXML = NewsScroller_LoadXML;
this.AddNewsItem = NewsScroller_AddNewsItem;
this.Clear = NewsScroller_Clear;
this.StartScrolling = NewsScroller_StartScrolling;
this.StopScrolling = NewsScroller_StopScrolling;
this.Render = NewsScroller_Render;
As you can see it defines NewsScroller_StartScrolling and NewsScroller_StopScrolling, which are the 2 lines I have to show you before I continue.
Both of those are scripted like this:
function NewsScroller_StartScrolling ()
{
if (this.itemCount > 0)
{
var sControlName = this.renderedControl;
if (sControlName == null)
{
window.alert ("You must render a control before you can start scrolling it.");
return;
}
var elmControl = document.getElementById(sControlName);
var elmItem0 = document.getElementById("floatingNews0");
if (this.itemCount > 1)
{
var elmItem1 = document.getElementById(sControlName + "1");
this.cySeparator = (elmItem1.offsetTop - elmItem0.offsetTop) - elmItem0.offsetHeight;
}
else
{
this.cySeparator = 0;
}
if (this.ScrollTimerID == null)
this.ScrollTimerID = window.setInterval(NewsScroller_ScrollNews, this.scrollRate);
}
}
function NewsScroller_StopScrolling ()
{
window.clearInterval(this.ScrollTimerID);
this.ScrollTimerID = null;
}
Now.. the problem i have is with my HTML page where I call this scroller applet. What happens now is that the whole thing scrolls all the way through without stopping. What I want is for onMouseOver to call the eventhandler "StopScrolling" and then on mouseout for it to null that by calling "startscrolling"
My HTML code is this:
<script type="text/javascript">
var scrollerMain = new NewsScroller("main");
</script>
<xml id="xmlNews" src="xmlNews.xml"></xml>
<div style="float: right; width: 200px; height: 250px;">
<script type="text/javascript">
scrollerMain.Render("floatingNews");
scrollerMain.LoadXML('xmlNews');
scrollerMain.StartScrolling ();
scrollerMain.onMouseOver = (StopScrolling);
scrollerMain.onMouseOut = (StartScrolling);
</script>
</div>
As you can see I've tried to stick the onMouseOver etc in there but I blatently dont know how to work it.
Here is the helpful FAQ that came with this, taken from this page
http://www.sharepointcustomization.com/resources/codesamples/NewsScroller/default.htm
Pause when hovering
For this feature, you do not need to change the newsscroller.js script at all. In your page, after calling the Render method of the NewsScroller object, attach onmouseover and onmouseout event handlers to the element that contains your rendered NewsScroller object. In the handler for the onmouseover event, call the StopScrolling method, and in the handler for the onmouseout event, call the StartScrolling method.
Sorry to make this a long post but I thought it was better to explain things clearly rather than just dump code on you and expect a quick answer.
Thanks
Hugh
You'll have to excuse me, I'm just learning javascript and this is really bugging me now!
I have a newscroller.js which contains amongst lots of other stuff the following:
function NewsScroller ()
{
if (window.NewsScrollerInstance != null)
{
window.alert("Only one NewsScroller control is allowed on a page.");
return;
}
window.NewsScrollerInstance = this;
this.LoadXML = NewsScroller_LoadXML;
this.AddNewsItem = NewsScroller_AddNewsItem;
this.Clear = NewsScroller_Clear;
this.StartScrolling = NewsScroller_StartScrolling;
this.StopScrolling = NewsScroller_StopScrolling;
this.Render = NewsScroller_Render;
As you can see it defines NewsScroller_StartScrolling and NewsScroller_StopScrolling, which are the 2 lines I have to show you before I continue.
Both of those are scripted like this:
function NewsScroller_StartScrolling ()
{
if (this.itemCount > 0)
{
var sControlName = this.renderedControl;
if (sControlName == null)
{
window.alert ("You must render a control before you can start scrolling it.");
return;
}
var elmControl = document.getElementById(sControlName);
var elmItem0 = document.getElementById("floatingNews0");
if (this.itemCount > 1)
{
var elmItem1 = document.getElementById(sControlName + "1");
this.cySeparator = (elmItem1.offsetTop - elmItem0.offsetTop) - elmItem0.offsetHeight;
}
else
{
this.cySeparator = 0;
}
if (this.ScrollTimerID == null)
this.ScrollTimerID = window.setInterval(NewsScroller_ScrollNews, this.scrollRate);
}
}
function NewsScroller_StopScrolling ()
{
window.clearInterval(this.ScrollTimerID);
this.ScrollTimerID = null;
}
Now.. the problem i have is with my HTML page where I call this scroller applet. What happens now is that the whole thing scrolls all the way through without stopping. What I want is for onMouseOver to call the eventhandler "StopScrolling" and then on mouseout for it to null that by calling "startscrolling"
My HTML code is this:
<script type="text/javascript">
var scrollerMain = new NewsScroller("main");
</script>
<xml id="xmlNews" src="xmlNews.xml"></xml>
<div style="float: right; width: 200px; height: 250px;">
<script type="text/javascript">
scrollerMain.Render("floatingNews");
scrollerMain.LoadXML('xmlNews');
scrollerMain.StartScrolling ();
scrollerMain.onMouseOver = (StopScrolling);
scrollerMain.onMouseOut = (StartScrolling);
</script>
</div>
As you can see I've tried to stick the onMouseOver etc in there but I blatently dont know how to work it.
Here is the helpful FAQ that came with this, taken from this page
http://www.sharepointcustomization.com/resources/codesamples/NewsScroller/default.htm
Pause when hovering
For this feature, you do not need to change the newsscroller.js script at all. In your page, after calling the Render method of the NewsScroller object, attach onmouseover and onmouseout event handlers to the element that contains your rendered NewsScroller object. In the handler for the onmouseover event, call the StopScrolling method, and in the handler for the onmouseout event, call the StartScrolling method.
Sorry to make this a long post but I thought it was better to explain things clearly rather than just dump code on you and expect a quick answer.
Thanks
Hugh