Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Making image move along left and right border

Posted on 2006-07-21
6
Medium Priority
?
204 Views
Last Modified: 2009-12-16
Hello,

I use the following script to move an image up the right border of a table cell (thanks, ed987)

Now I want it to scroll up BOTH the LEFT and RIGHT borders.

I want the one on the right to start moving imediatly, and I want the one on the left to start moving up 3 seconds later.

Any ideas?

Thanks!

<style>
table#mainLayout {
border: 1px #7799aa solid;
}
</style>

<table id="mainLayout" align="center">
 <tr>
  <td height="400" id=content>
   Content goes here
  </td>
 </tr>
<table>

<img src=blop.png style="display:none;width:1px;height:10px" id=img>

<script>
 // thanks, ed987
  function findPosX(obj)
  {
    var curleft = 0;
    if(obj.offsetParent)
        while(1)
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
  }

  function findPosY(obj)
  {
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
  }

var ma=document.getElementById('content'),img=document.getElementById('img');
img.style.display='block';

img.style.position='absolute';
var width=document.all?img.style.pixelWidth:img.clientWidth,height=document.all?img.style.pixelHeight:img.clientHeight;
var yTop=findPosY(ma);
var yy=yTop+ma.clientHeight;
img.style.left=(findPosX(ma)+ma.clientWidth-parseInt(width/2))+'px';
img.style.top=yy+'px';
//yTop-=height; //this line has sent it above the table, i quickly read it, thought that's desired

var moveyIntv;
function movey()
{
  var yy=(parseInt(img.style.top)-10);
  img.style.top=yy+'px';
  if(yy<yTop){ clearInterval(moveyIntv);img.style.top=yTop+'px';}
}
moveyIntv=setInterval("movey()",100);
 
</script>
0
Comment
Question by:hankknight
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 17

Expert Comment

by:Suat Ozgur
ID: 17154360
Hi,

Please try following modified code:

<style>
table#mainLayout {
border: 1px #7799aa solid;
}
</style>

<table id="mainLayout" align="center">
 <tr>
  <td height="400" id=content>
   Content goes here
  </td>
 </tr>
<table>

<img src=test.jpg style="display:none;width:1px;height:10px" id=img>
<img src=test.jpg style="display:none;width:1px;height:10px" id=imgleft>

<script>
 // thanks, ed987
  function findPosX(obj)
  {
    var curleft = 0;
    if(obj.offsetParent)
        while(1)
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
  }

  function findPosY(obj)
  {
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
  }

var ma=document.getElementById('content'),img=document.getElementById('img'),imgleft=document.getElementById('imgleft');

img.style.display='block';
img.style.position='absolute';

imgleft.style.display='block';
imgleft.style.position='absolute';

var width=document.all?img.style.pixelWidth:img.clientWidth,height=document.all?img.style.pixelHeight:img.clientHeight;
var yTop=findPosY(ma);
var yy=yTop+ma.clientHeight;


img.style.left=(findPosX(ma)+ma.clientWidth-parseInt(width/2))+'px';
img.style.top=yy+'px';
//yTop-=height; //this line has sent it above the table, i quickly read it, thought that's desired

var moveyIntv;
var moveyIntv2;
var delay;

function movey()
{
  var yy=(parseInt(img.style.top)-10);
  img.style.top=yy+'px';
  if(yy<yTop){ clearInterval(moveyIntv);img.style.top=yTop+'px';}

}
function moveyleft()
{
  var yy=(parseInt(imgleft.style.top)-10);
  imgleft.style.top=yy+'px';
  if(yy<yTop){ clearInterval(moveyIntv2);imgleft.style.top=yTop+'px';}

}

function startleft()
{
  clearInterval(delay);
  imgleft.style.left=(findPosX(ma)-parseInt(width/2))+'px';
  imgleft.style.top=yy+'px';
  moveyIntv2=setInterval("moveyleft()",100);
}
moveyIntv=setInterval("movey()",100);
delay=setInterval("startleft()",3000);
 
</script>
0
 
LVL 17

Expert Comment

by:Suat Ozgur
ID: 17154375
Sorry, I changed your image name in <img> tags as test.jpg.
Please change it back to blop.png for both. So it looks like:

<style>
table#mainLayout {
border: 1px #7799aa solid;
}
</style>

<table id="mainLayout" align="center">
 <tr>
  <td height="400" id=content>
   Content goes here
  </td>
 </tr>
<table>

<img src=blop.png style="display:none;width:1px;height:10px" id=img>
<img src=blop.png style="display:none;width:1px;height:10px" id=imgleft>

<script>
 // thanks, ed987
  function findPosX(obj)
  {
    var curleft = 0;
    if(obj.offsetParent)
        while(1)
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
  }

  function findPosY(obj)
  {
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
  }

var ma=document.getElementById('content'),img=document.getElementById('img'),imgleft=document.getElementById('imgleft');

img.style.display='block';
img.style.position='absolute';

imgleft.style.display='block';
imgleft.style.position='absolute';

var width=document.all?img.style.pixelWidth:img.clientWidth,height=document.all?img.style.pixelHeight:img.clientHeight;
var yTop=findPosY(ma);
var yy=yTop+ma.clientHeight;


img.style.left=(findPosX(ma)+ma.clientWidth-parseInt(width/2))+'px';
img.style.top=yy+'px';
//yTop-=height; //this line has sent it above the table, i quickly read it, thought that's desired

var moveyIntv;
var moveyIntv2;
var delay;

function movey()
{
  var yy=(parseInt(img.style.top)-10);
  img.style.top=yy+'px';
  if(yy<yTop){ clearInterval(moveyIntv);img.style.top=yTop+'px';}

}
function moveyleft()
{
  var yy=(parseInt(imgleft.style.top)-10);
  imgleft.style.top=yy+'px';
  if(yy<yTop){ clearInterval(moveyIntv2);imgleft.style.top=yTop+'px';}

}

function startleft()
{
  clearInterval(delay);
  imgleft.style.left=(findPosX(ma)-parseInt(width/2))+'px';
  imgleft.style.top=yy+'px';
  moveyIntv2=setInterval("moveyleft()",100);
}
moveyIntv=setInterval("movey()",100);
delay=setInterval("startleft()",3000);
 
</script>


Suat
0
 
LVL 16

Author Comment

by:hankknight
ID: 17154674
Thanks!  How can I have this process repeated every 20 seconds?
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 17

Accepted Solution

by:
Suat Ozgur earned 2000 total points
ID: 17154838
Try this one:

<style>
table#mainLayout {
border: 1px #7799aa solid;
}
</style>

<table id="mainLayout" align="center">
 <tr>
  <td height="400" id=content>
   Content goes here
  </td>
 </tr>
<table>

<img src=blop.png style="display:none;width:1px;height:10px" id=img>
<img src=blop.png style="display:none;width:1px;height:10px" id=imgleft>

<script>
 // thanks, ed987
  function findPosX(obj)
  {
    var curleft = 0;
    if(obj.offsetParent)
        while(1)
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
  }

  function findPosY(obj)
  {
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
  }

var ma=document.getElementById('content'),img=document.getElementById('img'),imgleft=document.getElementById('imgleft');

img.style.display='block';
img.style.position='absolute';

imgleft.style.display='block';
imgleft.style.position='absolute';

var width=document.all?img.style.pixelWidth:img.clientWidth,height=document.all?img.style.pixelHeight:img.clientHeight;
var yTop=findPosY(ma);
var yy=yTop+ma.clientHeight;


//yTop-=height; //this line has sent it above the table, i quickly read it, thought that's desired

var moveyIntv;
var moveyIntv2;
var delay;
var trigger;

starthere();

function movey()
{
  var yy=(parseInt(img.style.top)-10);
  img.style.top=yy+'px';
  if(yy<yTop){
    clearInterval(moveyIntv);
    img.style.top=yTop+'px';
  }

}
function moveyleft()
{
  var yy=(parseInt(imgleft.style.top)-10);
  imgleft.style.top=yy+'px';
  if(yy<yTop){
    clearInterval(moveyIntv2);
    imgleft.style.top=yTop+'px';
    trigger=setInterval("starthere()",20000);
  }

}

function startleft()
{
  clearInterval(delay);
  moveyIntv2=setInterval("moveyleft()",100);
}

function starthere(){
  img.style.left=(findPosX(ma)+ma.clientWidth-parseInt(width/2))+'px';
  img.style.top=yy+'px';
  imgleft.style.left=(findPosX(ma)-parseInt(width/2))+'px';
  imgleft.style.top=yy+'px';
  moveyIntv=setInterval("movey()",100);
  delay=setInterval("startleft()",3000);
  clearInterval(trigger);
}
 
</script>

Suat
0
 
LVL 16

Author Comment

by:hankknight
ID: 17155132
Thanks!  

By the way, I have posted a related question here:

http://www.experts-exchange.com/Web/Web_Languages/JavaScript/Q_21927506.html
0
 
LVL 17

Expert Comment

by:Suat Ozgur
ID: 17155193
Glad to hear it helps!

I'll look at the related question. I hope I can help. I think you might want to notify ed987 as well (original author).

Suat
(Thanks for the A grade)
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question