开发者

Possible to count # of specific div class within a div id?

开发者 https://www.devze.com 2023-03-10 00:03 出处:网络
Have the following script: var CurrentPageTop = 0; var PageHeight = 496; var TotalPages = 9; var CurrenPage = 1;

Have the following script:

    var CurrentPageTop = 0;
    var PageHeight = 496;
    var TotalPages = 9;
    var CurrenPage = 1;
    function Slide( control, panel ){



            if ( control.name == "SlideDown" ){

                    if ( (CurrenPage >= 1) && (CurrenPage <= TotalPages-1) ){
                            CurrenPage++;
                            CurrentPageTop =  ( CurrentPageTop - PageHeight );
                    }
            }

            if ( control.name == "SlideUp" ){

                    if ( (CurrenPage > 1) && (CurrenPage <= TotalPages) ){
                            CurrenPage--;
                            CurrentPageTop = (CurrentPageTop + PageHeight);
                    }
            }       

            var PanelScroller = document.getElementById(panel);
            PanelScroller.style.top = CurrentPageTop + 'px';

            var CurrenPageId = document.getElementById("CurrenPageId");
            CurrenPageId.innerHTML = "Page " + CurrenPage + " of 9";
    }

which accompanies a single image gallery on a page:

      <table cellpadding="0" cellspacing="0">
    <tr>
            <td>
                    <div class="SlidingPanel">
                            <div id="PanelScroller">
                                    <div class="Page">
         <a href="surf/1.jpg" rel="shadowbox[Surf]"><img src="i/gal/g1.jpg"></a>
          </div>

How would I set this up to have multiple instances on one page?

Some galleries have 9 images, some have 6, etc.

Is there a way to count the number of <div class="Page"> within a 开发者_如何学编程<div id="PanelScroller"> ?

I want to avoid having to use 3 slightly different instances of this script for 3 different galleries. I just can't wrap my head around it because I'm a novice.


function number_of_elements_with_class_name(class_name) {
    var elements = getElementsByClassName(class_name);
    var count = 0;
    for(var i in elements) {
        count++;
    }
    return count;
}


node.getElementsByClassName()

http://www.quirksmode.org/blog/archives/2008/05/getelementsbycl.html

0

精彩评论

暂无评论...
验证码 换一张
取 消