Home Web Front-end JS Tutorial Detailed explanation of jQuery tip prompt plug-in

Detailed explanation of jQuery tip prompt plug-in

Jan 17, 2018 pm 01:09 PM
jquery hint Detailed explanation

This article mainly introduces the relevant knowledge of jQuery tip plug-in. Has very good reference value. Let's take a look with the editor below, I hope it can help everyone.

Rendering:

The code is as follows:

<!DOCTYPE html> 
<html> 
<head> 
 <meta charset="UTF-8"> 
 <title>document</title> 
 <style> 
  .tip{ 
   width: 200px; 
   text-align: center; 
   position: relative; 
   border:1px solid #ccc; 
   height: 50px; 
   line-height: 50px; 
   left: 50%; 
   margin-top: 50px; 
   transform: translateX(-50%); 
  } 
  .tip-container{ 
   position: absolute; 
   box-shadow: 2px 2px 5px #f9f9f9; 
   z-index: 999; 
   display: none; 
  } 
  .tip-container .tip-point-top, 
  .tip-container .tip-point-bottom, 
  .tip-container .tip-point-left, 
  .tip-container .tip-point-right{ 
   border:1px solid #dcdcdc; 
   position: relative; 
   background: white; 
  } 
  .tip-content{ 
   padding:5px 10px; 
   background: white; 
   font-size: 12px; 
   line-height: 1.7; 
   font-family: "Helvetica Neue",Helvetica,Arial,"MicroSoft YaHei"; 
  } 
  .tip-container .tip-point-top::after, 
  .tip-container .tip-point-top::before, 
  .tip-container .tip-point-bottom::after, 
  .tip-container .tip-point-bottom::before{ 
   content:""; 
   position: absolute; 
   border:solid transparent; 
   left: 50%; 
   width: 0; 
   height: 0; 
   transform: translate3d(-50%,0,0); 
   -webkit-transform: translate3d(-50%,0,0); 
  } 
 
  .tip-container .tip-point-right::after, 
  .tip-container .tip-point-right::before, 
  .tip-container .tip-point-left::after, 
  .tip-container .tip-point-left::before{ 
   content:""; 
   position: absolute; 
   border:solid transparent; 
   top: 50%; 
   width: 0; 
   height: 0; 
   transform: translate3d(0,-50%,0); 
   -webkit-transform: translate3d(0,-50%,0); 
 
  } 
  /*tip-point-top*/ 
  .tip-container .tip-point-top::after{ 
   border-top-color: #fff; 
   top: 100%; 
   border-width: 5px; 
  } 
  .tip-container .tip-point-top::before { 
   border-top-color: #dcdcdc; 
   top: 100%; 
   border-width: 7px; 
  } 
  /*tip-point-bottom*/ 
  .tip-container .tip-point-bottom::after{ 
   border-bottom-color: #fff; 
   bottom: 100%; 
   border-width: 5px; 
  } 
  .tip-container .tip-point-bottom::before { 
   border-bottom-color: #dcdcdc; 
   bottom: 100%; 
   border-width: 7px; 
  } 
  /*tip-point-right*/ 
  .tip-container .tip-point-right::after{ 
   border-right-color: #fff; 
   right: 100%; 
   border-width: 5px; 
  } 
  .tip-container .tip-point-right::before { 
   border-right-color: #dcdcdc; 
   right: 100%; 
   border-width: 7px; 
  } 
  /*tip-point-left*/ 
  .tip-container .tip-point-left::after{ 
   border-left-color: #fff; 
   left: 100%; 
   border-width: 5px; 
  } 
  .tip-container .tip-point-left::before { 
   border-left-color: #dcdcdc; 
   left: 100%; 
   border-width: 7px; 
  } 
 </style> 
</head> 
<body> 
<p data-tip="寂寞的天下着忧郁的雨" data-mode="top">天堂不寂寞</p> 
<p data-tip="天堂不寂寞" data-mode="bottom">寂寞的天下着忧郁的雨</p> 
<p data-tip="寂寞的天下着忧郁的雨" data-mode="right">寂寞的天下着忧郁的雨</p> 
<p data-tip="天堂不寂寞" data-mode="left">寂寞的天下着忧郁的雨</p> 
<script src="http://libs.baidu.com/jquery/2.0.0/jquery.js"></script> 
<script> 
 /** 
  * Created by zxhuan (you@example.com) 
  * Date: 2016/11/28 
  * Time: 11:14 
  */ 
 ; 
 (function ($,window,document,undefined) { 
  var modePos; 
  $.fn.tip = function (options) { 
   var set = $.extend({ 
    "mode": "bottom", 
    "speed": 300, 
    "tipText":"提示内容" 
   }, options); 
   if(!modePos){ 
    //策略模式 
    //算法 
    modePos = { 
     top: function (t, tip) { 
      return { 
       left: t.offset().left + (t.width() - tip.width()) / 2 + "px", 
       top: t.offset().top - tip.height() - 12 + "px" 
      } 
     }, 
     bottom:function(t, tip){ 
      return { 
       left: this.top(t, tip).left, 
       top: t.offset().top + t.height() + 12 + "px" 
      } 
     }, 
     left:function(t, tip){ 
      return{ 
       left:t.offset().left - tip.width()-12+ "px", 
       top:t.offset().top +(t.height()-tip.height())/2+"px" 
      } 
     }, 
     right:function(t, tip){ 
      return{ 
       left:t.offset().left +t.width()+12+ "px", 
       top:t.offset().top +(t.height()-tip.height())/2+"px" 
      } 
     } 
    }; 
   } 
   function Tip(_this){ 
    var _that = $(_this); 
    var _mode = set.mode; 
    var tipText=set.tipText; 
    var _tip=".tip-container"; 
    if (_that.data("mode")) { 
     _mode = _that.data("mode"); 
    } 
    if(_that.data("tip")){ 
     tipText = _that.data("tip"); 
    } 
    _that.css("cursor", "pointer"); 
    _that.hover(function () { 
     var _tipHtml = &#39;<p><p class="tip-point-&#39; + _mode + &#39;"><p>&#39; + tipText + &#39;</p></p></p>&#39;; 
     _that.removeAttr("title alt"); 
     $("body").append(_tipHtml); 
     $(_tip).css(modePos[_mode](_that,$(_tip))).fadeIn(set.speed); 
    }, function () { 
     $(".tip-container").remove(); 
    }); 
   } 
   return this.each(function () { 
    return new Tip(this); 
   }); 
  } 
 })(jQuery,window,document); 
 $(".tip").tip(); 
</script> 
</body> 
</html>
Copy after login

Related recommendations:

Summary of Vue component implementation tips

Detailed explanation of examples of several small tips in css

Summary of tips in PHP development

The above is the detailed content of Detailed explanation of jQuery tip prompt plug-in. For more information, please follow other related articles on the PHP Chinese website!

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)

What should I do if Google Chrome prompts that the content of this tab is being shared? What should I do if Google Chrome prompts that the content of this tab is being shared? Mar 13, 2024 pm 05:00 PM

What should I do if Google Chrome prompts that the content of this tab is being shared? When we use Google Chrome to open a new tab, we sometimes encounter a prompt that the content of this tab is being shared. So what is going on? Let this site provide users with a detailed introduction to the problem of Google Chrome prompting that the content of this tab is being shared. Google Chrome prompts that the content of this tab is being shared. Solution: 1. Open Google Chrome. You can see three dots in the upper right corner of the browser "Customize and control Google Chrome". Click the icon with the mouse to change the icon. 2. After clicking, the menu window of Google Chrome will pop up below, and the mouse will move to "More Tools"

Detailed explanation of obtaining administrator rights in Win11 Detailed explanation of obtaining administrator rights in Win11 Mar 08, 2024 pm 03:06 PM

Windows operating system is one of the most popular operating systems in the world, and its new version Win11 has attracted much attention. In the Win11 system, obtaining administrator rights is an important operation. Administrator rights allow users to perform more operations and settings on the system. This article will introduce in detail how to obtain administrator permissions in Win11 system and how to effectively manage permissions. In the Win11 system, administrator rights are divided into two types: local administrator and domain administrator. A local administrator has full administrative rights to the local computer

Detailed explanation of division operation in Oracle SQL Detailed explanation of division operation in Oracle SQL Mar 10, 2024 am 09:51 AM

Detailed explanation of division operation in OracleSQL In OracleSQL, division operation is a common and important mathematical operation, used to calculate the result of dividing two numbers. Division is often used in database queries, so understanding the division operation and its usage in OracleSQL is one of the essential skills for database developers. This article will discuss the relevant knowledge of division operations in OracleSQL in detail and provide specific code examples for readers' reference. 1. Division operation in OracleSQL

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

Detailed explanation of the role and usage of PHP modulo operator Detailed explanation of the role and usage of PHP modulo operator Mar 19, 2024 pm 04:33 PM

The modulo operator (%) in PHP is used to obtain the remainder of the division of two numbers. In this article, we will discuss the role and usage of the modulo operator in detail, and provide specific code examples to help readers better understand. 1. The role of the modulo operator In mathematics, when we divide an integer by another integer, we get a quotient and a remainder. For example, when we divide 10 by 3, the quotient is 3 and the remainder is 1. The modulo operator is used to obtain this remainder. 2. Usage of the modulo operator In PHP, use the % symbol to represent the modulus

Baidu Tieba app prompts that the operation is too frequent, what's the matter? Baidu Tieba app prompts that the operation is too frequent, what's the matter? Apr 01, 2024 pm 05:06 PM

Baidu Tieba app prompts that the operation is too frequent. This prompt is usually to maintain the normal operation and user experience of the platform to prevent malicious screen spam, advertising spam and other inappropriate behaviors. For specific handling methods, you can read the tutorial shared by the editor. Baidu Tieba app prompts that the operation is too frequent. Sharing how to deal with it 1. When the system prompts [Operation is too frequent], we need to wait for a while. If you are anxious, you can do something else first. Generally, after waiting for a while, this prompt message will It will disappear automatically and we can use it normally. 2. If after waiting for a long time, it still displays [Operation Too Frequent], we can try to go to Tieba Emergency Bar, Tieba Feedback Bar and other official Tieba, post to report this phenomenon and ask official personnel to solve it. 3.

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:

See all articles