Hello.
Is there a way to make an element 'transparent' to mouse activity, such that
mouse events go to the underlying element? I have an absolutely-positioned
image element with transparency that partly overlaps another element. I want
mouse events on the overlapping image to go to the underlying element.
Thanks,
nf
Jul 23 '05
18 6071
nutso fasst wrote: "RobG" <rg***@iinet.ne t.auau> wrote in message news:42******** *************** @per-qv1-newsreader-01.iinet.net.au ...
This is an interesting issue. If that is what you are going to do, you may as well use RobB's method and fire the onclick from both images - it's the simplest by far.
But also fires over the overlapping image where it doesn't overlap.
So do that and keep things simple - anything based on pixel-perfect locations of elements in the page is bound to fail sooner rather than later.
Bound to fail?
Page co-ord methods may be OK now, but in future you may introduce
new stuff that messes with some browsers. The news site that I use
recently 'updated' their site so now Firefox has issues with
overlapping text and images until I force a re-fresh by
increasing/decreasing the font size. Not fatal, but a real PITA.
I would expect that page co-ord stuff would have problems in the
above scenario.
What I wrote works with FF and with IE all the way back to v.4.0, and standardization is improving. But there is a way to do it that doesn't rely on coordinates and doesn't need an event on the overlapping image: another div that overlaps both. Simple, really. I've removed IE 4's document.all support for clarity...
Ah yes, I was most of the way there but my implementation was flawed.
Put the overlying div with the onclick in a separate branch so
neither image gets in the way. Musta been tired...
[...] With document.all support added works with IE4 and later, also works with FF.
Clean, tidy, exactly as specified and no posX/Y - congratulations :-)
--
Rob
Hmm, just noticed another nice thing about this solution. If I add some
titles to the HTML, e.g.:
<div id="topdiv"><di v id="topclick" title="click to scroll the
image...">  ;</div></div>
<div id="clipdiv" title="click to hide the scroll bar..."><img height=150
src="images/wideimg.jpg" alt="wide
image"></div>
Presto, contextual instructions!
nf
nutso fasst wrote: "RobB" <fe******@hotma il.com> wrote in message news:11******** **************@ z14g2000cwz.goo glegroups.com.. .
Hi, Rob. Your example looks pretty straightforward , but it doesn't
account for 'cthru' only partially overlapping 'xpander'.
That's pretty cryptic...you said initially: The problem is that there is a absolutely-positioned GIF image overlapping the bottom of the wide image.
....which is exactly what I gave you. Make sure that the post wasn't
corrupted, there might be a control character or two in there, and that
long url is truncated.
Also, I don't understand statements like "/\bscroll\b/.test(obj.style .overflowX)." Can you
explain?
obj.style.overf lowX = /\bscroll\b/.test(obj.style .overflowX) ?
'hidden' : 'scroll';
Uses the regular expression /\bscroll\b/, which will match the string
'scroll' (could have used /^scroll$/ or simply /scroll/ also); if it
matches, RegExp.test returns true which assigns 'hidden' to the
overflowX property, otherwise assigning 'scroll'. A toggle, in other
words. Note that, first time around, this property will be the empty
string, a result of the CSS having cascaded from a global stylesheet
rather than being assigned in the element's HTML and setting the Style
object directly. So the toggle works both initially, and after the
property is set.
obj.style.overf low = /\bauto\b/.test(obj.style .overflow) ?
'hidden' : 'auto';
Same for the overflow property. Setting both is required to suppress
the vertical scrollbar cross-browser.
if ('undefined' != typeof obj.scrollLeft)
obj.scrollLeft = 0;
Returns image to flush left if 'unexpanded'. Seemed logical.
obj.title = /version/.test(obj.title ) ?
' click to reset...' : ' click for full-size version...';
Swaps title (prompt).
if (obj = document.getEle mentById('cthru '))
obj.style.zInde x = /((^$)|0|3)/.test(obj.style .zIndex) ?
'1' : '3';
Flips z-index; if empty string ^$ (first-time around, Gecko, others)
sets to '1', 'underlapping' gif; if '0' (MSIE, first-time, illogically,
as it's also cascaded) does same; if '3' (2nd+ time, all), ditto;
otherwise sets to '3', restoring overlap).
The other function simply causes clicks on the gif to invoke the
onclick handler of the inner container div.
The above is easily modifiable for a variety of different behaviors;
kept it simple as I wasn't entirely sure how you wanted it to work.
Fire away...
cheers, Rob
nutso fasst wrote: "RobB" <fe******@hotma il.com> wrote in message news:11******** **************@ z14g2000cwz.goo glegroups.com.. .
Hi, Rob. Your example looks pretty straightforward , but it doesn't
account for 'cthru' only partially overlapping 'xpander'.
Aargh...not all that 'cryptic' after all...I get it.
Rather than the rigmarole of getting click position, comparing to
graphic bottom position, etc. - took the easy way out, superimposing a
bottom-clipped version of the same gif within a common container, and
used that for event 'routing'. Not quite perfect cross-browser
(positioning variances) but very close. I'd normally use some simple
CSS hacks to equalize the display if this were my page (google 'css
hacks', if interested, for ways to hide rules from various browsers).
See if this is better:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<style type="text/css">
body {
background: url( http://www.light-speed-web-graphics.com/
stripes_horiz_d ifferent/fastest_00008.G IF);
}
#container {
position: relative;
width: 97%;
margin: 20px auto;
background: #000;
z-index: 2;
}
#xpander {
position: absolute;
left: 0;
top: 0;
width: 100%;
border: 4px #fff outset;
overflow: hidden;
cursor: e-resize;
}
#xpander img {
display: block;
border: none;
}
#cthru {
position: absolute;
left: 422px;
top: 386px;
width: 140px;
height: 140px;
z-index: 3;
}
#cthru #trigger {
position: absolute;
left: 0;
top: 0;
width: 140px;
height: 140px;
clip: rect(auto auto 78px auto);
cursor: e-resize;
z-index: 2;
}
#cthru img {
position: absolute;
left: 0;
top: 0;
width: 140px;
height: 140px;
z-index: 1;
}
</style>
<script type="text/javascript">
function expcon(obj)
{
if (document.getEl ementById)
{
obj.style.overf lowX = /\bscroll\b/.test(obj.style .overflowX) ?
'hidden' : 'scroll';
obj.style.overf low = /\bauto\b/.test(obj.style .overflow) ?
'hidden' : 'auto';
if ('undefined' != typeof obj.scrollLeft)
obj.scrollLeft = 0;
obj.title = /version/.test(obj.title ) ?
' ~ click to reset ~ ' : ' ~ click for full-size version ~ ';
if (obj = document.getEle mentById('cthru '))
obj.style.zInde x = /((^$)|0|3)/.test(obj.style .zIndex) ?
'1' : '3';
}
}
function routeclick(id)
{
var el;
if (document.getEl ementById
&& (el = document.getEle mentById(id))
&& 'undefined' != typeof el.onclick)
el.onclick();
}
</script>
</head>
<body>
<div id="container" >
<div id="xpander"
title=" ~ click for full-size version ~ "
onclick="return expcon(this)">
<img src="http://www.leaney.org/walks/photos/20040430jp.jpg" />
</div></div>
<div id="cthru">
<img id="trigger"
onclick="routec lick('xpander') "
src="http://www.ueda.info.w aseda.ac.jp/~hiroto/Graphics/sample1.gif" />
<img
src="http://www.ueda.info.w aseda.ac.jp/~hiroto/Graphics/sample1.gif" />
</div>
</body>
</html>
You'll need to paste that body {background: url(...); into a single
long url.
"RobG" <rg***@iinet.ne t.auau> wrote in message
news:ao******** ********@news.o ptus.net.au... Clean, tidy, exactly as specified and no posX/Y - congratulations :-)
Thanks. Most folks would consider it time badly spent, but sometimes the
solving of the problem is more important than the usefulness of the
solution.
nutso "the joy is in the journey" fasst
"RobB" <fe******@hotma il.com> wrote in message
news:11******** **************@ o13g2000cwo.goo glegroups.com.. . Uses the regular expression /\bscroll\b/, which will match the string 'scroll' (could have used /^scroll$/ or simply /scroll/ also); if it matches, RegExp.test returns true which assigns 'hidden' to the overflowX property, otherwise assigning 'scroll'. A toggle, in other words.
Ah, yes. I understand the toggle, I wasn't clear on the use of the regex.
Isn't
obj.style.overf low = (obj.style.over flow=='auto') ? 'hidden' : 'auto';
more efficient, and testing on the numeric value of zIndex more efficient
still? Having determined the zIndex, other tests are unnecessary, and one
'if()' is more efficient than multiple toggles.
Same for the overflow property. Setting both is required to suppress the vertical scrollbar cross-browser.
I was under the impression overflowX was a subset of overflow, setting
overflow sets both overflowX and overflowY.
if ('undefined' != typeof obj.scrollLeft) obj.scrollLeft = 0;
Returns image to flush left if 'unexpanded'. Seemed logical.
Good idea! Thanks.
Your 2nd solution looks good, tho it seems to me either an empty div or a
1-pixel-high totally-transparent gif sized with CSS to the overlapping area
would work better than a clipped duplicate of the overlapped image. On the
off chance of no stylesheet support, it wouldn't significantly affect
appearance. I put " " in my overlapping div out of fear that some
browser might ignore a click on an empty element, but perhaps that isn't
necessary. It works without it in IE and FF.
nf
nutso fasst wrote: "RobG" <rg***@iinet.ne t.auau> wrote in message news:ao******** ********@news.o ptus.net.au... Clean, tidy, exactly as specified and no posX/Y - congratulations
:-) Thanks. Most folks would consider it time badly spent, but sometimes
the solving of the problem is more important than the usefulness of the solution.
nutso "the joy is in the journey" fasst
As they say on that *Millionaire* show..."yes, final answer".
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<style type="text/css">
body {
background:
url( http://www.light-speed-web-graphics....st_00008.GIF);
}
#container {
position: relative;
width: 95%;
margin: 20px auto;
background: #000;
z-index: 2;
}
#xpander {
position: absolute;
left: 0;
top: 0;
width: 100%;
border: 4px #eef outset;
overflow: hidden;
cursor: e-resize;
}
#xpander img {
display: block;
border: none;
}
#cthru {
position: absolute;
left: 422px;
top: 386px;
width: 140px;
height: 140px;
z-index: 3;
}
#cthru #trigger {
position: absolute;
left: 0;
top: 0;
width: 140px;
height: 140px;
cursor: e-resize;
z-index: 2;
}
#cthru img {
position: absolute;
left: 0;
top: 0;
width: 140px;
height: 140px;
z-index: 1;
}
</style>
<script type="text/javascript">
function expcon(obj)
{
if (document.getEl ementById)
{
obj.style.overf lowX = /scroll/.test(obj.style .overflowX) ?
'hidden' : 'scroll';
obj.style.overf low = /auto/.test(obj.style .overflow) ?
'hidden' : 'auto';
if ('undefined' != typeof obj.scrollLeft)
obj.scrollLeft = 0;
obj.title = /version/.test(obj.title ) ?
' ~ click to reset ~ ' : ' ~ click for full-size version ~ ';
if (obj = document.getEle mentById('cthru '))
obj.style.zInde x = /((^$)|0|3)/.test(obj.style .zIndex) ?
'1' : '3';
}
}
function routeclick(id)
{
var el;
if (document.getEl ementById
&& (el = document.getEle mentById(id))
&& 'undefined' != typeof el.onclick)
el.onclick();
}
function getTopBottom(id )
{
var obj = document.getEle mentById(id),
ht = obj.offsetHeigh t,
y = obj.offsetTop;
while ((obj = obj.offsetParen t) != null)
y += obj.offsetTop;
return {top: y, bottom: y + ht};
}
function init()
{
if (document.getEl ementById)
{
var xb, ct, tg, bclip, adj = 4,
cp = 'rect(auto auto 0px auto)';
if ((xb = getTopBottom('x pander').bottom )
&& (ct = getTopBottom('c thru').top)
&& (tg = document.getEle mentById('trigg er'))
&& !isNaN(bclip = (xb - ct - adj)))
{
tg.style.clip = cp.replace(/0/, bclip);
}
}
}
window.onload = init;
</script>
</head>
<body>
<div id="container" >
<div id="xpander"
title=" ~ click for full-size version ~ "
onclick="return expcon(this)">
<img src="http://www.leaney.org/walks/photos/20040430jp.jpg" >
</div></div>
<div id="cthru">
<img id="trigger"
title=" ~ click for full-size version ~ "
onclick="routec lick('xpander') "
src="http://www.ueda.info.w aseda.ac.jp/~hiroto/Graphics/sample1.gif">
<img
src="http://www.ueda.info.w aseda.ac.jp/~hiroto/Graphics/sample1.gif">
</div>
</body>
</html>
If you need to see the efficacy of this, add 'background: red;' to the
CSS for #cthru #trigger. 'adj' trims the clip to deactivate the border
area.
Again, googlegroups will probably mangle this, so, repaste any
truncated urls as needed, close tags, open in Notepad and look for any
control characters (dashes) inserted. Been haranguing those pinheads
for a week...
nutso fasst wrote: "RobB" <fe******@hotma il.com> wrote in message news:11******** **************@ o13g2000cwo.goo glegroups.com.. . Uses the regular expression /\bscroll\b/, which will match the
string 'scroll' (could have used /^scroll$/ or simply /scroll/ also); if
it matches, RegExp.test returns true which assigns 'hidden' to the overflowX property, otherwise assigning 'scroll'. A toggle, in
other words. Ah, yes. I understand the toggle, I wasn't clear on the use of the
regex. Isn't obj.style.overf low = (obj.style.over flow=='auto') ? 'hidden' :
'auto'; more efficient, and testing on the numeric value of zIndex more
efficient still? Having determined the zIndex, other tests are unnecessary, and
one 'if()' is more efficient than multiple toggles.
Suit yourself, it's not a repetitive/recursive routine. Go ahead and
fine-tune if you like, the gains will likely be minimal. It's also not
necessarily turn-key, this is a free forum !
z-index is a string, btw. Same for the overflow property. Setting both is required to
suppress the vertical scrollbar cross-browser.
I was under the impression overflowX was a subset of overflow,
setting overflow sets both overflowX and overflowY.
I used to be under a lot of impressions, too, until I started playing
around with CSS in different browsers. One ends up using what works. If
you can find another approach, more power to you. Read some CSS
ngs/forums/blogs to see how unstraightforwa rd presentational coding can
get. #;=)
(snip)
Your 2nd solution looks good, tho it seems to me either an empty div
or a 1-pixel-high totally-transparent gif sized with CSS to the
overlapping area would work better than a clipped duplicate of the overlapped image.
No (see below). Why download that old 1-pixel-transparency when you
have the perfect item at hand: the very *same* transparency, ready for
'layering'.
On the off chance of no stylesheet support [ .. ]
F-them.
I put " " in my overlapping div out of fear that some browser might ignore a click on an empty element, but perhaps that
isn't necessary. It works without it in IE and FF.
It does? Not here (ie6win2k)...
"RobB" <fe******@hotma il.com> wrote in message
news:11******** **************@ z14g2000cwz.goo glegroups.com.. . It does? Not here (ie6win2k)...
True on ie6winXP as well. Sheee-it. Earlier IE do work OK. Well, this has
definitely been interesting. I dumped the overlapping div and put a
fully-transparent gif over the other image overlap and pointed its onclick
to togglescroll. AFICT this does work on IE4-6, FF and Opera. As for
overhead in getting the gif...it's 46 bytes, and I'm more concerned about
the possibility of misalignment.
Thanks much for all your input.
This is gratis work for a local library support group, BTW. Prob'ly only one
fellow (besides me) at the far right of the wide image who'll use the
scroll.
nf This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: zoltix |
last post by:
Hi,
I am beginner in JavaScript. I would like to intercept all click
events on my document. I use this function for that
document.onmousedown=click;. It works well. But I would like to
continue the execution code on a other button or anything else.
Example
1) Click anywhere intercept click->Execute the code in function click().
|
by: Paul Cooper |
last post by:
Dear All,
I am working on a piece of Javascript code that needs to detect a
mouse-click, shift-click and control-click. The code is not my own -
it is a part of a much larger suite of routines. The code as it stands
does not work in Firefox, and I suspect that the task of feature
detection (which currently depends on browser detection) can be
carried out better. The result should be that opcode is set to 0,1 or
2 dor click,...
|
by: J McD |
last post by:
Hi
I have a DataGrid with an ImageButton column. When I click on an imagebutton I get a postback but it doesn't run the OnImgBtnClick method. I can actually comment out the line where I add this Click event to the ImageButton Column and it makes no difference, I still get a postback. This is driving me crazy...something seems to be causing an OnClick postback and it isn't my Click event
I've included the code below....any help will be...
|
by: Terry Olsen |
last post by:
How can I catch a right-click on a DropDownMenuItem?
|
by: JohnR |
last post by:
In it's simplest form, assume that I have created a usercontrol,
WSToolBarButton that contains a button. I would like to eventually create
copies of WSToolBarButton dynamically at run time based on some
initialization information obtained elsewhere. Basically, I'm going to
create my own dynamic toolbar where the toolbarbuttons can change. I'm not
using the VB toolbar because of limitations in changing things like
backcolor (I can't get...
| |
by: Mattbooty |
last post by:
Hello,
Not sure if anyone else has seen this bug, but I have a form where
the entire form is covered with a picturebox. The picturebox has a
mouseup event. I also have an open file dialog for loading images into
the picturebox. If you double click the file you want to open in the
open file dialog, it somehow interperets one of the clicks as a mouseup
on the picturebox and fires the mouseup event for the picturebox. How
can I get...
|
by: Nick |
last post by:
Hey guys,
I have 2 events on a windows forms datagrid, the mouse move as well as the
double click events.
What's happening is that when I double click on a row in the grid, the mouse
move event gets triggered and the double click is not identified at all.
Is there any way I can invoke the double click when the mouse move also
exists?
|
by: cj |
last post by:
I would like to have menu items a main menu bar that represent the days
of the week. When you click on them they alternate from checked to
unchecked. Right now I have 7 subs that look like this one:
Private Sub MonMenuItem_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MonMenuItem.Click
If SunMenuItem.Checked Then
SunMenuItem.Checked = False
Else
SunMenuItem.Checked = True
|
by: |
last post by:
I have a control that need to perform one behavior when it's Clicked and a different behavior when it's DoubleClicked.
It seems that you can't get a DoubleClick without first getting a Click. So what's the best way to keep from executing the click functionality before it's determined if it's a double click or not?
Or do I just have to "undo" the Click stuff everytime a DoubleClick is received?
Thanks.
J
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |