純JS代碼實(shí)現(xiàn)氣泡效果
就不給大家多文字說明了。給大家梳理下關(guān)鍵步驟。
關(guān)鍵步驟:
1、引入js文件
<script type="text/javascript" src="js/jquery.min.js"></script> <script type="text/javascript" src='js/jquery.thoughtBubble.js'></script>
2、在需要使用氣泡效果的地方
<div id='mainContainer' class='container'> <img src='ahout.JPG' id="thoughtBubble" alt='whats up?' /> </div>
3、使用氣泡效果
<script type="text/javascript"> $(window).ready( function() { $('#thoughtBubble').thoughtBubble({ text: 'baby,I love you', font: 'avenir' }); });
4、這是jquery.thoughtBubblr.js代碼
(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);
以上給大家分享了js氣泡效果的關(guān)鍵步驟,代碼簡單易懂,就沒給寫過多的文字說明,大家有疑問歡迎給我留言,小編會及時回復(fù)大家的,在此小編也非常感謝大家對腳本之家網(wǎng)站的支持!
- JavaScript實(shí)現(xiàn)好看的跟隨彩色氣泡效果
- 使用JS實(shí)現(xiàn)氣泡跟隨鼠標(biāo)移動的動畫效果
- D3.js實(shí)現(xiàn)散點(diǎn)圖和氣泡圖的方法詳解
- javascript實(shí)現(xiàn)很浪漫的氣泡冒出特效
- JavaScript實(shí)現(xiàn)鼠標(biāo)滑過處生成氣泡的方法
- js由下向上不斷上升冒氣泡效果實(shí)例
- Jquery插件分享之氣泡形提示控件grumble.js
- JS+CSS實(shí)現(xiàn)一個氣泡提示框
- jquery.cvtooltip.js 基于jquery的氣泡提示插件
- js實(shí)現(xiàn)可愛的氣泡特效
相關(guān)文章
JavaScript實(shí)現(xiàn)異步圖像上傳功能
這篇文章主要介紹了JavaScript實(shí)現(xiàn)異步圖像上傳功能,本文展示了一種使用代碼示例立即顯示圖像的方法(使用圖像的Base64編碼版本),同時將其上載到服務(wù)器,而無需等待操作完成。需要的朋友可以參考下2018-07-07JS+Canvas實(shí)現(xiàn)接球小游戲的示例代碼
本文主要為大家詳細(xì)介紹了如何利用JS+Canvas實(shí)現(xiàn)接球小游戲,文中的示例代碼講解詳細(xì),對我們學(xué)習(xí)有一定的幫助,感興趣的小伙伴可以了解一下2022-06-06javascript 圖片上傳預(yù)覽-兼容標(biāo)準(zhǔn)
js圖片上傳預(yù)覽2009-06-06javascript實(shí)現(xiàn)簡單頁面倒計時
這篇文章主要為大家詳細(xì)介紹了javascript實(shí)現(xiàn)簡單頁面倒計時,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2021-03-03