gpt4 book ai didi

html - KineticJS集团

转载 作者:行者123 更新时间:2023-11-27 22:32:29 25 4
gpt4 key购买 nike

我正在用 HTML5 制作交互式世界地图。我正在使用 KineticJS 创建国家的多边形,我目前有澳大利亚和新西兰。但是我想要它,所以如果鼠标悬停在澳大利亚或新西兰上,它们都会突出显示。我不知道如何在 KineticJS 中使用组,但这是我尝试的方式(我使用省略号作为点,因为有很多坐标):

<!DOCTYPE HTML>
<html>
<head>
<style>
body {
margin: 0px;
padding: 0px;
}
#container {
background-image: url('world_map.png');
width: 1026px;
height: 540px;
}
</style>
</head>
<body>
<div id="container"></div>
<script src="http://d3lp1msu2r81bx.cloudfront.net/kjs/js/lib/kinetic-v4.5.2.min.js"> </script>
<script defer="defer">
var stage = new Kinetic.Stage({
container: 'container',
width: 1026,
height: 540
});

var layer = new Kinetic.Layer();

var nznorth = new Kinetic.Polygon({
points: [...],
fill: '#ffffff',
stroke: 'black',
strokeWidth: 1
});

var nzsouth = new Kinetic.Polygon({
points: [...],
fill: '#ffffff',
stroke: 'black',
strokeWidth: 1
});

var ausmain = new Kinetic.Polygon({
points: [...],
fill: '#ffffff',
stroke: 'black',
strokeWidth: 1
});

var aus = new Kinetic.Group();
aus.add(ausmain);
aus.add(nznorth);
aus.add(nzsouth);

aus.on('mouseover', function() {
this.setFill('blue');
layer.draw();
});

aus.on('mouseout', function() {
this.setFill('#ffffff');
layer.draw();
});

layer.add(aus);
stage.add(layer);

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

我应该如何在 KineticJS 中实现组?

最佳答案

你即将拥有它!

当您处理鼠标事件时,在澳大利亚和新西兰都设置填充 — 而不是在组上。

group.on("mouseover",function(){
australia.setFill("blue");
newzealand.setFill("blue");
layer.draw();
console.log("over");
});

group.on("mouseout",function(){
australia.setFill("skyblue");
newzealand.setFill("skyblue");
layer.draw();
console.log("out");
});

这是代码和 fiddle :http://jsfiddle.net/m1erickson/LXvkg/

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Prototype</title>
<script type="text/javascript" src="http://code.jquery.com/jquery.min.js"></script>
<script src="http://d3lp1msu2r81bx.cloudfront.net/kjs/js/lib/kinetic-v4.5.1.min.js"></script>

<style>
#container{
border:solid 1px #ccc;
margin-top: 10px;
}
</style>
<script>
$(function(){

var stage = new Kinetic.Stage({
container: 'container',
width: 400,
height: 400
});
var layer = new Kinetic.Layer();
stage.add(layer);
stage.draw();

var group=new Kinetic.Group();
layer.add(group);

var australia = new Kinetic.Rect({
x: 20,
y: 20,
width: 150,
height: 100,
fill: "skyblue",
stroke: "lightgray",
strokeWidth: 3
});
group.add(australia);

var newzealand = new Kinetic.Rect({
x: 250,
y: 110,
width: 20,
height: 50,
fill: "skyblue",
stroke: "lightgray",
strokeWidth: 3
});
group.add(newzealand);

layer.draw();

group.on("mouseover",function(){
australia.setFill("blue");
newzealand.setFill("blue");
layer.draw();
console.log("over");
});

group.on("mouseout",function(){
australia.setFill("skyblue");
newzealand.setFill("skyblue");
layer.draw();
console.log("out");
});



}); // end $(function(){});

</script>
</head>

<body>
<div id="container"></div>
</body>
</html>

关于html - KineticJS集团,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16738297/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com