国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

純JS代碼實現氣泡效果

2019-11-20 10:09:56
字體:
來源:轉載
供稿:網友

就不給大家多文字說明了。給大家梳理下關鍵步驟。

關鍵步驟:

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氣泡效果的關鍵步驟,代碼簡單易懂,就沒給寫過多的文字說明,大家有疑問歡迎給我留言,小編會及時回復大家的,在此小編也非常感謝大家對武林網網站的支持!

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 大新县| 洛阳市| 黄山市| 哈密市| 涿州市| 无为县| 汶川县| 湾仔区| 邵阳县| 澄迈县| 子长县| 青神县| 信宜市| 金坛市| 太保市| 东阿县| 陇南市| 延津县| 景东| 太和县| 昌宁县| 东乡族自治县| 策勒县| 教育| 东乡| 平塘县| 南和县| 虹口区| 长垣县| 阳曲县| 汕尾市| 锦州市| 西乡县| 奉新县| 渑池县| 象州县| 湘潭县| 清涧县| 永平县| 广昌县| 尚义县|