您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

纯JS代码实现气泡效果_javascript技巧

2026/2/2 13:17:38发布29次查看
就不给大家多文字说明了。给大家梳理下关键步骤。
关键步骤:
1、引入js文件

2、在需要使用气泡效果的地方

3、使用气泡效果
$(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 = + getmainbubble() + getbubbles() +
;return bubblecontainer;},getmainbubble = function() {return '' + gettext() + '
';},gettext = function() {return '' + settings.text + '';},getbubbles = function() {return '
';},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气泡效果的关键步骤,代码简单易懂,就没给写过多的文字说明,大家有疑问欢迎给我留言,小编会及时回复大家的,在此小编也非常感谢大家对脚本之家网站的支持!
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product