Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7787403
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:39:22+00:00 2026-06-01T20:39:22+00:00

I am building a horizontal and vertical scroller for a website I am currently

  • 0

I am building a horizontal and vertical scroller for a website I am currently developing. The vertical one is working great, with no problems, and I have also managed to incorporate jQuery to control it’s animation.
The problem lies in the horizontal scroller. To control it I need one important data: the total length of the div#news1 content (to use in the comp variable in function mexer). However the browser only returns me the clientHeight, which is the same as it’s container (div#cont1). I need this to be generated automatically and properly by the browser because my website will have dynamic data inserted into it (PHP).
Why does this happen? What I am doing wrong? How can I fix it?

Here is the code for the test file:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script src="JS/jquery-1.7.2.min.js"></script>
<style type="text/css">

.container {
    width:250px;
    height:250px;
    overflow:hidden;
    float:left;
    border:3px solid #666;
}

.container1 {
    width:400px;
    height:125px;
    overflow:hidden;
    border:3px solid #666;
}
.botao {
    border:3px solid #666;
    background-color:#CCC;
    padding:3px 3px 3px 3px;
    color:#FFFFFF;
    font-family:Arial, Helvetica, sans-serif;
    cursor:pointer;
}
</style>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Untitled Document</title>
</head>

<body>
<div class="container" id="cont">
<div id="news" style="position:relative">
<p><img src="a6.jpg" height="125" width="250" /></p>
<p><img src="a6.jpg" height="125" width="250" /></p>
<p><img src="a6.jpg" height="125" width="250" /></p>
<p><img src="a6.jpg" height="125" width="250" /></p>
<p><img src="a6.jpg" height="125" width="250" /></p>
<p><img src="a6.jpg" height="125" width="250" /></p>
</div>
</div>
<p><span id="botao1" onClick="mexe(1)" class="botao">Para cima</span></p>
<p><span id="botao2" onClick="mexe(2)" class="botao">Para baixo</span></p>

<div class="container1" id="cont1" style="float:left">
<div id="news1" style="position:relative">
<div style="float:left"><img src="fotosdojoao/1.png" height="125" width="250"></div>
<div style="float:left"><img src="fotosdojoao/2.png" height="125" width="250"></div>
<div style="float:left"><img src="fotosdojoao/3.png" height="125" width="250"></div>
<div style="float:left"><img src="fotosdojoao/4.png" height="125" width="250"></div>
</div>
</div>
<p><span id="botao3" onClick="mexer(1)" class="botao">Esquerda</span></p>
<p><span id="botao4" onClick="mexer(2)" class="botao">Direita</span></p>
<script type="text/javascript">
var topo;
var baixo;
var avanco;
var altura;


function mexe(direcao)
{
    topo=Number(document.getElementById("news").style.top.substr(0,document.getElementById("news").style.top.length-2));
    baixo=Number(document.getElementById("news").style.top.substr(0,document.getElementById("news").style.bottom.length-2));
    avanco=Number(document.getElementById("cont").clientHeight);
    altura=Number(document.getElementById("news").clientHeight)-avanco+30;


if (direcao==1 && topo<0)
    {
        if((topo+avanco)>=0)
        {
            topo=0;
        }
        else
        {
        topo=topo+avanco;
        }
    //document.getElementById("news").style.top=topo+"px";
    }
    
if(direcao==2)
    {
        if((topo-avanco)*(-1)>=altura)
        {
            topo=altura*-1;
        }
        else
        {
        topo=topo-avanco;
        }
        //document.getElementById("news").style.top=topo+"px";
    }
}

$(document).ready(function()
  {
  $("#botao1").click(function(){
    $("#news").animate({top:topo+"px"},"normal","swing");
  });
  $("#botao2").click(function(){
    $("#news").animate({top:topo+"px"},"normal","swing");
  });
});



function mexer(direcao)
{
    esq=Number(document.getElementById("news1").style.left.substr(0,document.getElementById("news1").style.left.length-2));
    passagem=Number(document.getElementById("cont1").clientWidth);
    comp=Number(document.getElementById("news1").style.width.substr(0,document.getElementById("news1").style.width.length-2));
    maximo=comp-passagem+20;


if (direcao==1 && esq<0)
    {
        if((esq+passagem)>=0)
        {
            esq=0;
        }
        else
        {
        esq=esq+passagem;
        }
    document.getElementById("news1").style.left=esq+"px";
    }
    
if(direcao==2)
    {
        if((esq-passagem)*(-1)>=maximo)
        {
            esq=maximo*-1;
        }
        else
        {
        esq=esq-passagem;
        }
        document.getElementById("news1").style.left=esq+"px";
    }
}
</script>
</body>
</html>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T20:39:25+00:00Added an answer on June 1, 2026 at 8:39 pm

    Not sure it’s what you wanted, but to set/get the width you can do it like this:

    //get width of an item
    var itemWidth = $('#news1 > div:first').width();
    //count number of items
    var itemsCount = $('#news1 > div').length;
    //width * count = width
    var containerWidth = itemWidth * itemsCount;
    alert(containerWidth);
    

    You can set it directly doing

    $('#news1').width(containerWidth);
    

    Or use it when you make the scrolling.

    Since it’s not in english i have a hard time understanding how it works :/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ok, I'm building a horizontal scroll website for a photographer. We have some really
I am building a horizontal navigation that also has a horizontal submenu. Soh Tanaka
Basically, I am building a horizontal navigation bar. I have following markup: <ui:style src=../common.css
I am currently building a horizontal gallery of videos. I'd like to make something
Building a website that has English & Japanese speaking users, with the Japanese users
Building my first SL MVVM application (Silverlight4 RC) and have some issues i don't
I have been working on a touch screen application. I need to know if
I'm building an horizontal menu in HTML+CSS. The current result is fine, except I
I am building this mobile website. If you check it on your mobile browser
I am building a view in my Android application which should scroll both horizontal

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.