


How to display character structure relationship diagram with jQuery dynamic effect_jquery
The example in this article describes the method of displaying the character structure relationship diagram with jQuery dynamic effects. Share it with everyone for your reference. The specific analysis is as follows:
This is a character relationship diagram that can be displayed dynamically and the effect is very beautiful. Click on the text to display the conversion effect of the dynamic relationship diagram.
<!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>
I hope this article will be helpful to everyone’s jQuery programming.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Detailed explanation of jQuery reference method: Quick start guide jQuery is a popular JavaScript library that is widely used in website development. It simplifies JavaScript programming and provides developers with rich functions and features. This article will introduce jQuery's reference method in detail and provide specific code examples to help readers get started quickly. Introducing jQuery First, we need to introduce the jQuery library into the HTML file. It can be introduced through a CDN link or downloaded

How to use PUT request method in jQuery? In jQuery, the method of sending a PUT request is similar to sending other types of requests, but you need to pay attention to some details and parameter settings. PUT requests are typically used to update resources, such as updating data in a database or updating files on the server. The following is a specific code example using the PUT request method in jQuery. First, make sure you include the jQuery library file, then you can send a PUT request via: $.ajax({u

jQuery is a fast, small, feature-rich JavaScript library widely used in front-end development. Since its release in 2006, jQuery has become one of the tools of choice for many developers, but in practical applications, it also has some advantages and disadvantages. This article will deeply analyze the advantages and disadvantages of jQuery and illustrate it with specific code examples. Advantages: 1. Concise syntax jQuery's syntax design is concise and clear, which can greatly improve the readability and writing efficiency of the code. for example,

How to remove the height attribute of an element with jQuery? In front-end development, we often encounter the need to manipulate the height attributes of elements. Sometimes, we may need to dynamically change the height of an element, and sometimes we need to remove the height attribute of an element. This article will introduce how to use jQuery to remove the height attribute of an element and provide specific code examples. Before using jQuery to operate the height attribute, we first need to understand the height attribute in CSS. The height attribute is used to set the height of an element

Title: jQuery Tips: Quickly modify the text of all a tags on the page In web development, we often need to modify and operate elements on the page. When using jQuery, sometimes you need to modify the text content of all a tags in the page at once, which can save time and energy. The following will introduce how to use jQuery to quickly modify the text of all a tags on the page, and give specific code examples. First, we need to introduce the jQuery library file and ensure that the following code is introduced into the page: <

Title: Use jQuery to modify the text content of all a tags. jQuery is a popular JavaScript library that is widely used to handle DOM operations. In web development, we often encounter the need to modify the text content of the link tag (a tag) on the page. This article will explain how to use jQuery to achieve this goal, and provide specific code examples. First, we need to introduce the jQuery library into the page. Add the following code in the HTML file:

How to tell if a jQuery element has a specific attribute? When using jQuery to operate DOM elements, you often encounter situations where you need to determine whether an element has a specific attribute. In this case, we can easily implement this function with the help of the methods provided by jQuery. The following will introduce two commonly used methods to determine whether a jQuery element has specific attributes, and attach specific code examples. Method 1: Use the attr() method and typeof operator // to determine whether the element has a specific attribute

jQuery is a popular JavaScript library that is widely used to handle DOM manipulation and event handling in web pages. In jQuery, the eq() method is used to select elements at a specified index position. The specific usage and application scenarios are as follows. In jQuery, the eq() method selects the element at a specified index position. Index positions start counting from 0, i.e. the index of the first element is 0, the index of the second element is 1, and so on. The syntax of the eq() method is as follows: $("s
