Mouseover, hover effects

2,453 views
Skip to first unread message

Victor Gladkikh

unread,
Dec 1, 2011, 6:20:25 AM12/1/11
to pap...@googlegroups.com
Is there any examples how to implement hover effect?

I want to change background color of grid cell on mouse move. But cannot understand where to start from. 
I've read about hitTest, but it's seems that I will need to cycle through all objects to return their state.

Jürg Lehni

unread,
Dec 2, 2011, 4:05:46 AM12/2/11
to pap...@googlegroups.com
Hi,

This functionality is all new, only present in the nightly build, and thus not documented yet.

But using the nightly build, this should work:

item.onMouseEnter = function() {
this.fillColor = 'red';
}

item.onMouseLeave = function() {
this.fillColor = 'blue';
}

Alternatively, you can also register and deregister events using the attach and detach methods:

item.attach('mouseenter', function() {
this.fillColor = 'red';
});

item.attach('mouseleave', function() {
this.fillColor = 'blue';
});

All these events are present:

onMouseEnter, onMouseLeave, onMouseOver, onClick, onDoubleClick, onMouseDrag

And their event names:

'mouseenter', 'mouseleave', 'mouseover', 'click', 'doubleclick', 'mousedrag'

I hope this helps, until we get some documentation together.

Best,

Jürg

Victor Gladkikh

unread,
Dec 2, 2011, 11:23:53 AM12/2/11
to pap...@googlegroups.com
Thanks, will try this later.

Xin Wang

unread,
Dec 5, 2011, 7:32:27 AM12/5/11
to pap...@googlegroups.com

It seems that onClick will take effect only if other mouse event is
also registered. For example:

var myCircle = new Path.Circle(new Point(100, 70), 50);
myCircle.fillColor = 'black';
myCircle.onClick = function () {
console.log('click')
}

Above code will not work, but following works:

var myCircle = new Path.Circle(new Point(100, 70), 50);
myCircle.fillColor = 'black';
myCircle.onClick = function () {
console.log('click')
}

myCircle.onMouseDrag = function () {
console.log('drag')
}


--
王欣 (Xin Wang)
blog: http://dram.me/

Jürg Lehni

unread,
Dec 5, 2011, 9:17:47 AM12/5/11
to pap...@googlegroups.com
I will look into this. The functionality is very new, there are most possibly bugs still.

J

Vladimir Kaluga

unread,
Jan 23, 2012, 7:16:57 AM1/23/12
to Paper.js
Hi!

onMouseenter/onMouseLeave are working incorrect with polygons in some
cases:

<!DOCTYPE html>
<html>
<head>
<title>Paper</title>
</head>
<body>
<canvas id="mainView" resize="true"></canvas>
<script src="../Lib/Paper/paper.js" type="text/javascript"></
script>
<script type="text/javascript">
paper.install(window);
window.onload = function () {
paper.setup("mainView");

var center = new Point(100, 100);
var sides = 6;
var radius = 20;
var hexagon = new Path.RegularPolygon(center, sides,
radius);
hexagon.fillColor = 'black';

hexagon.onMouseEnter = function () {
this.fillColor = 'red';
}

hexagon.onMouseLeave = function () {
this.fillColor = 'black';
}

paper.view.draw();

}
</script>
</body>
</html>

The hexagon is flickering when mouse move over it (tested in IE 9, FF
9, Chrome 16, Opera 11).
But when radius is 21 then code are working properly.

Jonathan Puckey

unread,
Jan 26, 2012, 7:55:20 AM1/26/12
to pap...@googlegroups.com
Hi Vladimir,

Could you please post this issue to: http://github.com/paperjs/paper.js/issues

Thanks!

greetings,
Jonathan

Vladimir Kaluga

unread,
Feb 2, 2012, 10:09:48 AM2/2/12
to Paper.js
Hi Jonathan,

Done (http://github.com/paperjs/paper.js/issues/71)

Best,
Vladimir

Kevin Scott

unread,
Sep 2, 2012, 12:25:23 PM9/2/12
to pap...@googlegroups.com
Hey guys, I know (I think) that this is still under active development. Nonetheless, wondering if there's a fix for this issue.

I've attached 'onMouseEnter' and 'onMouseLeave' to my Paths and they work great. However, when I try and create a Text object or Raster object, the mouse listeners on my Paths stop responding.

Has anyone seen this before, or have any work arounds? It looks like mouse functions attached to the stage (like onMouseDrag) continue to work fine.

Thanks everyone!

Kevin

Алексей Пономаренко

unread,
Dec 25, 2012, 5:06:26 AM12/25/12
to pap...@googlegroups.com, thekev...@gmail.com
Hi, this is some bug. I found it very quickly. This events don't consider rotation of items. For exapmle, I draw triangle and rotate it on 180 degrees, but this event "thinks" that triangle rotation angle is 0 degree... Should I write a bug? Sorry for my English :)

воскресенье, 2 сентября 2012 г., 19:25:23 UTC+3 пользователь Kevin Scott написал:

Jürg Lehni

unread,
Dec 25, 2012, 9:40:08 AM12/25/12
to pap...@googlegroups.com, thekev...@gmail.com
Yes, an issue with a little test-case would be good, thanks,

Jürg

Alexey Ponomarenoko

unread,
Dec 26, 2012, 10:47:01 AM12/26/12
to pap...@googlegroups.com, thekev...@gmail.com
Done. I can correct it if it something wrong. 

вторник, 25 декабря 2012 г., 16:40:08 UTC+2 пользователь Jürg Lehni написал:

Alexey Ponomarenoko

unread,
Dec 26, 2012, 11:47:54 AM12/26/12
to pap...@googlegroups.com, thekev...@gmail.com
https://github.com/paperjs/paper.js/issues/151

среда, 26 декабря 2012 г., 17:47:01 UTC+2 пользователь Alexey Ponomarenoko написал:
Reply all
Reply to author
Forward
0 new messages