/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] So close to being done.

I need some help on one final item of a script.

The intent is to display an image in an element (BGdiv in the script below)
and over-lay (z-index) it with another element (FGdiv) that contains a PNG image with a clear circle.

I want the user to click on a table of cells that will move the PNG over the background image to display only a portion at a time.

The object of the script is to determine how many areas (and where) need to be view to guess at the underlying image

Currently, I cannot figure out how to cover the background image (BGdiv) so that only the layered element of the circle display shows the underlying image. Right now all works as expected, except the whole background image is displayed instead of just the area under the circle. It appears to work the same way in the FF, IE and Safari browsers. ?

Here is the current script:

[code=php]
<html>
<head>
<title>PNG images</title>
<style type=”text/css”>
#BGdiv {
position:absolute;
left:100px;
top: 100px;
z-index:10;
}
#FGdiv {
position:absolute;
top:50px;
left:50px;
z-index:50;
height:200px;
width:200px;
}
body { background:#000000;
color:#ffffff;
}
</style>
<script type=”text/javascript”>
function MoveTo(x,y) {
x *= 100; // x += 100; // for relative positions
y *= 100; // y += 100; // for relative positions
var el = document.getElementById(‘FGdiv’);
// for non-IE browsers
el.style.left=x+’px’; el.style.top=y+’px’;
// for IE browsers
el.style.posLeft = x; el.style.posTop = y;
}

// create dynamic table
function createTable() {
var div = document.createElement(‘div’);
div.setAttribute(‘height’,’200′);
div.setAttribute(‘width’,’200′);
div.setAttribute(‘style’,’margin: 1cm 1cm 1cm 1cm’); // currently not changing in the display ???

var table = document.createElement(‘table’);
table.setAttribute(‘border’,’1′);
var tbody = document.createElement(‘tbody’);
for (r=1; r<5; r++) {
var tr = document.createElement(‘tr’);
for (c=1; c<5; c++) {
var td = document.createElement(‘td’);
var txt = ‘MoveTo(‘+c.toString()+’,’+r.toString()+’)’;
td.setAttribute(‘onclick’,txt)
var newText = document.createTextNode(r.toString()+c.toString());
td.appendChild(newText);
tr.appendChild(td);
}
tbody.appendChild(tr);
}
table.appendChild(tbody);
document.body.appendChild(table);
document.body.appendChild(div);
}
</script>
</head>
<body onLoad=”createTable()”>

<div id=”BGdiv”>
<img src=”../PA190036.JPG” height=”400″ width=”400″>
</div>
<div id=”FGdiv”>
<img src=”../spotlight_circle.png” height=”100″ width=”100″>
</div>

</body>
</html>
[/code]

The .PNG file is attached.
The background image is any .JPG you wish to use. Currently I have a ‘Pocket Dragon’ to view.

Currently the actual script is located at: [url]http://www.nova.edu/~rumsey/spot/test/dragon.html[/url]
if you wish to see my incomplete progress.

Is there a JS setting or CSS command I’m missing somewhere? ?
I’m so close to done and need this last bit of help. 😮

[upl-file uuid=d104b296-2296-4304-adc9-54f4a1f83c57 size=24kB]spotlight_circle.png[/upl-file]

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@jasonahouleNov 20.2007 — Why not cover all other cells with a solid black square? Then remove them as necessary.
Copy linkTweet thisAlerts:
@James_McMurrayNov 20.2007 — Check out the code examples for this book. Click on Code Examples on the right and then Launch Code Browser. Chapter 18 under "Follow the Mouse Pointer."
Copy linkTweet thisAlerts:
@JMRKERauthorNov 21.2007 — Why not cover all other cells with a solid black square? Then remove them as necessary.[/QUOTE]

That's an idea I had not considered.

I guess I could determine the matrix of positions and use a show/hide code

to cover/uncover the area before I move the circle over it.

Might work with a little more calculation power. I was trying to keep

it a bit simpler, but I'll look into this if my initial attempt go for naught.

Thanks for the idea.
Copy linkTweet thisAlerts:
@JMRKERauthorNov 21.2007 — Check out the code examples for this book. Click on Code Examples on the right and then Launch Code Browser. Chapter 18 under "Follow the Mouse Pointer."[/QUOTE]

Thanks. I have an earlier edition of the book (BTW: It's chapter 17 in the new edition).

The problem I was having with that book code was:

1. It used a .gif image which does not have the transparency of a .png

2. It did not seem to work on the body as the actual text that is revealed is part of and displayed in a <div> area.

3. When I replaced the .gif with the .png image, I only get a faint circle that reveals the text (instead of a displayed hole). It is only partly transparent.

and

4. It did not hide the background dragon image when I put it into the body region or the <div> region of the text area, which is what I'm trying to do with my script.

I do confess that I got the idea from this book. I was trying to modify it to suit my needs and I can ALMOST do it, but not quite. I do like the idea of the mouse movement of the element and will probably use that function is a later script.

The CSS forum people have given me some code that does seem to work.

It's just that it is above my pay grade to comprehend so I could not modify it without screwing it up.


My attempt in post #1 was to simplify it so I could both understand it and successfully modify it.


So far, it's not going as good as I had planned. (I can reference the CSS forum post for anyone interested)

Like I said, I'm so close.

My goal is to have the IMAGE hidden under the spotlight

just like the TEXT is hidden in the books' script.


I thought the PNG image was the only way I could do this.
Copy linkTweet thisAlerts:
@JMRKERauthorNov 22.2007 — After reviewing about 7 books, many 'googled' sites and the review of earlier versions, I finally found the 'magic command' that I had trouble with getting to work. It is a CSS argument called 'clip'

It works well, but for me was very confusing as to it's implementation.

Below is the code I have finally come up with. Substitute your own images if interested in using it.
[code=php]
<html>
<head>
<title>PNG images</title>
<style type="text/css">
#BGdiv {
position:absolute;
left:100px;
top: 100px;
z-index:10;

clip: rect(0px,100px,100px,0px); /* top,right,bottom,left */
background-color: #ffffff; /* #000000 for black background */
}
#FGdiv {
position:absolute;
top:50px;
left:50px;
z-index:50;

height:100px;
width:100px;
border: 1px solid cyan;
}
body { background:#ffffcc; color:#000000; /* #000000 for black background */
}
</style>
<script type="text/javascript">
function MoveTo(x,y) {
x *= 100; // x += 100; // for relative positions
y *= 100; // y += 100; // for relative positions
var el = document.getElementById('FGdiv');
// for non-IE browsers
el.style.left=x+'px'; el.style.top=y+'px';
// for IE browsers
el.style.posLeft = x; el.style.posTop = y;

el = document.getElementById('BGdiv');
el.style.clip.top = y; // +'px';
el.style.clip.left = x; // +'px';
el.style.clip.bottom= y+50; // +'px';
el.style.clip.right= x+50; //+'px';;
}

var xscale = 100; var yscale = 100;
function SetRect(t,r,b,l) {
t *= yscale; r *= xscale; b *= yscale; l *= xscale;
var str = "document.getElementById('BGdiv').style.clip='";
str += 'rect('; str += t+'px,'; str += r+'px,'; str += b+'px,'; str += l+"px)'";
return str;
}

// create dynamic table
function createTable() {
// var div = document.createElement('div');
// div.setAttribute('height','200');
// div.setAttribute('width','200');
// div.setAttribute('style','margin: 1cm 1cm 1cm 1cm');

var table = document.createElement('table');
table.setAttribute('border','1');
var tbody = document.createElement('tbody');
for (r=1; r<5; r++) {
var tr = document.createElement('tr');
for (c=1; c<5; c++) {
var td = document.createElement('td');
var txt = 'MoveTo('+c.toString()+','+r.toString()+');';
txt += SetRect((r-1),c,r,(c-1));
td.setAttribute('onclick',txt)
var newText = document.createTextNode(r.toString()+c.toString());
td.appendChild(newText);
tr.appendChild(td);
}
tbody.appendChild(tr);
}
table.appendChild(tbody);
document.body.appendChild(table);
// document.body.appendChild(div);
}
</script>
</head>
<body onLoad="createTable()">
<button onClick="document.getElementById('BGdiv').style.clip='rect(auto,auto,auto,auto)'">Reveal</button>
<div id="BGdiv"> <img src="dragon.JPG" height="400" width="400"> </div>
<div id="FGdiv"> <img src="../spotlight_circle.png" height="100" width="100"> </div>

<div style="position:absolute;top:250px;left:250px;font-size:2em;"> Message on background goes here. </div>

</body>
</html>
[/code]

You can view my working test version at:

http://www.nova.edu/~rumsey/spot/test/dragn1.html

Thanks to all for providing challenging hints.
×

Success!

Help @JMRKER spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.29,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...