JavaScript based Scroller
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: JavaScript based Scroller

  1. #1
    Join Date
    Jan 2006
    Posts
    352

    Unhappy JavaScript based Scroller

    My JavaScript based Scroller don't work in Opera 9 Final!
    I know only PHP, mysql and xhtml with css. So can someone alter this code for me and test it?

    Thank you in advance!

    Code:
    <script type="text/JavaScript">
    <!--
    function MM_findObj(n, d) { //v4.01
    var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
    if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
    for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
    if(!x && d.getElementById) x=d.getElementById(n); return x;
    }
    
    function flevGetDivProperty() { // v1.0
    this.opera = (window.opera); this.ns4 = (document.layers); this.ie = (document.all);
    this.ns6 = (document.getElementById && !document.all && !this.opera);
    var sV = "", sD = arguments[0], oD = MM_findObj(sD), sP = arguments[1]; if (oD == null) {return 0;}
    var sF = (sD.indexOf("?") > 0) ? sD.substring(sD.indexOf("?")+1) : "";
    if ((sF != "") && (this.ie)) {sD = "parent.frames['" + sF + "']." + sD.substring(0,sD.indexOf("?"));}
    if ((sP == "left") || (sP == "top")) {
    if (!this.ns4) {oD = oD.style;} sV = eval("oD." + sP);
    if ((this.ie) && (sV == "")) { // IE (on PC) bug with nested layers
    if (sP == "top") { sV = eval(sD + ".offsetTop");}
    else { sV = eval(sD + ".offsetLeft");}}}
    else {if (this.opera) {oD = oD.style;
    if (sP == "height") { sV = oD.pixelHeight;}
    else if (sP == "width") { sV = oD.pixelWidth;}}
    else if (this.ns4) {sV = eval("oD.clip." + sP);}
    else if (this.ns6) {sV = document.defaultView.getComputedStyle(oD, "").getPropertyValue(sP);}
    else if (this.ie) {
    if (sP == "width") {sV = eval(sD + ".offsetWidth");}
    else if (sP == "height") {sV = eval(sD + ".offsetHeight");}}}
    sV = (sV == "") ? 0 : sV; if (isNaN(sV)) {if (sV.indexOf('px') > 0) { sV = sV.substring(0,sV.indexOf('px'));}}
    return parseInt(sV);
    }
    
    function flevMoveDiv(sD, sX, sY){ // v1.4
    var oD = MM_findObj(sD), sS=""; if (!oD) {return;}
    if (!document.layers) {oD = oD.style;} // not NS4.x
    if((parseInt(navigator.appVersion)>4 || navigator.userAgent.indexOf("MSIE")>-1) && (!window.opera)) {sS="px";}
    if (sX != "") {eval("oD.left = '" + sX + sS + "'");}
    if (sY != "") {eval("oD.top = '" + sY + sS + "'");}
    }
    
    function flevAutoScrollDivs() { // v1.2
    var aA = arguments, iA = aA.length, oD = MM_findObj('AutoScrollContainer'); if (!oD) {return;}
    if (oD.scrollTimeout != null) {clearTimeout(oD.scrollTimeout);}
    var sID1 = 'AutoScrollContainer', sID2 = 'AutoScrollContent';
    var iSS = (iA > 0) ? parseInt(aA[0]) : 1, iPx = (iA > 1) ? parseInt(aA[1]) : 1;
    var iMs = (iA > 2) ? parseInt(aA[2]) : 50;
    var iST = (-1 * flevGetDivProperty(sID2, 'height')), iSB = flevGetDivProperty(sID1, 'height');
    var iCX = flevGetDivProperty(sID2, 'left'), iCY = flevGetDivProperty(sID2, 'top');
    if (iSS) {if (iCY >= iST) {flevMoveDiv(sID2, String(iCX), String(iCY-iPx));} // Continue scrolling
    else {flevMoveDiv(sID2, String(iCX), String(iSB));} // Re-position scrolling layer at bottom of container
    oD.scrollTimeout = setTimeout("flevAutoScrollDivs(" + iSS + "," + iPx + "," + iMs + ")", iMs);}
    }
    //-->
    </script>

  2. #2
    Join Date
    Apr 2005
    Location
    Norway
    Posts
    3,934

    Re: JavaScript based Scroller

    You've only posted the javascript part - and it seems to reference other parts of the HTML document. If you post a complete page that works in IE etc, but not in Opera, then someone may be able to spot the bug.

    - petter

  3. #3
    Join Date
    Jan 2006
    Posts
    352

    Re: JavaScript based Scroller

    Well sorry, but I thought that code was most important here.
    It works in IE & FF. In opera it is shaking. It is actually 2 layers sistem, one scrolling beneath the other and giving the illusion of scrolling.

    I will post MISSING RELEVANT HTML and CSS here.

    HTML: It is all about these 2 layers: div id="AutoScrollContainer" & div id="AutoScrollContent"

    Code:
    <!-- Start absolute positioned Cross-browser AutoScroller -->
    <!-- Do NOT change these layer ID's -->
    <div id="AutoScrollContainer" onmouseover="flevAutoScrollDivs(0)" onmouseout="flevAutoScrollDivs(1,2,50)">
      <div id="AutoScrollContent">
    <p>CONTENT OF SCROLLING LAYER GOES HERE!!!</p>
       </div>
    </div>
    <!-- End absolute positioned Cross-browser AutoScroller -->
    </body>
    </html>
    And here is external CSS file linked to this html:

    Code:
    #AutoScrollContent {
    	position:absolute;
    	top:300px;
    	left:0px;
    	width:170px;
    	visibility:visible;
    	z-index: 8;
    }
    #AutoScrollContainer {
    	overflow: hidden;
    	position: absolute;
    	visibility: visible;
    	z-index: 7;
    	height: 475px;
    	width: 170px;
    	left: 730px;
    	top: 205px;
    }

  4. #4
    Join Date
    Jan 2006
    Posts
    352

    Re: JavaScript based Scroller

    Help... Anybody...,plz?!?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center