基于JS如何制作上下滑动的轮播效果,代码是什么
Admin 2022-08-09 群英技术资讯 1518 次浏览
今天小编跟大家讲解下有关“基于JS如何制作上下滑动的轮播效果,代码是什么”的内容 ,相信小伙伴们对这个话题应该有所关注吧,小编也收集到了相关资料,希望小伙伴们看了有所帮助。一、效果图

第一步:遍历所有的元素使得鼠标点击右侧小图时,图片变亮并且根据偏移值加上红框。点击右边的小图左边出现对用的图片。
第二步:利用循环计时器,克隆ul里面的第一个元素使得连续循环滑动。
第三步:鼠标进入时循环滑动停止,离开时继续。
第四步:设置上下按钮,当第一张图片的offsetTop值为0时,下面按钮出现,当到达底部最后一个元素时,上面按钮出现,底部按钮消失,当在整个元素中间时,上下按钮都出现,每点击一次按钮移动一个格子,左边图片也对应改变。
//找到right-btn 元素添加事件
var righttBtnList;
var Line;
var transy = 0;
var liHeight = 430;
var ulItem;
var count = 0;
var timer;
var speed = 2000;
var Item;
var ItemMenu;
var offsetTop = 0;
var itemtabinfo, topBtn, bottomBtn;
window.onload = function () {
righttBtnList = document.getElementsByClassName("right-btn");
Line = document.getElementsByClassName("line")[0];
ulItem = document.getElementsByClassName("item-child-ul")[0];
Item = document.getElementsByClassName("item-list")[0];
ItemMenu = document.getElementsByClassName("item-menu")[0];
itemtabinfo = document.getElementsByClassName("item-tab-info")[0];
topBtn = document.getElementsByClassName("top-btn")[0];
bottomBtn = document.getElementsByClassName("bottom-btn")[0];
//默认复制第一张添加到ulItem之中
ulItem.appendChild(ulItem.children[0].cloneNode(true));
//设置itemtabinfo 默认移动值
itemtabinfo.style.transform = "translateY(" + offsetTop + "px)";
//直接默认启动计时器
Animate();
//遍历所有的li添加事件
for (var i = 0; i < righttBtnList.length; i++) {
righttBtnList[i].index = i;
righttBtnList[i].onclick = function () {
//点击当前移除top-white
if (checkClass(this, 'top-white')) {
this.classList.remove("top-white");
//其余的添加
addWhite(this.index);
}
//获取偏移值
Line.style.top = ((this.index * 110 + 10) + offsetTop) + "px";
//输出当前点击的索引
ulItem.style.transform = "translateY(" + (-this.index * liHeight) + "px)";
//用户点击的索引 对应count值
count = this.index;
}
}
Item.onmouseenter=function(){
clearTimeout(timer);
}
Item.onmouseleave=function(){
Animate();
}
topBtn.onclick = function () {
offsetTop += 110;
//获取原来的top
var oldTop = parseFloat(Line.style.top);
Line.style.top = (oldTop + 110) + "px";
itemtabinfo.style.transform = "translateY(" + offsetTop + "px)";
checkBtnShow();
}
bottomBtn.onclick = function () {
offsetTop -= 110;
//获取原来的top
var oldTop = parseFloat(Line.style.top);
//只能取到行内样式
Line.style.top = (oldTop - 110) + "px";
itemtabinfo.style.transform = "translateY(" + offsetTop + "px)";
checkBtnShow();
}
ItemMenu.onmouseenter = function () {
checkBtnShow();
}
function checkBtnShow() {
if (offsetTop == 0) {
//下面按钮出现
bottomBtn.classList.add("showBottom");
topBtn.classList.remove("showTop");
}
else if (offsetTop == -220) {
//上面按钮出现
topBtn.classList.add("showTop");
bottomBtn.classList.remove("showBottom");
} else {
//两个按钮同时出现
bottomBtn.classList.add("showBottom");
topBtn.classList.add("showTop");
}
}
ItemMenu.onmouseleave = function () {
bottomBtn.classList.remove("showBottom");
topBtn.classList.remove("showTop");
}
//检测是否具有top-white
function checkClass(obj,className){
return obj.classList.contains(className);
}
//其余的li添加
function addWhite(index){
for(var i=0;i<righttBtnList.length;i++){
if(i!=index){
righttBtnList[i].classList.add("top-white");
}
}
}
//启动计时器动画
function Animate(){
//写执行代码
timer=setInterval(function(){
if (timer)
clearInterval(timer);
if(!ulItem.classList.contains("transY")){
ulItem.classList.add("transY");
}
count++;
ulItem.style.transform="translateY("+(-count*liHeight)+"px)";
//找出当前每一张图动画完成时间
setTimeout(function(){
if(count>=ulItem.children.length-1){
count=0;
//移除过渡类
ulItem.classList.remove("transY");
ulItem.style.transform="translateY(0px)";
}
//让右边的元素动画对应
//rigthBtnlist[count].click();
},500)
},speed)
}
}
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:mmqy2019@163.com进行举报,并提供相关证据,查实之后,将立刻删除涉嫌侵权内容。
猜你喜欢
接到需求需要一个服务来执行shell脚本,要求可以实时打印shell脚本执行的过程,并看到脚本执行的结果。明确任务目标:这是一个web服务,需要执行shell脚本当一个脚本执行的时候,再次发送请求需要等待当前脚本执行完毕,再自动执行这次请求使用长连接而不是socket添加脚本不需要重启服务器这里采用的是express框架开始首先搭好express基本框架新建
这篇文章主要给大家介绍JS中的Proxy对象,一些朋友可能对Proxy对象的用途以及用法不是很了解,对此下文有详细的介绍,有需要的朋友可以参考下面的代码,接下来我们一起来学习Proxy对象吧。
利用nodejs实现:逐行读写(从一个文件逐行复制到另外一个文件);逐行读取、处理和写入(读取一行,处理后,写入另一个文件)1.所需要的模块:fs,os,readline2.具体实现:a.功能的实现:readWriteFileByLine.jsvarfs=require('fs-extra');varos=require('os');varrl=requir
所谓数据代理(也叫数据劫持),指的是在访问或者修改对象的某个属性时,通过一段代码拦截这个行为,进行额外的操作或者修改返回结果。比较典型的是 Object.defineProperty() 和 ES2015 中新增的 Proxy 对象
这篇文章给大家分享的是有关nodejs错误处理过程的内容。小编觉得挺实用的,下文有具体实例可以个参考,感兴趣的朋友不妨跟随小编一起看看吧。
成为群英会员,开启智能安全云计算之旅
立即注册关注或联系群英网络
7x24小时售前:400-678-4567
7x24小时售后:0668-2555666
24小时QQ客服
群英微信公众号
CNNIC域名投诉举报处理平台
服务电话:010-58813000
服务邮箱:service@cnnic.cn
投诉与建议:0668-2555555
Copyright © QY Network Company Ltd. All Rights Reserved. 2003-2020 群英 版权所有
增值电信经营许可证 : B1.B2-20140078 ICP核准(ICP备案)粤ICP备09006778号 域名注册商资质 粤 D3.1-20240008