RaphaelJS:如果从页面哈希中找到,则更改变量属性
假设我有 var mycircle = paper.circle(0, 0, 20).attr({行程: "#ff0000"});
现在默认情况下,当有人访问我的页面时 www .url.com/index.html
他们得到这个带有红色笔划的圆圈。
但是,如果我想要怎么办 如果浏览时定义了#hash,则更改圆笔画,例如 已做出选择,并且您想将其链接到某人。说某人 现在浏览www.url.com/index.html#mycircle
。
使用: var hash = window.location.hash.substr(1) 我可以使变量哈希返回“mycircle”。
然而,通过做 hash.attr({lines: "#0000ff"});
描边颜色不会变成蓝色!有没有办法解决这个问题,这样我就可以像这样改变圆圈的笔划?
// 编辑
我已经像这样设置了我的圈子:
var name1 = paper.circle(....);
name1.node.id = "name1";
name1.node.name = "Name";
var name2 = paper.circle(....);
name2.node.id = "name2";
name2.node.name = "Another Name";
等等。然后我将它们组合成一个集合:
nodes = paper.set();
nodes.push(name1, name2, name3, name4....);
然后使用 nodes.hover(function() { });
和 nodes.click(function() { });
来定义行动。 name.node.id
用于将正确的信息页面加载到 div 中,而当用户将鼠标悬停在节点上时,name.node.name
会出现在节点上方。
我尝试按照建议重新组织节点:
var mapObjects = {};
mapObjects['name1'] = paper.circle(....);
mapObjects['name1'].node.id = "name1";
mapObjects['name1'].node.name = "Name";
mapObjects['name2'] = paper.circle(....);
mapObjects['name2'].node.id = "name1";
mapObjects['name2'].node.name = "Another Name";
然后,我尝试像以前一样使用函数,只需将节点更改为 mapObjects mapObjects.hover(function() { });
与单击相同。这些已经不起作用了!哈希技术确实有效,所以这是朝着正确方向迈出的一步。现在如何让我的悬停和单击功能正常工作?
Say I have var mycircle = paper.circle(0, 0, 20).attr({stroke: "#ff0000"});
Now by default when someone goes to my page at www.url.com/index.html
they get this circle with the red stroke.
However, what if I wanted
the circle stroke to change if a #hash was defined when browsing, e.g.
a selection was made and you wanted to link it to someone. Say someone
browses to www.url.com/index.html#mycircle
now.
With: var hash = window.location.hash.substr(1)
I can make the variable hash return "mycircle".
However, by doinghash.attr({stroke: "#0000ff"});
the stroke colour wont change to blue! Is there a way around this so I could change the stroke of the circle like so?
// EDIT
I have set up my circles like so:
var name1 = paper.circle(....);
name1.node.id = "name1";
name1.node.name = "Name";
var name2 = paper.circle(....);
name2.node.id = "name2";
name2.node.name = "Another Name";
And so on. Then I have combined them into a set:
nodes = paper.set();
nodes.push(name1, name2, name3, name4....);
I then use nodes.hover(function() { });
and nodes.click(function() { });
to define actions. The name.node.id
is used for loading the right info page into a div while the name.node.name
appears above the node when the user hovers over it.
I tried reorganizing my nodes as suggested:
var mapObjects = {};
mapObjects['name1'] = paper.circle(....);
mapObjects['name1'].node.id = "name1";
mapObjects['name1'].node.name = "Name";
mapObjects['name2'] = paper.circle(....);
mapObjects['name2'].node.id = "name1";
mapObjects['name2'].node.name = "Another Name";
I then tried to use the functions like I did before by simply changing nodes into mapObjects mapObjects.hover(function() { });
same with click. These didn't work anymore! The hash technique worked tho so that's a step to the right direction. How do I get my hover and click functions working now?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
评估会有所帮助,但它会非常脆弱。更好的方法是记住关联数组中的圆:
The eval would help, but it would be very vulnerable. The better way is to remember the circle in associative array: