您的位置:时时app平台注册网站 > 彩世界网址 > jQuery动态效果显示人物结构关系图的方法_jquery

jQuery动态效果显示人物结构关系图的方法_jquery

2019-12-06 10:53

那是一位物关系图,可动态展现,效果十二分奇妙。点击文字可现身动态关系图的改动职能。

jQuery动态效果突显人物结构关系图的章程

   那篇文章首要介绍了jQuery动态效果展现人物结构涉及图的方法,涉及jQuery操作json构造数据及鼠标事件的技术,须要的爱人能够参见下

  那是一位物关系图,可动态体现,效果极其完美。点击文字可现身动态关系图的转移职能。

  ?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

207

208

209

210

211

212

213

214

215

216

217

218

219

220

221

222

223

224

225

226

227

228

229

230

231

232

233

234

235

236

237

238

239

240

241

242

243

244

245

246

247

248

249

250

251

252

253

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Untitled Document</title>

<style>

#box{

width:500px; height:500px;

position: relative

}

.host{

position:absolute;

width:100px; height:50px;

line-height:50px; text-align:center;

color:#000000; background-color:#eeeeee;

border:#000000 1px solid; font-weight:bolder

}

.guest{

position:absolute;

width:80px; height:40px;

line-height:40px;text-align:center;

color: #999999; background-color:#FFFFFF;

border:#000000 1px solid; cursor:pointer

}

.relationship{

position:absolute;

width:60px; height:20px;

color: #aaa; line-height:20px;

font-size:12px; text-align:center

}

</style>

<script src="jquery-1.6.2.min.js"></script>

<script>

var relationName = [

{name:"成龙",friend:[

{name:"房祖名",relationship:"父子"},

{name:"林凤娇",relationship:"夫妻"},

{name:"吴绮莉",relationship:"绯闻"},

{name:"徐静蕾",relationship:"激吻"}]

},

{name:"房祖名",friend:[

{name:"成龙",relationship:"父子"},

{name:"林凤娇",relationship:"母子"},

{name:"方大同",relationship:"情敌"},

{name:"薛凯琪",relationship:"女友"},

{name:"陈坤",relationship:"朋友"},

{name:"赵薇",relationship:"朋友"}]

},

{name:"林凤娇",friend:[

{name:"成龙",relationship:"夫妻"},

{name:"房祖名",relationship:"母子"},

{name:"吴绮莉",relationship:"情敌"}]

},

{name:"吴绮莉",friend:[

{name:"成龙",relationship:"绯闻"},

{name:"林凤娇",relationship:"情敌"},

{name:"吴卓林",relationship:"母女"}]

},

{name:"徐静蕾",friend:[

{name:"李亚鹏",relationship:"电影"},

{name:"韩寒",relationship:"娱乐圈"},

{name:"成龙",relationship:"激吻"},

{name:"黄立行",relationship:"电影"}]

},

{name:"方大同",friend:[

{name:"房祖名",relationship:"情敌"},

{name:"薛凯琪",relationship:"否认拍拖"},

{name:"林宥嘉",relationship:"歌手"},

{name:"韩庚",relationship:"演唱会"}]

},

{name:"薛凯琪",friend:[

{name:"方大同",relationship:"否认拍拖"},

{name:"房祖名",relationship:"女友"}]

}

]

var relation = {

radius:150,

boxW:500,

boxH:500,

hostW:100,

hostH:50,

guestW:80,

guestH:40,

relationW:60,

relationH:20,

angle:0,

id:"box",

init:function(array,n){//传入参数1:数组 参数2:第几个

this.array = array;

this.appendHost(this.array,n);

this.appendQuest(this.array,n);

this.appendRelationShip(this.array,n);

},

appendHost:function(array,n){

var box = $("#" this.id);

var host ="<span class='host'>" array[n].name "</span>";

box.append(host)

this.postHost();

},

postHost:function(){

var x = (this.boxW - this.hostW)/2;

var y = (this.boxH - this.hostH)/2;

$(".host").css({

left:x,

top:y

})

},

appendQuest:function(array,n){

var box = $("#" this.id);

var guests="";

var that = this;

for(var i=0; i<array[n].friend.length; i ){

guests ="<span class='guest'>" array[n].friend[i].name "</span>";

}

$(guests).appendTo(box);

$(".guest").live("click",function(){

that.move(that,this);

})

this.postQuest();

},

postQuest:function(){

var guests = $(".guest");

var that = this;

guests.each(function(i){

guests.eq(i).css({

left:that.setQuestPose(guests.length,that.radius,i,that.guestW,that.guestH,that.angle).left,

top:that.setQuestPose(guests.length,that.radius,i,that.guestW,that.guestH,that.angle).top

}).attr("angle",i/guests.length)

})

},

setQuestPose:function(n,r,i,w,h,d){

//n:代表共几个对象 r代表周长 i代表第几个对象

//w代表外面对象的宽带 h代表外面对象的高度 d代表其实角度

var p = i/n*Math.PI*2 Math.PI*2*d;

var x = r * Math.cos(p);

var y = r * Math.sin(p);

return {

"left":parseInt(this.boxW/2 x - w/2),

"top":parseInt(this.boxH/2 y - h/2)

}

},

appendRelationShip:function(array,n){

var box = $("#" this.id);

var relation="";

for(var i=0; i<array[n].friend.length; i ){

relation ="<span class='relationship'>" array[n].friend[i].relationship "</span>";

}

box.append(relation);

this.postRelationShip();

},

postRelationShip:function(){

var guests = $(".relationship");

var that = this;

guests.each(function(i){

guests.eq(i).css({

left:that.setQuestPose(guests.length,that.radius/2,i,that.relationW,that.relationH,that.angle).left,

top:that.setQuestPose(guests.length,that.radius/2,i,that.relationW,that.relationH,that.angle).top

})

})

},

move:function(t,i){

var n = $(".guest").index($(i));

this.angle = parseFloat($(i).attr("angle")) 0.5;

this.delect(n);

this.moveHost(i);

this.moveQuest(i);

this.moveRelationship(i);

this.changeClass();

setTimeout(function(){t.newAppend(i)},500);

},

newAppend:function(i){

this.newAppendGuest(i,"guest","name",this.guestW,this.guestH,this.radius);

this.newAppendGuest(i,"relationship","relationship",this.relationW,this.relationH,this.radius/2);

},

 

newAppendGuest:function(i,className,name,w,h,r){

var host = $(i).html();

var guest = $(".guest").html();

var box = $("#" this.id);

var that = this;

var next=0;

for(var i=0; i<this.array.length; i ){

if(host == this.array[i].name){

for(var j=0;j<this.array[i].friend.length; j ){

if(guest !== this.array[i].friend[j].name){

next ;

var guests ="<span class='" className "'>" this.array[i].friend[j][name] "</span>";

$(guests).appendTo(box).css({

left:that.setQuestPose(this.array[i].friend.length,r,next,w,h,that.angle).left,

top:that.setQuestPose(this.array[i].friend.length,r,next,w,h,that.angle).top

}).attr("angle",that.angle next/this.array[i].friend.length).hide().fadeIn(1000);

}

}

}

}

},

 

moveHost:function(i){

var hLeft = parseInt($(".host").css("left")) this.hostW/2;

var hTop = parseInt($(".host").css("top")) this.hostH/2;

var gLeft = parseInt($(i).css("left")) this.guestW/2;

var gTop = parseInt($(i).css("top")) this.guestH/2;

var l = gLeft - hLeft;

var t = gTop - hTop;

var left = (hLeft - l - this.guestW/2) "px";

var top = (hTop - t - this.guestH/2) "px";

this.animate(".host",left,top);

},

moveRelationship:function(i){

var hLeft = parseInt($(".host").css("left")) this.hostW/2;;

var hTop = parseInt($(".host").css("top")) this.hostH/2;

var gLeft = parseInt($(".relationship").css("left")) this.relationW/2;

var gTop = parseInt($(".relationship").css("top")) this.relationH/2;

var l = gLeft - hLeft;

var t = gTop - hTop;

var left = (hLeft - l - this.relationW/2) "px";

var top = (hTop - t - this.relationH/2) "px";

this.animate(".relationship",left,top);

},

moveQuest:function(i){

var left = $(".host").css("left");

var top = $(".host").css("top");

this.animate(i,left,top);

},

delect:function(n){

$(".guest").slice(0,n).remove();

$(".guest").slice(1).remove();

$(".relationship").slice(0,n).remove();

$(".relationship").slice(1).remove();

},

animate:function(i,left,top){

$(i).animate({

left:left,

top:top

},500);

},

changeClass:function(){

var that =this;

$(".guest").addClass("abcdef").removeClass("guest");

$(".host").addClass("guest").removeClass("host").attr("angle",that.angle);

$(".abcdef").addClass("host").removeClass("abcdef").attr("angle",null);

}

}

$(document).ready(function(){

relation.init(relationName,0)

})

</script>

</head>

<body>

<div id="box"></div>

</body>

</html>

  希望本文所述对大家的jQuery程序设计具备利于。

那篇文章首要介绍了jQuery动态效果展现人物构造关系图的主意,涉及jQuery操作json构造数据及鼠标事...

正文实例呈报了jQuery动态效果彰显人物结构涉及图的不二秘籍。分享给我们供我们参谋。具体剖析如下:

Untitled Document#box{width:500px; height:500px;position: relative}.host{position:absolute;width:100px; height:50px;line-height:50px; text-align:center;color:#000000; background-color:#eeeeee;border:#000000 1px solid; font-weight:bolder}.guest{position:absolute;width:80px; height:40px;line-height:40px;text-align:center;color: #999999; background-color:#FFFFFF;border:#000000 1px solid; cursor:pointer}.relationship{position:absolute;width:60px; height:20px;color: #aaa; line-height:20px;font-size:12px; text-align:center}var relationName = [ {name:"&#25104;&#40857;",friend:[ {name:"&#25151;&#31062;&#21517;",relationship:"&#29238;&#23376;"}, {name:"&#26519;&#20964;&#23047;",relationship:"&#22827;&#22971;"}, {name:"&#21556;&#32494;&#33673;",relationship:"&#32495;&#38395;"}, {name:"&#24464;&#38745;&#34174;",relationship:"&#28608;&#21563;"}] }, {name:"&#25151;&#31062;&#21517;",friend:[ {name:"&#25104;&#40857;",relationship:"&#29238;&#23376;"}, {name:"&#26519;&#20964;&#23047;",relationship:"&#27597;&#23376;"}, {name:"&#26041;&#22823;&#21516;",relationship:"&#24773;&#25932;"}, {name:"&#34203;&#20975;&#29738;",relationship:"&#22899;&#21451;"}, {name:"&#38472;&#22372;",relationship:"&#26379;&#21451;"}, {name:"&#36213;&#34183;",relationship:"&#26379;&#21451;"}] }, {name:"&#26519;&#20964;&#23047;",friend:[ {name:"&#25104;&#40857;",relationship:"&#22827;&#22971;"}, {name:"&#25151;&#31062;&#21517;",relationship:"&#27597;&#23376;"}, {name:"&#21556;&#32494;&#33673;",relationship:"&#24773;&#25932;"}] }, {name:"&#21556;&#32494;&#33673;",friend:[ {name:"&#25104;&#40857;",relationship:"&#32495;&#38395;"}, {name:"&#26519;&#20964;&#23047;",relationship:"&#24773;&#25932;"}, {name:"&#21556;&#21331;&#26519;",relationship:"&#27597;&#22899;"}] }, {name:"&#24464;&#38745;&#34174;",friend:[ {name:"&#26446;&#20122;&#40527;",relationship:"&#30005;&#24433;"}, {name:"&#38889;&#23506;",relationship:"&#23089;&#20048;&#22280;"}, {name:"&#25104;&#40857;",relationship:"&#28608;&#21563;"}, {name:"&#40644;&#31435;&#34892;",relationship:"&#30005;&#24433;"}] }, {name:"&#26041;&#22823;&#21516;",friend:[ {name:"&#25151;&#31062;&#21517;",relationship:"&#24773;&#25932;"}, {name:"&#34203;&#20975;&#29738;",relationship:"&#21542;&#35748;&#25293;&#25302;"}, {name:"&#26519;&#23461;&#22025;",relationship:"&#27468;&#25163;"}, {name:"&#38889;&#24218;",relationship:"&#28436;&#21809;&#20250;"}] }, {name:"&#34203;&#20975;&#29738;",friend:[ {name:"&#26041;&#22823;&#21516;",relationship:"&#21542;&#35748;&#25293;&#25302;"}, {name:"&#25151;&#31062;&#21517;",relationship:"&#22899;&#21451;"}] }]var relation = { radius:150, boxW:500, boxH:500, hostW:100, hostH:50, guestW:80, guestH:40, relationW:60, relationH:20, angle:0, id:"box", init:function{//&#20256;&#20837;&#21442;&#25968;1&#65306;&#25968;&#32452; &#21442;&#25968;2&#65306;&#31532;&#20960;&#20010; this.array = array; this.appendHost; this.appendQuest; this.appendRelationShip; }, appendHost:function{ var box = $; var host ="&lt;span class='host'&gt;" array[n].name "&lt;/span&gt;"; box.append; }, postHost:function(){ var x = (this.boxW - this.hostW)/2; var y = (this.boxH - this.hostH)/2; $.css }, appendQuest:function{ var box = $; var guests=""; var that = this; for(var i=0; i&lt;array[n].friend.length; i  ){ guests ="&lt;span class='guest'&gt;" array[n].friend[i].name "&lt;/span&gt;"; } $; $.live{ that.move this.postQuest(); }, postQuest:function(){ var guests = $; var that = this; guests.each{ guests.eq.css({ left:that.setQuestPose(guests.length,that.radius,i,that.guestW,that.guestH,that.angle).left, top:that.setQuestPose(guests.length,that.radius,i,that.guestW,that.guestH,that.angle).top }).attr("angle",i/guests.length) }) }, setQuestPose:function{//n:&#20195;&#34920;&#20849;&#20960;&#20010;&#23545;&#35937; r&#20195;&#34920;&#21608;&#38271; i&#20195;&#34920;&#31532;&#20960;&#20010;&#23545;&#35937; //w&#20195;&#34920;&#22806;&#38754;&#23545;&#35937;&#30340;&#23485;&#24102; h&#20195;&#34920;&#22806;&#38754;&#23545;&#35937;&#30340;&#39640;&#24230; d&#20195;&#34920;&#20854;&#23454;&#35282;&#24230; var p = i/n*Math.PI*2 Math.PI*2*d; var x = r * Math.cos; var y = r * Math.sin; return { "left":parseInt, "top":parseInt(this.boxH/2   y - h/2) } }, appendRelationShip:function{ var box = $; var relation=""; for(var i=0; i&lt;array[n].friend.length; i  ){ relation ="&lt;span class='relationship'&gt;" array[n].friend[i].relationship "&lt;/span&gt;"; } box.append; this.postRelationShip(); }, postRelationShip:function(){ var guests = $; var that = this; guests.each{ guests.eq.css({ left:that.setQuestPose(guests.length,that.radius/2,i,that.relationW,that.relationH,that.angle).left, top:that.setQuestPose(guests.length,that.radius/2,i,that.relationW,that.relationH,that.angle).top }) }) }, move:function{ var n = $; this.angle = parseFloat 0.5; this.delect; this.moveQuest; this.moveRelationship; this.changeClass(); setTimeout{t.newAppend; }, newAppend:function{ this.newAppendGuest(i,"guest","name",this.guestW,this.guestH,this.radius); this.newAppendGuest(i,"relationship","relationship",this.relationW,this.relationH,this.radius/2); }, newAppendGuest:function(i,className,name,w,h,r){ var host = $; var guest = $; var box = $; var that = this; var next=0; for(var i=0; i&lt;this.array.length; i  ){ if(host == this.array[i].name){ for(var j=0;j&lt;this.array[i].friend.length; j  ){ if(guest !== this.array[i].friend[j].name){ next  ; var guests ="&lt;span class='" className "'&gt;" this.array[i].friend[j][name] "&lt;/span&gt;"; $.css({ left:that.setQuestPose(this.array[i].friend.length,r,next,w,h,that.angle).left, top:that.setQuestPose(this.array[i].friend.length,r,next,w,h,that.angle).top }).attr("angle",that.angle next/this.array[i].friend.length).hide; } } } } }, moveHost:function{ var hLeft = parseInt.css   this.hostW/2; var hTop = parseInt)   this.hostH/2; var gLeft = parseInt   this.guestW/2; var gTop = parseInt   this.guestH/2; var l = gLeft - hLeft; var t = gTop - hTop; var left = (hLeft - l - this.guestW/2) "px"; var top = (hTop - t - this.guestH/2) "px"; this.animate; }, moveRelationship:function{ var hLeft = parseInt.css   this.hostW/2;; var hTop = parseInt)   this.hostH/2; var gLeft = parseInt.css   this.relationW/2; var gTop = parseInt.css   this.relationH/2; var l = gLeft - hLeft; var t = gTop - hTop; var left = (hLeft - l - this.relationW/2) "px"; var top = (hTop - t - this.relationH/2) "px"; this.animate(".relationship",left,top); }, moveQuest:function{ var left = $; var top = $; this.animate; }, delect:function.slice; $.remove.slice; $.slice; }, animate:function.animate({ left:left, top:top },500); }, changeClass:function(){ var that =this; $.addClass.removeClass.addClass.removeClass.attr; $.addClass.removeClass.attr; }}$.ready{ relation.init

梦想本文所述对我们的jQuery程序设计有着扶助。

本文由时时app平台注册网站发布于彩世界网址,转载请注明出处:jQuery动态效果显示人物结构关系图的方法_jquery

关键词: