Pure JS Code implements bubble effect, js Code bubble

Source: Internet
Author: User

Pure JS Code implements bubble effect, js Code bubble

I will not explain it to anyone. Let's sort out the key steps.

Key steps:

1. Introduce js files

<script type="text/javascript" src="js/jquery.min.js"></script><script type="text/javascript" src='js/jquery.thoughtBubble.js'></script>

2. Where bubble effects need to be used

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

3. Use bubble effect

<script type="text/javascript">$(window).ready( function() {$('#thoughtBubble').thoughtBubble({text: 'baby,I love you',font: 'avenir'});});

4. This is the 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 ),style = '"position: absolute; top:' + modifiedHeight + 'px; left:' + offset.left + 'px ; width:' + settings.width + '; height:' + settings.height + ';"',bubbleContainer = "<div class='bubble-holder' style=" + style + ">" + getMainBubble() + getBubbles() + "</div>";return bubbleContainer;},getMainBubble = function() {return '<div class="main-bubble-holder"><div class="bubble main-bubble">' + getText() + '</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"><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.speed;$(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().left;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);

I have shared with you the key steps for js bubble effect. The code is simple and easy to understand. I didn't write too many text descriptions. If you have any questions, please leave a message. I will reply to you in a timely manner, here, I would like to thank you for your support for the help House website!

Related Article

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.