views:

50

answers:

1

I'm having a lot of trouble getting a simple text link to work in IE8 using Raphael. I want text that behaves like a normal link. I've included some code below that I have been playing with.

  • Got the cursor to change to a hand by using the hover function and document.body.cursor
  • The click function only works when clicking on actual text pixels - clicking on the gaps between letters does nothing
  • The above problem also affects hover

Do I need to add some element behind the text, a rectangle / bounding box, to handle the mouse? Any ideas? This problem is only in IE8, which as you know, uses VML via Raphael.

Here's the code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <link rel="shortcut icon" type="image/x-icon" href="images/favicon.ico">
    <script type="text/javascript" src="js/jquery-1.4.2.js"></script>
    <script type="text/javascript" src="js/jquery-ui-1.8.4.min.js"></script>
    <script type="text/javascript" src="js/raphael-min.js" charset="utf-8"></script>
    <script type="text/javascript">
    window.onload = function () {

    // Creates canvas 320 × 200 at 10, 50
    var paper = Raphael(10, 50, 420, 400);

    var lbl = paper.text(50, 40, 'test').attr( {
      "font" : '14px Helvetica, Arial',
      stroke : "none",
      fill : '#ffffff',
      'text-anchor' : 'middle'
    });

    lbl.node.style.display = 'block';
    lbl.node.style.cursor = 'pointer';

    lbl.click(function() {
      alert('hi');        });

    lbl.hover(function() {
      document.body.style.cursor = 'hand';
    }, function() {
        document.body.style.cursor = 'default';
    });

    }
    </script>
</head>
<body style="background-color: #000000;">
    <div id="wrapper" style="background-color: #000000;"> </div>
</body>
</html>
+1  A: 
var lbl = paper.text(50, 40, 'test').attr( {
  font : '14px Helvetica, Arial',
  stroke : "none",
  fill : '#fff'
}),
blanket = paper.rect().attr(lbl.getBBox()).attr({
  fill: "#000",
  opacity: 0,
  cursor: "pointer"
}).click(function () { alert("hi"); });
Dmitry Baranovskiy
Thanks Dmitry that helped me greatly.
ncatnow