?
Solved

Making image move along left and right border

Posted on 2006-07-21
6
Medium Priority
?
200 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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
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…
Suggested Courses

777 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