Page Count

0

I am trying to make a page counting system, which counts the total number of pages and which page the user is in.

I was able to do the total page count but I can not find a way to show the current page of it, I tried to use the position () method but I could not.

var arrMenuInterno = [
{ titulo: "Introdução",
    telas: [
        {arquivo: "ambev_VPO_gente_sld002.swf", tipo:""},
        {arquivo: "ambev_VPO_gente_sld005.swf", tipo:""},
        {arquivo: "ambev_VPO_gente_sld007.swf", tipo:""},
        {arquivo: "ambev_VPO_gente_sld009.swf", tipo:""},
        {arquivo: "ambev_VPO_gente_sld010.swf", tipo:""}

    ]
}

];

for(var i = 0;i < arrMenuInterno.length;i++){
            _totalTelas = arrMenuInterno[i].telas.length;

        }

        $("#qtdTelas").html(+ localizaTelaAtual + "</b> de <b>" + _totalTelas + "</b>");
    
asked by anonymous 21.12.2017 / 13:44

1 answer

1

You can use the HTML5 Date attribute to store the indexes of your page array. Here is an example implementation.

var arrMenuInterno = [
{ titulo: "Introdução",
    telas: [
        {arquivo: "ambev_VPO_gente_sld002.swf", tipo:""},
        {arquivo: "ambev_VPO_gente_sld005.swf", tipo:""},
        {arquivo: "ambev_VPO_gente_sld007.swf", tipo:""},
        {arquivo: "ambev_VPO_gente_sld009.swf", tipo:""},
        {arquivo: "ambev_VPO_gente_sld010.swf", tipo:""}
    ]
}]
 
function getNextContent(){
  var $conteudo = $("#conteudo");
  var titleIndex = $conteudo.data("titleIndex");
  var fileIndex = $conteudo.data("fileIndex") + 1;
  var content = arrMenuInterno[titleIndex].telas[fileIndex];
  var countDescription = " [" + fileIndex + " de " + arrMenuInterno[titleIndex].telas.length + "]";

  if (content !== undefined){
  	$conteudo.data("fileIndex", fileIndex);
  	var $span = $("<span></span>");
  	$span.append(content.arquivo + countDescription);
  	$("#conteudo").html($span);
  }
}

function getPreviousContent(){
  var $conteudo = $("#conteudo");
  var titleIndex = $conteudo.data("titleIndex");
  var fileIndex = $conteudo.data("fileIndex")  - 1;
  var content = arrMenuInterno[titleIndex].telas[fileIndex];
  var countDescription = " [" + fileIndex + " de " + arrMenuInterno[titleIndex].telas.length + "]";

  if (content !== undefined){
  	$conteudo.data("fileIndex", fileIndex);
  	var $span = $("<span></span>");
  	$span.append(content.arquivo + countDescription);
  	$("#conteudo").html($span);
  }
}
 
.content {
  width: 100%;
  background-color: black;
  vertical-align: middle;
}

#conteudo {
  display: table-cell;
  height: 150px;
}

span {
  color: #fff;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><div><divclass="content">
<div id="conteudo" data-title-index="0" data-file-index="0">
   <span>Introdução</span>
</div>
</div>

<a type="button" href="#" id="anterior" onclick="getPreviousContent()">Anterior</a>
<a type="button" href="#" id="proximo" onclick="getNextContent()">Próximo</a>
</div>
    
21.12.2017 / 14:19