最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to change path's width and height drawn by Raphael JS? - Stack Overflow

programmeradmin4浏览0评论

I have path that I then draw with Raphael JS. Code looks like this:

var paper = Raphael($('#draw_here')[0], '32', '32');

var star = paper.path("M 22.137,19.625 32,12 20,12 16,0 12,12 0,12 9.875,19.594 6,32 16.016,24.32 26.008,32 z");

star.attr({
    fill: 'white',
    stroke: 'black',
    title: 'This is a STAAAAAAAR!'
});

It works and it draws 32 x 32 pixels big star. How to change it's width and height?

I tried to do this:

var paper = Raphael($('#draw_here')[0], 64, 64);

var star = paper.path("M 22.137,19.625 32,12 20,12 16,0 12,12 0,12 9.875,19.594 6,32 16.016,24.32 26.008,32 z");

star.attr({
    fill: 'white',
    stroke: 'black',
    title: 'This is a STAAAAAAAR!',
    width: 64,
    height: 64
});

...but all that changes is “paper element's“ width and height, not star's.

The thing I want to do is put effect that star gets bigger when mouse's cursor is on it.

Thanks in any advice!

P.S. I didn't write the path myself, it's get from Iconic set.

I have path that I then draw with Raphael JS. Code looks like this:

var paper = Raphael($('#draw_here')[0], '32', '32');

var star = paper.path("M 22.137,19.625 32,12 20,12 16,0 12,12 0,12 9.875,19.594 6,32 16.016,24.32 26.008,32 z");

star.attr({
    fill: 'white',
    stroke: 'black',
    title: 'This is a STAAAAAAAR!'
});

It works and it draws 32 x 32 pixels big star. How to change it's width and height?

I tried to do this:

var paper = Raphael($('#draw_here')[0], 64, 64);

var star = paper.path("M 22.137,19.625 32,12 20,12 16,0 12,12 0,12 9.875,19.594 6,32 16.016,24.32 26.008,32 z");

star.attr({
    fill: 'white',
    stroke: 'black',
    title: 'This is a STAAAAAAAR!',
    width: 64,
    height: 64
});

...but all that changes is “paper element's“ width and height, not star's.

The thing I want to do is put effect that star gets bigger when mouse's cursor is on it.

Thanks in any advice!

P.S. I didn't write the path myself, it's get from Iconic set.

Share Improve this question asked May 21, 2012 at 7:57 daGrevisdaGrevis 21.3k39 gold badges103 silver badges139 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 7

You have to adjust the path too! Just try it on the Raphaël Playground.

The width and height attributes are just the size of the element to draw on, but the path coordinates are still the same.

For a simple resize you may also use

star.transform("s2");

to resize it to the 2x as before.

If don't want to edit the path and simple scale it, you should use the transform method to resize it and translate the full path by a certain value.

star.transform("t32,32 s2");

This for example will move the object by 32px from the top and 32px from the left and resize it to the 2x as before.

发布评论

评论列表(0)

  1. 暂无评论