Pure JS code realizes bubble effect _javascript skill

Source: Internet
Author: User

I will not give you more text description. We'll comb through the key steps.

Key steps:

1, the introduction of JS files

<script type= "Text/javascript" src= "js/jquery.min.js" ></script>
<script type= "Text/javascript" Src= ' Js/jquery.thoughtbubble.js ' ></script>

2, where you need to use the bubble effect

<div id= ' maincontainer ' class= ' container ' > 
</div>

3, the use of bubble effect

<script type= "Text/javascript" >
$ (window). Ready (function () {
$ (' #thoughtBubble '). Thoughtbubble ({
text: ' Baby,i love for You ',
font: ' Avenir '
}
);

4, this is Jquery.thoughtBubblr.js code

(function ($) {$.fn.thoughtbubble = function (defaults) {var settings = $.extend ({backgroundcolor: ' White ', FontColor: "Black", Width: ' 330px ', Height: ' 210px ', FontSize: ' 15px ', Bubblecolor: ' White ', speed:125}, defaults), Getbubblediv = function (container) {var offset = Container.offset (), modifiedheight = Offset.top-parseint (settings.height), Styl E = ' "Position:absolute; Top: ' + modifiedheight + ' px; Left: ' + offset.left + ' px; Width: ' + settings.width + '; Height: ' + settings.height + '; ', Bubblecontainer = ' <div class= ' bubble-holder ' style= ' + style + ' > ' + Getmainbubb
Le () + getbubbles () + "</div>";
return bubblecontainer; }, getmainbubble = function () {return ' <div class= ' main-bubble-holder ' ><div class= ' bubble main-bubble ' > ' + G
Ettext () + ' </div></div> ';  }, GetText = function () {return ' <span style= ' vertical-align:middle; color: ' + Settings.fontcolor + '; font-size: ' + Settings.fontsize + '; font-family: ' + Settings.fonT + ' > ' + settings.text + ' </span> '}, Getbubbles = function () {return ' <div class= ' Sm-bubble-holder ' &GT;&L T;div class= "bubble Bubblelg ></div><div class=" bubble bubblemd "></div><div class=" bubble
Bubblesm "></div></div>"; Animate = function () {var bubbles = $ (document). Find ('. Bubble '), reversed = Bubbles.get (). reverse (), speed = SETTINGS.S
peed; $ (reversed[0]). Stop (). Animate ({opacity:1}, speed, function () {$ (reversed[1)). Animate ({opacity:1}, speed, function ()
{$ (reversed[2]). Animate ({opacity:1}, speed, function () {$ (reversed[3)). Animate ({opacity:1},speed);});};
});  }, Unanimate = function () {var bubbles = $ (document). Find ('. Bubble '); Bubbles.stop (). Animate ({opacity:0});}, Shiftdiv = Function (container) {var Bubbleholder = $ (document). Find ('. Bubble-holder '), previousposition = Container.offset (). lef
T
Bubbleholder.css (' left ', previousposition);
}; Return This.each (function () {var $this = $ (this), container = gEtbubblediv ($this);
$this. On (' MouseEnter ', animate);
$this. On (' Mouseout ', unanimate);
$ (window). On (' Resize ', Shiftdiv.bind (this, $this));
Return $this. Parent (). prepend (container);
});
}; }) (JQuery);

Above to share the JS bubble effect of the key steps, the code is easy to understand, did not write too much text, we have questions welcome to my message, small series will promptly reply to everyone, in this small series also thank you for your support cloud Habitat community site!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.