Home Web Front-end JS Tutorial Jquery implements broadcasting imitating Tencent Weibo_jquery

Jquery implements broadcasting imitating Tencent Weibo_jquery

May 16, 2016 pm 04:31 PM
jquery broadcast

Preface: Since I have been learning some knowledge about Jquery these days, I feel that Jquery is too powerful than before. Many simple functions used to require dozens of lines of code in JavaScript but only use a few lines of code in Jquery. That’s it, so I decided to study Jquery hard. Please support me. Haha, learning Jquey these days has made me feel that it is not difficult to use Jquery. I feel that Jquery only needs to learn the selector. The basics can be easily solved, learn more about some methods, events, etc. So I implemented a Jquery here to imitate Tencent's meager broadcast publishing.

1. First create a new HTML page and introduce what function I want to achieve

(1) Create a new HTML page as follows

(2) The first function, when the mouse slides over the broadcast image, it will turn into another picture with a lighter color, and it will return to the original state when leaving it

(3) The second function is that when you enter text into the text input box and do not enter a word, the number of words indicated at the bottom is reduced by 1. If it exceeds the number, the user will be prompted how many words have been exceeded

(4) The third function is to click the topic button. If the text box is empty, #Please enter topic information # will be entered, and please enter the topic information to highlight. If the text box is not empty, nothing will be displayed. Do not enter

(5) The fourth function is that when a friend is clicked, a layer will be generated underneath to display the user’s friends. When the user clicks a friend, the name will be displayed in the text box

(6) The fifth function, when the user clicks on the emoticon, the commonly used emoticons of QQ will be displayed, and then the user can select the emoticon to click and display in the text box. This is basically the same as the fourth function, as follows The functions are described below

2. The first function

 (1) Function display diagram

Since this is just a simple sliding effect, the screenshot does not look obvious, so I only posted the code

 (2) Code

Copy code The code is as follows:

//Realize the change reaction of moving the picture up and down
  $("#sendBox :button.sendBtn").mouseover(function () {
   $(this).css("backgroundPosition", "0 -196px");
  }).mouseout(function () {
​​ $(this).css("backgroundPosition", "-117px -165px");
  });

3. The second function

 (1) Function screenshots

 

 (2) Code

Copy code The code is as follows:

//Realize changes in the number of input characters
  $("#msgTxt").change(function () {
​var world = $("#msgTxt").val();
var length = 140 - world.length;
​if (length < 0) {
$("#sendBox span.countTxt").html("You have exceeded " Math.abs(length) " words");
}else {
​$("#sendBox span.countTxt").html("You can also enter " length "words");
}
});
​ setInterval(function () {
​$("#msgTxt").change();
}, 20);

4. The third function

 (1) Function screenshots

 

 (2)Code

Copy code The code is as follows:

//Confirm the text of the output information (please enter the topic information to display in red)
/*
​​Extend a method for selecting text for jQuery
*/
$.fn.selectRange = function (start, end) {
        var curObj = $(this).get(0);
            if (!curObj) return;
            else if (curObj.setSelectionRange) {
                                 curObj.focus();
                 curObj.setSelectionRange(start, end);
             } /* WebKit */
            else if (curObj.createTextRange) {
            var range = curObj.createTextRange();
                 range.collapse(true);
                 range.moveEnd('character', end);
                 range.moveStart('character', start);
                  range.select();
                         /* IE */
             else if (curObj.selectionStart) {
alert('aaaaaaaa');
CurObj.selectionStart = start;
CurObj.selectionEnd = end;
          }
};
//Click topic output#Please enter topic information#
​​​ $("#funBox a.creatNew").click(function () {
If ($.trim($("#msgTxt").val()).length == 0) {
                 $("#msgTxt").val("#Please enter topic information#").selectRange(1, 8);
         }
});

5. The fourth function

 (1) Function screenshots

 

 (2)Code

Copy code The code is as follows:

//Realize the display of friend information when clicking the friend button
var friendList = ["Dai Zhong", "Xiao Meng", "Ren Shoulong", "Dai Wei", "Maria", "Han Yinglong", "Sheng Jingheng", "Feifei", "Xiao Xian", " Yuanfang"];
$("#funBox a.atSome").click(function () {
//The div layer with id as level defined above is position:absolution
$("
    ").appendTo("#funBox");
    //Use $.each to loop through the array values ​​and add them to the layer
    If ($("#level").text() == "") {
                       $.each(friendList, function () {
    //Traverse and add li style transformation to the layer
    $("
  • @" this "
  • ").css("cursor", "pointer").mouseover(function () {
                    $(this).css("backgroundColor", "yellow").siblings().css("backgroundColor", "white");
                    }).appendTo($("#ul")).click(function () {
    //When implementing the click style, write the value to
                   $("#msgTxt").val($("#msgTxt").val() $(this).text());
                })
             })
    };
    //How to determine whether a user clicked a button
    $("#level").mouseleave(function () {
    ​​​​​ $("#level").remove();
    })
    //Place the location of the created module
    $("#level").css("top", $(this).offset().top $(this).height "px").css("left", $(this).offset(). left "px");
    });

    6. The fifth function

     (1) Function screenshots

     

     (2)Code

    Copy code The code is as follows:

    //Realize the function of QQ emoticons
    var userFaces = { '0.gif': 'smile', '1.gif': 'lip', '2.gif': 'color', '3.gif': 'daze', '4.gif': 'Proud', '5.gif': 'Crying', '6.gif': 'Shy', '7.gif': 'Shut up', '8.gif': 'Sleep', '9.gif' : 'crying', '10.gif': 'embarrassed', '11.gif': 'angry', '12.gif': 'naughty', '13.gif': 'baring teeth', '14. gif': 'surprised', '15.gif': 'sad', '16.gif': 'cool', '17.gif': 'cold sweat', '18.gif': 'crazy', '19 .gif': 'vomit', '20.gif': 'smirk', '21.gif': 'cute', '22.gif': 'eye roll', '23.gif': 'arrogant', ' 24.gif': 'hungry', '25.gif': 'sleepy', '26.gif': 'frightened', '27.gif': 'sweating', '28.gif': 'silly laughter', '29.gif': 'Soldier', '30.gif': 'Struggle', '31.gif': 'Swear', '32.gif': 'Question', '33.gif': 'Hush', '34.gif': 'faint', '35.gif': 'torture', '36.gif': 'degeneration', '37.gif': 'skeleton', '38.gif': 'beat', '39.gif': 'Goodbye', '40.gif': 'Wipe sweat', '41.gif': 'Pick your nose', '42.gif': 'Applause', '43.gif': 'Embarrassment' Big', '44.gif': 'Smirk', '45.gif': 'Left humming', '46.gif': 'Right humming', '47.gif': 'Yawn', ' 48.gif': 'contempt', '49.gif': 'grievance', '50.gif': 'almost crying', '51.gif': 'insidious', '52.gif': 'kiss ', '53.gif': 'Scary', '54.gif': 'Poor', '55.gif': 'Chopper', '56.gif': 'Watermelon', '57.gif': 'Beer ', '58.gif': 'Basketball', '59.gif': 'Ping Pong', '60.gif': 'Coffee', '61.gif': 'Rice', '62.gif': 'Pig Head ', '63.gif': 'Rose', '64.gif': 'Wither', '65.gif': 'Show love', '66.gif': 'Love', '67.gif': 'Heart Broken', '68.gif': 'Cake', '69.gif': 'Lightning', '70.gif': 'Bomb', '71.gif': 'Knife', '72.gif': ' Football', '73.gif': 'Ladybug', '74.gif': 'Poop', '75.gif': 'Moon', '76.gif': 'Sun', '77.gif': 'gift', '78.gif': 'hug', '79.gif': 'strong', '80.gif': 'weak', '81.gif': 'handshake', '82.gif': 'Victory', '83.gif': 'Fist', '84.gif': 'Seduce', '85.gif': 'Fist', '86.gif': 'Poor', '87.gif': 'Love you', '88.gif': 'NO', '89.gif': 'OK', '90.gif': 'Love', '91.gif': 'Blow a kiss', '92.gif' : 'jumping', '93.gif': 'trembling', '94.gif': 'burning', '95.gif': 'turning in circles', '96.gif': 'kowtow', '97. gif': 'turn back', '98.gif': 'skipping rope', '99.gif': 'waving', '100.gif': 'excited', '101.gif': 'street dance', '102. gif': 'Kiss', '103.gif': 'Left Tai Chi', '104.gif': 'Right Tai Chi', '105.gif': 'Calm', '106.gif': 'Dizzy', '107.gif': 'dissatisfaction', '108.gif': 'sleep', '109.gif': 'naughty', '110.gif': 'cursing', '111.gif': 'angry' , '112.gif': 'laughing', '113.gif': 'smiling', '114.gif': 'shocked', '115.gif': '囧' };
    $("#funBox a.insertFace").click(function () {
    $("
    ").appendTo("#funBox");
    $.each(userFaces, function (key, value) {
    $("").css("cursor", "pointer").appendTo("#Userfaces").click(function () {
             $("#msgTxt").val($("#msgTxt").val() "[" $(this).attr("title") "]");
    });
    });
    //Same as above, how to determine whether a user clicked a button
    $("#Userfaces").mouseleave(function () {
              $("#Userfaces").remove();
    });
    //Placement
    $("#Userfaces").css("top", $(this).offset().top $(this).height "px").css("left", $(this).offset(). left "px");
    });

    Alright, we have all the functions we should have. As for beautification, friends can do it by themselves

    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

    AI Hentai Generator

    AI Hentai Generator

    Generate AI Hentai for free.

    Hot Article

    R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
    3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
    R.E.P.O. Best Graphic Settings
    3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
    R.E.P.O. How to Fix Audio if You Can't Hear Anyone
    3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

    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)

    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 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

    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

    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

    In-depth analysis: jQuery's advantages and disadvantages In-depth analysis: jQuery's advantages and disadvantages Feb 27, 2024 pm 05:18 PM

    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,

    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