jquery响应式手风琴图片自动折叠展开特效代码

所属分类: 网页特效-图片特效&上传    2023-10-25 09:35:55

jquery响应式手风琴图片自动折叠展开特效代码 ie兼容6
 查看演示  登录后下载 温馨提示
登录会员即可享受免费下载
 我要建站

jquery响应式手风琴图片自动折叠展开特效代码(共7个文件)

    • main.js
    • index.html
    • style.css

使用方法

var slideCount = document.querySelectorAll(".slider").length - 1;
var slideIndex = 1;
var direction;
var sliderSpeed = 700;
var sliderAutoplayTime = 3000;
var sliderHeight = 600;
var sliderWidth = $(".slider-wrapper").width();

if ($(window).width() > 767) {
	desktopSlider();
} else {
	mobileSlider();
}

function desktopSlider() {
	direction = "left";

	$(".slider.first").css("left", 0);

	var timer = setInterval(() => {
		playAnimation("left", "left", ".slider", "right");
	}, sliderAutoplayTime);

	$(".slider").click(function () {
		let elem = $(this);
		let index = parseInt(elem.data("index"));
		let position;

		clearInterval(timer);

		slideIndex = index;

		if ($(`.slider:nth-of-type(${index + 2})`).hasClass("slide")) {
			if (index == 3) {
				return false;
			} else {
				$(".slider").each(function (pos, el) {
					if ($(`.slider:nth-of-type(${pos + 2})`).hasClass("slide") && pos >= index) {
						position = sliderWidth - (slideCount - (pos + 1)) * 50 + "px";
						$(`.slider:nth-of-type(${pos + 2})`)
							.stop()
							.animate({ left: position }, sliderSpeed);
						$(`.slider:nth-of-type(${pos + 2})`).toggleClass("active slide");
					}
				});
			}
		} else {
			if (index == 1) {
				position = index * 50 + "px";
				elem.stop().animate({ left: position }, 500);
				elem.toggleClass("slide");
			} else {
				$(".slider").each(function (pos, el) {
					if (pos != 0 && !$(el).hasClass("slide") && pos <= index) {
						position = pos * 50 + "px";
						$(el).stop().animate({ left: position }, sliderSpeed);
						$(el).toggleClass("slide");
					}
				});
			}
		}

		checkIndex("left", "right");
		timer = setInterval(() => {
			playAnimation("left", "left", ".slider", "right");
		}, sliderAutoplayTime);
	});
}

function mobileSlider() {
	direction = "top";

	$(".m-slider.first").css("top", 0);

	var timer = setInterval(() => {
		playAnimation("top", "top", ".m-slider", "bottom");
	}, sliderAutoplayTime);

	$(".m-slider").click(function () {
		let elem = $(this);
		let index = parseInt(elem.data("index"));
		let position;

		clearInterval(timer);

		slideIndex = index;

		if (index == 0) return false;

		if (elem.hasClass("slide")) {
			$(".m-slider").each(function (pos, el) {
				if ($(el).hasClass("slide") && pos >= index) {
					position = sliderHeight - (slideCount - pos + 1) * 50 + "px";
					$(el).stop().animate({ top: position }, sliderSpeed);
					$(el).toggleClass("slide");
				}
			});
		} else {
			$(".m-slider").each(function (pos, el) {
				if (pos != 0 && !$(el).hasClass("slide") && pos <= index) {
					position = pos * 50 + "px";
					$(el).stop().animate({ top: position }, sliderSpeed);
					$(el).toggleClass("slide");
				}
			});
		}

		checkIndex("top", "bottom");
		timer = setInterval(() => {
			playAnimation("top", "top", ".m-slider", "bottom");
		}, sliderAutoplayTime);
	});
}

/**
 * Play animation
 * @param {string} sliderDirection it is direction of slider (left-right, top-bottom)
 * @param {string} animateDirection it is a direction of animation (left, top)
 * @param {string} sliderClass the class of slider, in case of desktop ".slider" and mobile ".m-slider"
 * @param {string} secondaryDirection it is a second parameter of checkIndex function
 * @function
 * return void
 */
function playAnimation(sliderDirection, animateDirection, sliderClass, secondaryDirection) {
	var position;
	if (direction === sliderDirection) {
		position = slideIndex * 50 + "px";
		$(`${sliderClass}:nth(${slideIndex})`).addClass("slide");
	} else {
		if (sliderDirection == "left") {
			position = sliderWidth - (slideCount - slideIndex) * 50 + "px";
		} else {
			position = sliderHeight - (slideCount - (slideIndex - 1)) * 50 + "px";
		}
		$(`${sliderClass}:nth(${slideIndex})`).removeClass("slide");
	}

	let animationParams = {};
	animationParams[animateDirection] = position;

	$(`${sliderClass}:nth(${slideIndex})`)
		.stop()
		.animate(animationParams, sliderSpeed, function () {
			checkIndex(animateDirection, secondaryDirection);
		});
}

/**
 * It is check the slider direction and increase or decreases
 * the sliderIndex variable.
 * @param {string} direction1 primary slider direction
 * @param {string} direction2 secondary slider direction
 * @function
 * return void
 */
function checkIndex(direction1, direction2) {
	if (slideIndex == 1 && direction == direction2) {
		direction = direction1;
	} else if (slideIndex >= 1 && direction == direction1 && slideIndex < slideCount) {
		slideIndex++;
	} else if ((slideIndex == slideCount || slideIndex < slideCount) && direction == direction2) {
		slideIndex--;
	} else if (slideIndex == slideCount) {
		direction = direction2;
	}
}

站长提示:
1. 苦力吧素材官方QQ群:950875342
2. 平台上所有素材资源,需注册登录会员方能正常下载。
3. 会员用户积极反馈网站、素材资源BUG或错误问题,每次奖励2K币
4. PHP源码类素材,如需协助安装调试,或你有二次开发需求,可联系苦力吧客服。
5. 付费素材资源,需充值后方能下载,如有任何疑问可直接联系苦力吧客服
相关资源 / 图片特效&上传

jquery使用SVG创建图片反射和镜像特效代码

一款将图片呈现镜像效果,可自定义四个方向的镜像特效:top/left/right/bottom。
  图片特效&上传
 2226  0

jquery支持触屏拖动的图文卡片轮播特效

一款响应式个人简介图文幻灯片代码,支持鼠标点击焦点以及支持触屏滑动操作,在手机端显示一个卡片,在680px到1000px宽度屏面上显示两个卡片,以及在1000px以上的屏幕显示三个卡片。
  图片特效&上传
 9216  0

jquery上传图片预览带在线裁剪功能特效代码

一款上传图片可在线预览裁剪特效插件,还可旋转图片,非常的实用!
  图片特效&上传
 8264  0

javascript支持自定义文件上传插件

用户可上传指定大小且指定后缀名的文件,点选本地电脑文件后带图片预览效果。当上传的文件超过设置的大小限制,会显示相应的错误消息。
  图片特效&上传
 3305  0

评论数(0) 回复有机会获得K币 用户协议

^_^ 还没有人评论,快来抢个沙发!
😀
  • 😀
  • 😊
  • 😂
  • 😍
  • 😑
  • 😷
  • 😵
  • 😛
  • 😣
  • 😱
  • 😋
  • 😎
  • 😵
  • 😕
  • 😶
  • 😚
  • 😜
  • 😭
发表评论