没有合适的资源?快使用搜索试试~ 我知道了~
vue.js层叠轮播效果的实例代码
4 下载量 152 浏览量
2021-01-19
16:42:49
上传
评论
收藏 64KB PDF 举报
温馨提示
最近写公司项目有涉及到轮播banner,一般的ui框架无法满足产品需求;所以自己写了一个层叠式轮播组件;现在分享给大家; 主要技术栈是vue.js ;javascript;jquery;确定实现思路因工作繁忙,暂时不做梳理了;直接贴代码参考; 此组件是基于jquer封装,在vue项目中使用首先需要先安装jquery插件:指令:npm install jquery,安装完成之后再webpack.base.conf.js配置插件: plugins: [ new webpack.ProvidePlugin({ $: 'jquery', jQuery: 'jquery' }),
资源推荐
资源详情
资源评论
vue.js层叠轮播效果的实例代码层叠轮播效果的实例代码
最近写公司项目有涉及到轮播banner,一般的ui框架无法满足产品需求;所以自己写了一个层叠式轮播组件;现在分享给大
家;
主要技术栈是vue.js ;javascript;jquery;确定实现思路因工作繁忙,暂时不做梳理了;直接贴代码参考;
此组件是基于jquer封装,在vue项目中使用首先需要先安装jquery插件:指令:npm install jquery,安装完成之后再
webpack.base.conf.js配置插件:
plugins: [
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery'
}),
]
主要实现逻辑js文件:postercarousel.js;
代码如下:
(function(jq){
function postercarousel(o, options, data){
this.parent = jq("#"+ o);
this.body = jq("body");
if (this.parent.length <= 0) {
return false;
}
this.options = jq.extend({}, postercarousel.options, options);
if(typeof(data) !== 'object') return false;
this.data = data || {};
this.reset();
//处理页面resize
var _this = this;
jq(window).resize(function(){
_this.reset();
});
};
postercarousel.prototype = {
reset: function(options){
if(typeof(options) == 'object'){
jq.extend(this.options, options);
}
if(parseInt(this.body.outerWidth())>1255 || navigator.userAgent.indexOf('iPad') !== -1){
this.options.width = 970;
}else{
this.options.width = 970;
}
this.total = this.data.length;
this.pageNow = this.options.initPage;
this.preLeft = 0;
this.nextLeft = this.options.width-530;
this.preNLeft = -530;
this.nextNLeft = this.options.width;
this.pageNowLeft = (this.options.width-640)/2
this.drawContent();
},
drawContent: function(){
this.parent.empty();
this.parent.css({width:this.options.width+"px", height:this.options.height+"px", position: "relative"});
this.content = document.createElement("DIV");
this.content.className = this.options.className;
this.content.cssText = "width:"+this.options.width+"px;height:"+this.options.height+"px;cursor:move;position:absolute;";
this.bottomNav = document.createElement("DIV");
this.bottomNav.className = "bottomNav";
for(var i=1; i<= this.total; i++){
var bottomItem = document.createElement("DIV");
bottomItem.className = "bottomNavButtonOFF";
if(i == this.pageNow){
bottomItem.className = "bottomNavButtonOFF bottomNavButtonON";
}
bottomItem.setAttribute("ref", i);
this.bottomNav.appendChild(bottomItem);
}
this.content.appendChild(this.bottomNav);
this.bannerControls = '<div class="bannerControls"> <div class="leftNav" style="display: block;"></div> <div
class="rightNav" style="display: block;"></div> </div>';
this.content.innerHTML += this.bannerControls;
this.contentHolder = document.createElement("DIV");
this.contentHolder.style.width = this.options.width + 'px';
this.contentHolder.style.height = this.options.height + 'px';
for(var item=0, i = 1, l= this.data.length ; item < l ; ++item, ++i){
var contentHolderUnit = document.createElement("DIV");
contentHolderUnit.className = "contentHolderUnit";
contentHolderUnit.setAttribute("ref", i);
contentHolderUnit.setAttribute("id", 'contentHolderUnit' + (i));
var unitItem = '<a href="'+this.data[item].url+'" rel="external nofollow" target="_blank" class="elementLink">';
unitItem += '</a>';
unitItem += '<img src="'+this.data[item].img+'" alt="'+this.data[item].title+'"/>';
unitItem += '<span class="elementOverlay"></span>';
unitItem += '<span class="leftShadow"></span>';
unitItem += '<span class="rightShadow"></span>';
contentHolderUnit.innerHTML = unitItem;
this.contentHolder.appendChild(contentHolderUnit);
}
this.content.appendChild(this.contentHolder);
this.parent.append(this.content);
this.parent.css({overflow:'hidden'});
this.initContent();
this.bind();
this.start();
},
initContent: function(){
contentHolderUnit = this.parent.find(".contentHolderUnit");
contentHolderUnit.css({width:'0px',height:'0px', opacity: 0, left:this.options.width/2+'px', zIndex:0, marginTop: '135px'});
this.parent.find(".contentHolderUnit:nth-child("+this.pageNow+")").css({width:'640px',height:'450', opacity: 1, left:
this.pageNowLeft+'px', zIndex: 3, marginTop: 0});
this.parent.find(".contentHolderUnit:nth-child("+this.pageNow+") .elementOverlay").css({opacity:0});
this.parent.find(".contentHolderUnit:nth-child("+this.pageNow+") .leftShadow").css({opacity:1});
this.parent.find(".contentHolderUnit:nth-child("+this.pageNow+") .rightShadow").css({opacity:1});
var pre = this.pageNow > 1 ? this.pageNow -1: this.total;
var next = this.pageNow == this.total ? 1 : this.pageNow + 1;
this.parent.find(".contentHolderUnit:nth-child("+pre+")").css({opacity: 1, left: this.preLeft+'px',height: '450', width: '530px',
zIndex: 0, marginTop: '23px'});
this.parent.find(".contentHolderUnit:nth-child("+pre+") .elementOverlay").css({opacity:0.4});
this.parent.find(".contentHolderUnit:nth-child("+pre+") .leftShadow").css({opacity:0});
this.parent.find(".contentHolderUnit:nth-child("+pre+") .rightShadow").css({opacity:0});
this.parent.find(".contentHolderUnit:nth-child("+next+")").css({opacity: 1, left: this.nextLeft+'px',height: '450', width: '530px',
zIndex: 0, marginTop: '23px'});
this.parent.find(".contentHolderUnit:nth-child("+next+") .elementOverlay").css({opacity:0.4});
this.parent.find(".contentHolderUnit:nth-child("+next+") .leftShadow").css({opacity:0});
this.parent.find(".contentHolderUnit:nth-child("+next+") .rightShadow").css({opacity:0});
},
bind: function(){
this.leftNav = this.parent.find(".leftNav");
this.rightNav = this.parent.find(".rightNav");
this.bottonNav = this.parent.find(".bottomNavButtonOFF");
this.lists = this.parent.find(".contentHolderUnit");
var _this = this;
this.parent.mouseover(function(){
_this.stop();
_this.leftNav.show();
剩余7页未读,继续阅读
资源评论
weixin_38599231
- 粉丝: 3
- 资源: 950
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功