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无限循环幻灯片式自动切换列表插件

一款文本文字列表自动切换特效,带渐变的淡出淡入效果,无缝转换很丝滑!
  图片特效&上传
 4785  0

VanillaJS实现的两张图片比对滑块特效代码

通过拖动滑块的交互方式比较两张图片,主要功能包括根据滑块的位置动态更改当前背景图片的宽度,提供无缝的图片比较体验,非常的有创意。
  图片特效&上传
 8770  0

纯CSS实现的鼠标悬停分割图片特效代码

一个分割图片效果。它使用剪辑路径标签属性,将图片分成四个尺寸相等的区块,再使用变换属性在悬停时移动和旋转角度。
  图片特效&上传
 5839  0

基于swiper的图片视频左右滑块特效代码

一款兼容电脑端拖动和手机端滑动的切换特效,主要是利用Swiper库来实现平滑的交互式滑块特效,支持img图片和video视频,类似于短视频平台上下滑动切换视频。
  图片特效&上传
 81061  0

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

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