html自动切换一言插件,jQuery和css3自动轮换的用户评论留言插件

这是一款非常实用的jQuery和css3自动轮换的用户评论留言插件。该用户评论插件通过进度条来控制用户评论显示的时间,当进度条到达100%时,该插件自动播放下一条用户留言。该插件同样通过media query媒体查询来处理各种屏幕的响应式问题。

HTML结构

img01

People eat meat and think they will become as strong as an ox, forgetting that the ox eats grass.

Pino Caruso

CSS样式

插件中用户留言面板的CSS样式非常简单,你可以构建自己的CSS样式来使它更加漂亮。

.cbp-qtrotator {

position: relative;

margin: 3em auto 5em auto;

max-width: 800px;

width: 100%;

min-height: 400px;

}

.cbp-qtrotator .cbp-qtcontent {

position: absolute;

min-height: 200px;

border-top: 1px solid #f4f4f4;

border-bottom: 1px solid #f4f4f4;

padding: 2em 0;

top: 0;

z-index: 0;

opacity: 0;

width: 100%;

}

.no-js .cbp-qtrotator .cbp-qtcontent {

border-bottom: none;

}

/* Currently visible */

.cbp-qtrotator .cbp-qtcontent.cbp-qtcurrent,

.no-js .cbp-qtrotator .cbp-qtcontent {

position: relative;

z-index: 100;

pointer-events: auto;

opacity: 1;

}

.cbp-qtrotator .cbp-qtcontent:before,

.cbp-qtrotator .cbp-qtcontent:after {

content: " ";

display: table;

}

.cbp-qtrotator .cbp-qtcontent:after {

clear: both;

}

.cbp-qtprogress {

position: absolute;

background: #47a3da;

height: 1px;

width: 0%;

top: 0;

z-index: 1000;

}

.cbp-qtrotator blockquote {

margin: 0;

padding: 0;

}

.cbp-qtrotator blockquote p {

font-size: 2em;

color: #888;

font-weight: 300;

margin: 0.4em 0 1em;

}

.cbp-qtrotator blockquote footer {

font-size: 1.2em;

}

.cbp-qtrotator blockquote footer:before {

content: '? ';

}

.cbp-qtrotator .cbp-qtcontent img {

float: right;

margin-left: 3em;

}

/* Example for media query */

@media screen and (max-width: 30.6em) {

.cbp-qtrotator {

font-size: 70%;

}

.cbp-qtrotator img {

width: 80px;

}

}

JAVASCRIPT

有几个可用参数可以使用:

speed:CSS动画过渡的时间,单位毫秒,默认值为700ms。

easing:CSS动画的类型,默认值为easing。

interval:进度条每次从0走到100%的时间(用户评论显示的时间)。单位毫秒,默认值为8000ms。

代码如下:

;( function( $, window, undefined ) {

'use strict';

// global

var Modernizr = window.Modernizr;

$.CBPQTRotator = function( options, element ) {

this.$el = $( element );

this._init( options );

};

// the options

$.CBPQTRotator.defaults = {

// default transition speed (ms)

speed : 700,

// default transition easing

easing : 'ease',

// rotator interval (ms)

interval : 8000

};

$.CBPQTRotator.prototype = {

_init : function( options ) {

// options

this.options = $.extend( true, {}, $.CBPQTRotator.defaults, options );

// cache some elements and initialize some variables

this._config();

// show current item

this.$items.eq( this.current ).addClass( 'cbp-qtcurrent' );

// set the transition to the items

if( this.support ) {

this._setTransition();

}

// start rotating the items

this._startRotator();

},

_config : function() {

// the content items

this.$items = this.$el.children( 'div.cbp-qtcontent' );

// total items

this.itemsCount = this.$items.length;

// current item´s index

this.current = 0;

// support for CSS Transitions

this.support = Modernizr.csstransitions;

// add the progress bar

if( this.support ) {

this.$progress = $( '' ).appendTo( this.$el );

}

},

_setTransition : function() {

setTimeout( $.proxy( function() {

this.$items.css( 'transition', 'opacity ' + this.options.speed + 'ms ' + this.options.easing );

}, this ), 25 );

},

_startRotator: function() {

if( this.support ) {

this._startProgress();

}

setTimeout( $.proxy( function() {

if( this.support ) {

this._resetProgress();

}

this._next();

this._startRotator();

}, this ), this.options.interval );

},

_next : function() {

// hide previous item

this.$items.eq( this.current ).removeClass( 'cbp-qtcurrent' );

// update current value

this.current = this.current < this.itemsCount - 1 ? this.current + 1 : 0;

// show next item

this.$items.eq( this.current ).addClass('cbp-qtcurrent');

},

_startProgress : function() {

setTimeout( $.proxy( function() {

this.$progress.css( { transition : 'width ' + this.options.interval + 'ms linear', width : '100%' } );

}, this ), 25 );

},

_resetProgress : function() {

this.$progress.css( { transition : 'none', width : '0%' } );

},

destroy : function() {

if( this.support ) {

this.$items.css( 'transition', 'none' );

this.$progress.remove();

}

this.$items.removeClass( 'cbp-qtcurrent' ).css( {

'position' : 'relative',

'z-index' : 100,

'pointer-events' : 'auto',

'opacity' : 1

} );

}

};

var logError = function( message ) {

if ( window.console ) {

window.console.error( message );

}

};

$.fn.cbpQTRotator = function( options ) {

if ( typeof options === 'string' ) {

var args = Array.prototype.slice.call( arguments, 1 );

this.each(function() {

var instance = $.data( this, 'cbpQTRotator' );

if ( !instance ) {

logError( "cannot call methods on cbpQTRotator prior to initialization; " +

"attempted to call method '" + options + "'" );

return;

}

if ( !$.isFunction( instance[options] ) || options.charAt(0) === "_" ) {

logError( "no such method '" + options + "' for cbpQTRotator instance" );

return;

}

instance[ options ].apply( instance, args );

});

}

else {

this.each(function() {

var instance = $.data( this, 'cbpQTRotator' );

if ( instance ) {

instance._init();

}

else {

instance = $.data( this, 'cbpQTRotator', new $.CBPQTRotator( options, this ) );

}

});

}

return this;

};

} )( jQuery, window );

idea插件文心一言是一款用于提供代码自动补全和生成的插件。它可以帮助开发者快速编写代码,减少了繁琐的代码编写过程,提高了开发效率。使用该插件,开发者可以从文心一言数据库中获取到各种代码片段和模板,通过简单的快捷键就可以插入到代码中,大大减少了编写重复性代码的工作量。要安装这个插件,你可以在"Settings/Preferences"窗口中选择"Plugins"选项卡,然后点击"Marketplace"按钮,在搜索框中输入"文心一言",找到并安装这个插件即可。虽然还有其他一些工具如Cursor和GitHub Copilot可以用于编码,但文心一言更加专注于代码补全和生成的功能,使开发者能够更好地聚焦于业务逻辑而不是重复性的代码编写。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [推荐一款idea神级代码插件【Bito-ChatGPT】而且免费!- 第9篇](https://blog.csdn.net/linxingliang/article/details/130488391)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *3* [人工智能时代,软件工程师们将会被取代?](https://blog.csdn.net/w605283073/article/details/129656118)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值