南强小屋 Design By 杰米
代码分两个部分:1、HTML部分,根据注释处理即可;2、play.js插件部分,引到HTML里面即可。
1、HTML部分:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
<style>/*style标签及其内的内容,在实际项目中可以不要*/
* {
margin: 0;
padding: 0;
}
</style>
</head>
<body>
<!--body标签里的内容,没说可以增减或更改的,不要增减或更改-->
<div id="box">
<div>
<!--以下是可增减区域-->
<div><img src="/UploadFiles/2021-04-02/banner1.jpg">
2、play.js插件部分
function Banner(width, height) {/*类*/
/*以下最外层div*/
var that = this;
this.width = width;
this.height = height;
this.oBox = document.getElementById("box");
this.oBox.style.width = width;
this.oBox.style.height = height;
this.oBox.style.margin = "0 auto";
this.oBox.style.overflow = "hidden";
this.oBox.style.position = "relative";
/*以下轮播区的div*/
this.oBoxInner = this.oBox.getElementsByTagName('div')[0];
this.oBoxInner.style.height = height;
this.oBoxInner.style.position = "absolute";
this.oBoxInner.style.left = 0;
this.oBoxInner.style.right = 0;
this.aDiv = this.oBoxInner.getElementsByTagName('div');//单个轮播图
this.oBoxInner.innerHTML/* 轮播区的内部后面*/ += this.aDiv[0].outerHTML/*第一个轮播图片的外部*/;
this.oBoxInner.style.width = parseFloat(width) * this.aDiv.length + "px";//轮播区的宽度
for (var i = 0; i < this.aDiv.length; i++) {/*遍历轮播区的每个div及其内部的图片*/
this.aDiv[i].style.width = width;
this.aDiv[i].style.height = height;
this.aDiv[i].style.float = "left";
this.aDiv[i].aImg = this.aDiv[i].getElementsByTagName('img')[0];
this.aDiv[i].aImg.style.width = "100%";
this.aDiv[i].aImg.style.height = "100%";
}
/*以下是焦点区部分(定位在轮播区的右下方)*/
var oUl=document.createElement('ul');
for(i=0; i<this.aDiv.length-1; i++){
oUl.innerHTML+='<li class='+i+'===1"on":null></li>';
}
this.oBox.appendChild(oUl);
this.oUl = this.oBox.getElementsByTagName('ul')[0];
this.oUl.style.position = "absolute";
this.oUl.style.right = "10px";
this.oUl.style.bottom = "10px";
this.aLi = this.oUl.getElementsByTagName('li');
for (i = 0; i < this.aLi.length; i++) {/*遍历焦点区的每个焦点*/
this.aLi[i].style.width = "18px";
this.aLi[i].style.height = "18px";
this.aLi[i].style.float = "left";
this.aLi[i].style.listStyle = "none";
this.aLi[i].style.background = "green";
this.aLi[i].style.borderRadius = "50%";
this.aLi[i].style.marginLeft = "10px";
this.aLi[i].style.cursor = "pointer";
}
/*以下是向左向右两个箭头式按钮*/
for(i=0; i<2; i++){
var oA=document.createElement('a');
oA.href="javascript:;" rel="external nofollow"
this.oBox.appendChild(oA);
}
/*以下是左按钮(点击它,图片向左运动)*/
this.oBtnL = this.oBox.getElementsByTagName('a')[0];
this.oBtnL.style.width = "30px";
this.oBtnL.style.height = "30px";
this.oBtnL.style.position = "absolute";
this.oBtnL.style.top = (parseFloat(this.height) / 2 - 15) + "px";
this.oBtnL.style.left = "30px";
this.oBtnL.style.border = "10px solid red";
this.oBtnL.style.borderLeft = "none";
this.oBtnL.style.borderBottom = "none";
this.oBtnL.style.opacity = "0.3";
this.oBtnL.style.filter = "alpha(opacity=30)";
this.oBtnL.style.display = "none";
this.oBtnL.style.transform = "rotate(-135deg)";
this.oBtnL.onclick = function () {
if (that.step <= 0) {
that.step = that.aDiv.length - 1;
that.css(that.oBoxInner, 'left', -that.step * parseFloat(that.width));
}
that.step--;
that.animate(that.oBoxInner, {left: -that.step * parseFloat(that.width)});
that.bannerTip();
};
/*以下是右按钮(点击它,图片向右运动)*/
this.oBtnR = this.oBox.getElementsByTagName('a')[1];
this.oBtnR.style.width = "30px";
this.oBtnR.style.height = "30px";
this.oBtnR.style.position = "absolute";
this.oBtnR.style.top = (parseFloat(this.height) / 2 - 15) + "px";
this.oBtnR.style.right = "30px";
this.oBtnR.style.border = "10px solid red";
this.oBtnR.style.borderLeft = "none";
this.oBtnR.style.borderBottom = "none";
this.oBtnR.style.opacity = "0.3";
this.oBtnR.style.filter = "alpha(opacity=30)";
this.oBtnR.style.display = "none";
this.oBtnR.style.transform = "rotate(45deg)";
this.oBtnR.onclick = function () {
if (that.step >= that.aDiv.length - 1) {
that.step = 0;
that.css(that.oBoxInner, 'left', 0)
}
that.step++;
that.animate(that.oBoxInner, {left: -that.step * parseFloat(that.width)}, 1000);
that.bannerTip();
};
/*以下是其它*/
this.step = 0;//记录每次运动
this.timer = null;//定时器
this.init();//初始化轮播图
}
Banner.prototype = {//类的原型
constructor: Banner,
/*getCss:获取元素的属性值*/
getCss: function (curEle, attr) {
var val = null;
var reg = null;
if (getComputedStyle) {//标准浏览器
val = getComputedStyle(curEle, false)[attr];
} else {//非标准浏览器
if (attr === 'opacity') {
val = curEle.currentStyle.filter; //'alpha(opacity=10)'
reg = /^alpha\(opacity[=:](\d+)\)$/i;
return reg.test(val) "on") {
this.aLi[i].style.background = "red";
} else {
this.aLi[i].style.background = "green";
}
}
},
over_out: function () {
var _this = this;
_this.oBox.onmouseover = function () {
clearInterval(_this.timer);
_this.oBtnL.style.display = 'block';
_this.oBtnR.style.display = 'block';
};
_this.oBox.onmouseout = function () {
_this.timer = setInterval(function () {
_this.autoMove()
}, 2000);
_this.oBtnL.style.display = 'none';
_this.oBtnR.style.display = 'none';
}
}
};
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,同时也希望多多支持!
南强小屋 Design By 杰米
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
南强小屋 Design By 杰米
暂无原生JS轮播图插件的评论...
《魔兽世界》大逃杀!60人新游玩模式《强袭风暴》3月21日上线
暴雪近日发布了《魔兽世界》10.2.6 更新内容,新游玩模式《强袭风暴》即将于3月21 日在亚服上线,届时玩家将前往阿拉希高地展开一场 60 人大逃杀对战。
艾泽拉斯的冒险者已经征服了艾泽拉斯的大地及遥远的彼岸。他们在对抗世界上最致命的敌人时展现出过人的手腕,并且成功阻止终结宇宙等级的威胁。当他们在为即将于《魔兽世界》资料片《地心之战》中来袭的萨拉塔斯势力做战斗准备时,他们还需要在熟悉的阿拉希高地面对一个全新的敌人──那就是彼此。在《巨龙崛起》10.2.6 更新的《强袭风暴》中,玩家将会进入一个全新的海盗主题大逃杀式限时活动,其中包含极高的风险和史诗级的奖励。
《强袭风暴》不是普通的战场,作为一个独立于主游戏之外的活动,玩家可以用大逃杀的风格来体验《魔兽世界》,不分职业、不分装备(除了你在赛局中捡到的),光是技巧和战略的强弱之分就能决定出谁才是能坚持到最后的赢家。本次活动将会开放单人和双人模式,玩家在加入海盗主题的预赛大厅区域前,可以从强袭风暴角色画面新增好友。游玩游戏将可以累计名望轨迹,《巨龙崛起》和《魔兽世界:巫妖王之怒 经典版》的玩家都可以获得奖励。