Solved

Making image move along left and right border

Posted on 2006-07-21
6
187 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
  • 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 17

Accepted Solution

by:
Suat Ozgur earned 500 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

When you need to keep track of a simple list of numbers or strings, the Array object is your most direct tool.  As we saw in my earlier EE Article (http://www.experts-exchange.com/A_3488.html), typical array handling might look like this: (CODE) B…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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…

929 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now