Home Web Front-end JS Tutorial jQuery dynamic cloud tag plug-in_jquery

jQuery dynamic cloud tag plug-in_jquery

May 16, 2016 pm 04:31 PM
jquery dynamic

Foreword:

Recently, I am particularly interested in the plug-in encapsulation of js. With the current technology, it is still difficult to completely encapsulate js, so I encapsulated a small plug-in based on jQuery, and it was developed based on the object level. Not adding a global method. There is almost no advanced syntax. There is a return: foreach() method to return the object instance itself, and an extend() function to extend the properties of the parameter object. This is also to facilitate the chaining of the object after adjusting my method. type operation.

Plug-in package download address: Click here to download

Plug-in name: Dynamic Cloud Tag

Plug-in features:

Dynamicly generate a tag within the specified block-level element
The height, width, position, number of layers, and background color of the a label are randomly controllable
The a label fades in and out, and the initial transparency can be changed
The speed of a label creation and movement speed are controllable (timer)
The step size of a label movement can be controlled (distance moved in each cycle)
When the mouse is hovering, the animation will be stopped with maximum transparency and the highest number of layers. When the mouse leaves, the previous state will be restored
Encountering a problem:

At present, the plug-in can run normally, but if you switch the browser tab and the plug-in page is not displayed, and then switch back after a while, there will be a lag. I don’t know what the situation is yet. Please give me some advice if you know more about it. , there are a lot of areas that need to be optimized. If you have any good ideas, please bring them up so that I can make corrections in a timely manner.

Animation effect:

Khan: The gif image may be a bit big and will move after a while. Be patient

JS code snippet:

Copy code The code is as follows:

(function($){
$.fn.activiTag = function(opts) {
         opts = $.extend({
             move_step:2, // element movement step size--px
             move_speed:40, // Element movement speed--ms
               init_speed:1000,//Element creation speed--ms
                                                                                                                                                          min_opacity:0,                max_grain: 10, // Maximum grain size
// A label array > a_List: ["Please add elements","Spring Jpa detailed explanation","javamailmail"], // a tag string array
                        // Background color array
            color_List: ['#CD2626','#8b4513','#696969','#ff8c00','#6495ED']                                                                                                                                      ;            },opts||{});
                             
        var aTag = $(this); // Current container object
        var T_width = aTag.width(), T_height = aTag.height(); // Container height, width
                             
         return this.each(function(){
                                                                      Function settatagcss () {// Set the corresponding CSS
               aTag.css({position:'relative',overflow:'hidden'});
            }
                                                                                       function getRandomNum(Min, Max){ // Get random numbers within two intervals
Min = new Number(Min);Max = new Number(Max);
              var Range = Max - Min 1;
              var Rand = Math.random();
                    return Min Math.floor(Rand * Range);
            }
                                                                      Function getrandomxy (num) {// Randomly return a positive/negative parameter
                  num = new Number(num);                              If(Math.random()<=0.5)
                num = -num;
                        return num;
            }
                                                                                     /**
* Randomly create a tag with a width of one-third of the width of the container, and then based on itself - one-fifth of the width
                 * Height is one-third of its own width, then - one-third
                               */
              function createATag() {
              var i = getRandomNum(0,opts.a_List.length-1);
              var a = $(opts.a_List[i]);               aTag.append(a);
                      return a;
            }
                                                                                     /**Set a tag css style **/
              function setCss(a) {
              var w = Math.ceil(T_width/3) getRandomXY(T_width/60);
                     var h = Math.ceil(w/3) getRandomXY(w/36); // Row height
                    var zIndex = Math.ceil(Math.random()*400);               var rdmOpcy = getRandomNum(new Number(opts.min_opacity),0);
// Line height, number of layers, transparency
a.css({
                  opacity:rdmOpcy,
                     zIndex: zIndex,
                       lineHeight:h 'px',
position: 'absolute',
                       textDecoration:'none',
                        textAlign:'center',
                       borderRadius: '3px',
                     color:'#FFFFFF',
                      whiteSpace: 'nowrap',
                });
                      return a;
            }
                                                                                     /**Calculate the initial position of the label relative to the container (X_Y coordinates) **/
              function setXY(a) {
              var x = getRandomNum(0,(T_width-a.width()));
                var y = getRandomNum(0,T_height/10);
                a.css({left:x 'px', bottom:y 'px'});
                      return a;
            }
                                                                                     /**Set random background color **/
              function setColor(a) {
            var i = Math.ceil(Math.random()*opts.color_List.length -1);
a.css({backgroundColor:opts.color_List[i]})
            }
                                                                                     /**Constructor entry **/
             function construct() {
            var a = createATag();
                      setCss(a);                    setColor(a); // color
                     setXY(a);                       return a;
            }
                                                                                     /**Animation timer function **/
              function interVal(a,s_opcy,botm,n,space,s) {
              var opcy = a.css('opacity'); // Transparency
                  var botm_ = a.css('bottom').replace('px',''); // Real-time bottom distance
              var opcy_ = parseFloat(new Number(a.css('opacity'))) s_opcy; // Transparency
                   var _opcy_ = parseFloat(new Number(a.css('opacity'))) - s_opcy; // --Transparency
                     var fall = botm_ - botm; // Moved distance
                         botm_ = new Number(botm_) new Number(opts.move_step);
a.css({
                      display: 'block',
                    bottom: botm_,
                });
                                                                        If(fall < n)
{A.CSS ({OPACITY: OPCY_})}
                         else if(2*n < fall)
                                                                                                                                   ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,                                                                           If (botm_ >= space)
                                                {
                                                                                                                                                                                                                                                                                                                   a.remove();
                }
            }
                                                                                    function init() {
If(aTag.children('a').length >= new Number(opts.max_grain))
Return;
            var a = construct();
              var opcy = a.css('opacity'); // Transparency
              var zInx = a.css('zIndex');               var botm = a.css('bottom').replace('px',''); // Initial distance to bottom
                 var space = T_height - a.height() - a.css('bottom').replace('px',''); // Distance to move
                                                                                        var n = space/3;               var step = 1-opcy;                     var sec = n/opts.move_step*opts.move_speed/1000; // Distance/single step length * single step length seconds = number of seconds required
                   var s_opcy = opts.move_speed/1000/sec * step; // The transparency value that needs to be transformed in each loop
            var speed_ = getRandomNum(new Number(opts.move_speed)-30,new Number(opts.move_speed) 30);
Var Curropcy; // Record the transparency when the mouse is moved
//                     console.log(opts.move_speed '....' speed_)
                     /**Element movement loop **/
              var s = setInterval(function(){
                          interVal(a,s_opcy,botm,n,space,s);
                  }, speed_)
                                                                        A.Mouseover (function () {// mouse moves
                currOpcy = a.css('opacity');
                                                                                                                                                                                                                                                                                                $(this).css({
                          zIndex: 401,
Opacity: 1
                     });
                });
                                                                                         a.mouseout(function(){ // Mouse out
$(this).css({
                        zIndex: zInx,
Opacity: currOpcy
                     });
                     s= setInterval(function(){
                               interVal(a,s_opcy,botm,n,space,s);
                          },speed_);
                });
            }
                setATagCss();
               setInterval(init,opts.init_speed);
        });
}
})(jQuery)



HTML:


Copy code

The code is as follows:

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


云动态标签生成插件


<script><br> $(function(){<br>     $('#tag').activiTag({});<br> });<br> </script>



   



Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Convert VirtualBox fixed disk to dynamic disk and vice versa Convert VirtualBox fixed disk to dynamic disk and vice versa Mar 25, 2024 am 09:36 AM

When creating a virtual machine, you will be asked to select a disk type, you can select fixed disk or dynamic disk. What if you choose fixed disks and later realize you need dynamic disks, or vice versa? Good! You can convert one to the other. In this post, we will see how to convert VirtualBox fixed disk to dynamic disk and vice versa. A dynamic disk is a virtual hard disk that initially has a small size and grows in size as you store data in the virtual machine. Dynamic disks are very efficient at saving storage space because they only take up as much host storage space as needed. However, as disk capacity expands, your computer's performance may be slightly affected. Fixed disks and dynamic disks are commonly used in virtual machines

Detailed explanation of jQuery reference methods: Quick start guide Detailed explanation of jQuery reference methods: Quick start guide Feb 27, 2024 pm 06:45 PM

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? How to use PUT request method in jQuery? Feb 28, 2024 pm 03:12 PM

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

How to remove the height attribute of an element with jQuery? How to remove the height attribute of an element with jQuery? Feb 28, 2024 am 08:39 AM

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

jQuery Tips: Quickly modify the text of all a tags on the page jQuery Tips: Quickly modify the text of all a tags on the page Feb 28, 2024 pm 09:06 PM

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: &lt

Use jQuery to modify the text content of all a tags Use jQuery to modify the text content of all a tags Feb 28, 2024 pm 05:42 PM

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? How to tell if a jQuery element has a specific attribute? Feb 29, 2024 am 09:03 AM

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

Understand the role and application scenarios of eq in jQuery Understand the role and application scenarios of eq in jQuery Feb 28, 2024 pm 01:15 PM

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

See all articles