찾다
웹 프론트엔드JS 튜토리얼jquery_jquery를 기반으로 한 이미지 캐러셀 탭 전환 구성요소

현재 스크롤 효과만 추가되었으며 스크롤은 x 및 y 방향으로의 슬라이딩을 지원할 수 있습니다. 아무 효과도 없으며 나중에 다른 효과를 추가하고 확장해야 합니다. 글이 좀 거칠네요 ㅎㅎ. 분실 방지를 위해 여기에 메모를 남겨주세요.
 데모 주소: http://demo.jb51.net/js/2012/sinaapp/

코드 복사코드는 다음과 같습니다.

/**
* 빅맥 회전목마
*/
$.fn.loopSlider = function(option) {
var 설정 = {
//기본 표시 순서
initIndex: 1 ,
// 제목 노드에 스타일이 추가됨
className: "current",
// 캐러셀 방향, 기본값은 x축 캐러셀
direct: "x",
// 이전 버튼
prevBtn: "",
// 다음 버튼
nextBtn: "",
// 페이지 위로 및 아래로 버튼 스타일 비활성화
btnDisable: "disable ",
/ /버튼 누르기 스타일
btnTouchClass: "",
// 자동 캐러셀
auto: false,
// 자동 캐러셀 시간 간격
timeFlag: 4000,
// 캐러셀 효과 시간
scrollTime: 350,
// 회전판 효과
효과: "scroll",
// 회전판 요소가 하나만 있을 때 숨길지 여부 슬라이딩 버튼
hideBtn: true,
// 캐러셀 순환 여부
cycle: true,
// 캐러셀 콘텐츠 영역의 컨테이너 경로
contentContainer: "#imgScroll",
//캐러셀 콘텐츠 영역의 노드
contentChildTag: "li",
// 제목 캐러셀 영역의 컨테이너 경로
titleContainer: "#titleScroll",
// 제목 캐러셀 영역 노드
titleChildTag: "li",
/ / 캐러셀 콘텐츠 영역 배열
cont: [],
// 캐러셀 제목 영역 배열
탭: [] ,
// 현재 캐러셀 번호
현재: 0,
// 타이머
ptr: "",
// 캐러셀 콜백 함수, 캐러셀이 호출될 때마다 호출되며 매개변수는 다음과 같습니다. 현재 캐러셀의 일련번호
콜백: function() {
return true;
}
}
if (option) {
$.extend(setting, option)
}
//현재 호출 유형의 함수 초기화
setting.currentMethod = function() {
return true;
}
var boss = $(this)
// 첫 번째 요소가 아닌 경우 먼저 회전합니다.
(setting.initIndex != 1) {
setting.current = settings.initIndex - 1;
}
// 회전 노드 목록 가져오기
var childList = boss.find(setting.contentContainer " "setting.contentChildTag);
// 캐러셀 제목 노드 목록 가져오기
var titleList = boss.find(setting.titleContainer " "setting.titleChildTag)
// 콘텐츠에 각 캐러셀 노드 저장 Area
setting.cont = childList
// 제목의 캐러셀 노드 저장
setting.tabs = titleList;// 회전해야 하는 콘텐츠의 경우
if (setting.cont.length == 0) {
return;
}
// 콘텐츠 영역 및 제목 영역에 대한 인덱스 속성
childList 설정 .each(function(index) {
$(this).attr("index", index);
titleList.eq(index).attr("index", index)
}); arrows
var nextBtn = boss.find(setting.nextBtn);
var prevBtn = boss.find(setting.prevBtn);
// 길이
var counts = childList .length; // 캐러셀 컨테이너의 상위 노드
var childParent = childList.parent();
var titleParent = titleList.parent()
if (childList.length setting.current = 0;
}
//초기화
doInit();
if (childList.length return; /**
* 효과 없이 전환 처리
*/
var doScrollNone = {
프로세스: function(i) {
childList.eq(i).css("display", "block") .siblings(). css("display", "none");
titleList.eq(i).addClass(setting.className).siblings().removeClass(setting.className)
//record 현재 표시된 노드
setting.current = i;
// 콜백 함수 호출
setting.callback(setting.current);
},
init: function() {
settings.currentMethod = doScrollNone ;
bindEvent();
// 자동 캐러셀
if (setting.auto) {
processAuto()
}
// 초기화 중 콜백 함수도 호출합니다
setting.callback(setting.current);
}
};
var doScrollXY = {
c_width: 0,
c_height: 0,
init : function() {
//캐러셀 요소의 너비
this.c_width = childList.width();
//캐러셀 요소의 높이
this.c_height = childList.height()
// x축 방향 캐러셀
if (setting.direct == "x") {
childParent.width(this.c_width * (childList.length > 1 ? counts 1 : counts) ); >childParent.css("left", -this.c_width * (setting.current));
} else {
childParent.height(this.c_height * (childList.length > 1 ? 개수 1 : 개수) ));
childParent.css("top", -this.c_height * (setting.current))
}
titleList.eq(setting.current).addClass(setting.className).siblings ().removeClass(setting.className);
setting.currentMethod = doScrollXY;
// 바인딩 이벤트
bindEvent()
// 초기화 중에도 콜백 함수가 호출됩니다. .callback(setting.current);
//자동 캐러셀
if (setting.auto) {
processAuto();
}
},
process: function(i, needFast) {
setting.current = i;
//alert(i)
if (setting.direct == "x") {
//효과 애니메이션 실행
childParent.animate ({
왼쪽: "-" (this.c_width * i)
},
(needFast ? 50 : settings.scrollTime),
function() {
if (setting.current == 개수) {
doScrollXY.processMove("left", $(this))
}
if (setting.auto) {
processAuto()
}
});
} else {
childParent.animate({
top: "-" (this.c_height * i)
},
(needFast ? 50 : settings.scrollTime),
function() {
if (setting.current == counts) {
doScrollXY.processMove("top", $(this)) ;
}
if (setting.auto) {
processAuto();
}
});
}
if (i == 개수) {
i = 0;
}
// 调用回调函数
setting.callback(setting.current);
titleList.eq(i).addClass(setting.className).siblings().removeClass(setting.className);
},
processMove: function(direct, node) {
var childs = node.children();
for (var i = 1; i var RemoveNode = childs.eq(i).remove();
node.append(removeNode);
}
var first = childs.eq(0).remove();
node.append(첫 번째);
node.css(직접, "0");
}
};
스위치(설정.효과) {
case "none":
doScrollNone.init();
휴식;
케이스 "스크롤":
doScrollXY.init();
휴식;
}
// 一些初始화操작
function doInit() {
childParent.css("position", "relative");
if (!setting.cycle) {
prevBtn.removeClass(setting.btnDisable);
nextBtn.removeClass(setting.btnDisable);
if (setting.current == 0) {
prevBtn.addClass(setting.btnDisable);
}
if (setting.current == counts - 1) {
nextBtn.addClass(setting.btnDisable);
}
}
// 只有一个元素,并且需要隐藏按钮
if (childList.length prevBtn.hide();
nextBtn.hide();
}
// 克隆第一个元素到最后
if (childList.length > 1) {
var cloneNode = childList.eq(0).clone();
cloneNode.attr("index", counts);
cloneNode.appendTo(childParent);
}
}
/**
* 캐러셀 바인딩 이벤트
*/
function binEvent() {
nextBtn && nextBtn.bind("click",
function(event) {
// 如果按钮已经被禁用
if ($(this).hasClass(setting.btnDisable)) {
return;
}
var cur = settings.current; cur >= 0) {
prevBtn.removeClass(setting.btnDisable);
}
if (cur == counts - 2 && !setting.cycle) {
$(this).addClass (setting.btnDisable);
}
if (cur == counts) {
setting.current = 1
} else if (cur == counts - 1) {
//轮播到最后一个
setting.current = counts;
} else {
setting.current = cur 1
}
if (setting.ptr) {
clearInterval(setting .ptr);
setting.ptr = null;
}
$(this).addClass(setting.btnTouchClass)
setting.currentMethod.process(setting.current); );
prevBtn && prevBtn.bind("click",
function() {
if ($(this).hasClass(setting.btnDisable)) {
return;
}
var cur = settings.current;
if (cur nextBtn.removeClass(setting.btnDisable)
}
if (cur == 1 && !setting. 사이클) {
$(this).addClass(setting.btnDisable);
}
setting.current == 0 ? counts - 1 : cur - 1; ) {
clearInterval(setting.ptr);
setting.ptr = null
}
$(this).addClass(setting.btnTouchClass)
var fast = false; >if (cur == 0) {
fast = true;
}
setting.currentMethod.process(setting.current, fast)
});
titleParent && titleParent.bind("click",
function(e) {
var element = $(e.target);
// 得到轮播节点
while (element[ 0].tagName != titleList[0].tagName) {
element = element.parent();
}
if (setting.ptr) {
clearInterval(setting.ptr)
setting.ptr = null;
}
var index =parseInt(element.attr("index"), 10)
if (index != 0) {
prevBtn.removeClass( settings.btnDisable);
} else if (!setting.cycle) {
prevBtn.addClass(setting.btnDisable)
}
if (index != counts - 1) {
nextBtn.removeClass(setting.btnDisable);
} else if (!setting.cycle) {
nextBtn.addClass(setting.btnDisable)
}
setting.currentMethod.process(index);
});
childParent[0].ontouchstart = handlerTouchStart;
// 触摸屏幕事件
function handlerTouchStart(event) {
var element = $(event.target);
// 得到标题节点
while (element[0].tagName != childList[0].tagName) {
element = element.parent();
}
if (event.targetTouches.length == 0) {
return;
}
var touch = event.targetTouches[0];
var startX = touch.pageX;
var startY = touch.pageY;
var moveDirect = "";
var currentPosition = settings.direct == "x" ? childParent.css("왼쪽") : childParent.css("상단");
if (setting.ptr) {
clearInterval(setting.ptr);
setting.ptr = null;
}var moveX = movetouch.pageX;
var moveY = movetouch.pageY;
var x = moveX - startX; var y = moveY - startY; // 여기서의 목적은 이미지를 왼쪽이나 오른쪽으로 슬라이드할 때 브라우저의 기본 이벤트를 방지하는 것입니다. 그러나 위아래로 슬라이드하는 경우에는 일반적으로 브라우저의 기본 이벤트를 직접 방지할 수 없습니다. 페이지가 정지할 때 Y축 방향보다 X축 방향으로 10픽셀 이상 더 슬라이드하도록 설정하면 위와 같은 상황이 발생하지 않도록 효과적으로 방지할 수 있습니다
if (Math.abs(x) - Math.abs (y) > 10) {
// 기본 이벤트 방지
moveEvent.preventDefault()
childParent.css("left", parseFloat(currentPosition) x);
moveDirect = x > 0 ? "sub": "추가"
} else {
}
} /Y축 방향으로 스크롤
moveEvent.preventDefault() ;
var moveY = touch.pageY;
var y = moveY - startY
childParent.css("top",parseFloat(currentPosition) ) y);
moveDirect = y > 0 ? " sub": "add";
childParent[0].ontouchend =
}
// 화면
function handlerTouchEnd() {
//손가락의 이동 방향에 따라 표시할 다음 노드 번호를 결정
var fast = false
if (moveDirect == "add; ") {
if (setting.current == 개수) {
setting .current = 1;
} else {
setting.current = settings.current 1;
}
} else {
if (setting.current == 0) {
설정 .current = 개수 - 1
fast = true
} else {
setting.current = 설정.현재 - 1;
}
}
// 해당 처리 함수 호출
setting.currentMethod.process(setting.current, fast)
childParent[0].ontouchend = null; 🎜>childParent[0].ontouchmove = null;
}
}
}
/**
* 자동 캐러셀
*/
function processAuto() {
if (setting.ptr ) {
clearInterval(setting.ptr);
setting.ptr = null
}
//캐러셀 타이머 설정
setting.ptr = setInterval(function() {
if (setting.current == counts) {
setting.current = 1;
} else if (setting.current == counts - 1) {
// 마지막 항목으로 캐러셀
setting .current = 개수;
} else {
setting.current = 설정 .current 1
}
var index = 설정.current
if (index != 0) {
prevBtn.removeClass(setting.btnDisable);
} else if (!setting .cycle) {
prevBtn.addClass(setting.btnDisable)
}
if (index != counts - 1 ) {
nextBtn.removeClass(setting.btnDisable);
} else if (!setting.cycle) {
nextBtn.addClass(setting.btnDisable)
setting.currentMethod. process(setting.current);
},
setting.timeFlag) ;
}
// 반환 함수를 호출하여 필요한 사진의 일련번호를 지정할 수 있습니다. 일반적으로 작은 그림을 클릭한 후 큰 그림을 보고 싶을 때 사용되며, 작은 그림을 클릭할 때는 캐러셀 이벤트만 연결하면 됩니다. 이 함수를 호출하고 해당 일련 번호를 전달합니다.
return function(index) {
if (index index = 0
} else if (index >= 개수) {
색인 = 개수 - 1
}
setting.currentMethod.process(index)
}

성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
JavaScript 및 웹 : 핵심 기능 및 사용 사례JavaScript 및 웹 : 핵심 기능 및 사용 사례Apr 18, 2025 am 12:19 AM

웹 개발에서 JavaScript의 주요 용도에는 클라이언트 상호 작용, 양식 검증 및 비동기 통신이 포함됩니다. 1) DOM 운영을 통한 동적 컨텐츠 업데이트 및 사용자 상호 작용; 2) 사용자가 사용자 경험을 향상시키기 위해 데이터를 제출하기 전에 클라이언트 확인이 수행됩니다. 3) 서버와의 진실한 통신은 Ajax 기술을 통해 달성됩니다.

JavaScript 엔진 이해 : 구현 세부 사항JavaScript 엔진 이해 : 구현 세부 사항Apr 17, 2025 am 12:05 AM

보다 효율적인 코드를 작성하고 성능 병목 현상 및 최적화 전략을 이해하는 데 도움이되기 때문에 JavaScript 엔진이 내부적으로 작동하는 방식을 이해하는 것은 개발자에게 중요합니다. 1) 엔진의 워크 플로에는 구문 분석, 컴파일 및 실행; 2) 실행 프로세스 중에 엔진은 인라인 캐시 및 숨겨진 클래스와 같은 동적 최적화를 수행합니다. 3) 모범 사례에는 글로벌 변수를 피하고 루프 최적화, Const 및 Lets 사용 및 과도한 폐쇄 사용을 피하는 것이 포함됩니다.

Python vs. JavaScript : 학습 곡선 및 사용 편의성Python vs. JavaScript : 학습 곡선 및 사용 편의성Apr 16, 2025 am 12:12 AM

Python은 부드러운 학습 곡선과 간결한 구문으로 초보자에게 더 적합합니다. JavaScript는 가파른 학습 곡선과 유연한 구문으로 프론트 엔드 개발에 적합합니다. 1. Python Syntax는 직관적이며 데이터 과학 및 백엔드 개발에 적합합니다. 2. JavaScript는 유연하며 프론트 엔드 및 서버 측 프로그래밍에서 널리 사용됩니다.

Python vs. JavaScript : 커뮤니티, 라이브러리 및 리소스Python vs. JavaScript : 커뮤니티, 라이브러리 및 리소스Apr 15, 2025 am 12:16 AM

Python과 JavaScript는 커뮤니티, 라이브러리 및 리소스 측면에서 고유 한 장점과 단점이 있습니다. 1) Python 커뮤니티는 친절하고 초보자에게 적합하지만 프론트 엔드 개발 리소스는 JavaScript만큼 풍부하지 않습니다. 2) Python은 데이터 과학 및 기계 학습 라이브러리에서 강력하며 JavaScript는 프론트 엔드 개발 라이브러리 및 프레임 워크에서 더 좋습니다. 3) 둘 다 풍부한 학습 리소스를 가지고 있지만 Python은 공식 문서로 시작하는 데 적합하지만 JavaScript는 MDNWebDocs에서 더 좋습니다. 선택은 프로젝트 요구와 개인적인 이익을 기반으로해야합니다.

C/C에서 JavaScript까지 : 모든 것이 어떻게 작동하는지C/C에서 JavaScript까지 : 모든 것이 어떻게 작동하는지Apr 14, 2025 am 12:05 AM

C/C에서 JavaScript로 전환하려면 동적 타이핑, 쓰레기 수집 및 비동기 프로그래밍으로 적응해야합니다. 1) C/C는 수동 메모리 관리가 필요한 정적으로 입력 한 언어이며 JavaScript는 동적으로 입력하고 쓰레기 수집이 자동으로 처리됩니다. 2) C/C를 기계 코드로 컴파일 해야하는 반면 JavaScript는 해석 된 언어입니다. 3) JavaScript는 폐쇄, 프로토 타입 체인 및 약속과 같은 개념을 소개하여 유연성과 비동기 프로그래밍 기능을 향상시킵니다.

JavaScript 엔진 : 구현 비교JavaScript 엔진 : 구현 비교Apr 13, 2025 am 12:05 AM

각각의 엔진의 구현 원리 및 최적화 전략이 다르기 때문에 JavaScript 엔진은 JavaScript 코드를 구문 분석하고 실행할 때 다른 영향을 미칩니다. 1. 어휘 분석 : 소스 코드를 어휘 단위로 변환합니다. 2. 문법 분석 : 추상 구문 트리를 생성합니다. 3. 최적화 및 컴파일 : JIT 컴파일러를 통해 기계 코드를 생성합니다. 4. 실행 : 기계 코드를 실행하십시오. V8 엔진은 즉각적인 컴파일 및 숨겨진 클래스를 통해 최적화하여 Spidermonkey는 유형 추론 시스템을 사용하여 동일한 코드에서 성능이 다른 성능을 제공합니다.

브라우저 너머 : 실제 세계의 JavaScript브라우저 너머 : 실제 세계의 JavaScriptApr 12, 2025 am 12:06 AM

실제 세계에서 JavaScript의 응용 프로그램에는 서버 측 프로그래밍, 모바일 애플리케이션 개발 및 사물 인터넷 제어가 포함됩니다. 1. 서버 측 프로그래밍은 Node.js를 통해 실현되며 동시 요청 처리에 적합합니다. 2. 모바일 애플리케이션 개발은 재교육을 통해 수행되며 크로스 플랫폼 배포를 지원합니다. 3. Johnny-Five 라이브러리를 통한 IoT 장치 제어에 사용되며 하드웨어 상호 작용에 적합합니다.

Next.js (백엔드 통합)로 멀티 테넌트 SAAS 애플리케이션 구축Next.js (백엔드 통합)로 멀티 테넌트 SAAS 애플리케이션 구축Apr 11, 2025 am 08:23 AM

일상적인 기술 도구를 사용하여 기능적 다중 테넌트 SaaS 응용 프로그램 (Edtech 앱)을 구축했으며 동일한 작업을 수행 할 수 있습니다. 먼저, 다중 테넌트 SaaS 응용 프로그램은 무엇입니까? 멀티 테넌트 SAAS 응용 프로그램은 노래에서 여러 고객에게 서비스를 제공 할 수 있습니다.

See all articles

핫 AI 도구

Undresser.AI Undress

Undresser.AI Undress

사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover

AI Clothes Remover

사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool

Undress AI Tool

무료로 이미지를 벗다

Clothoff.io

Clothoff.io

AI 옷 제거제

AI Hentai Generator

AI Hentai Generator

AI Hentai를 무료로 생성하십시오.

뜨거운 도구

MinGW - Windows용 미니멀리스트 GNU

MinGW - Windows용 미니멀리스트 GNU

이 프로젝트는 osdn.net/projects/mingw로 마이그레이션되는 중입니다. 계속해서 그곳에서 우리를 팔로우할 수 있습니다. MinGW: GCC(GNU Compiler Collection)의 기본 Windows 포트로, 기본 Windows 애플리케이션을 구축하기 위한 무료 배포 가능 가져오기 라이브러리 및 헤더 파일로 C99 기능을 지원하는 MSVC 런타임에 대한 확장이 포함되어 있습니다. 모든 MinGW 소프트웨어는 64비트 Windows 플랫폼에서 실행될 수 있습니다.

DVWA

DVWA

DVWA(Damn Vulnerable Web App)는 매우 취약한 PHP/MySQL 웹 애플리케이션입니다. 주요 목표는 보안 전문가가 법적 환경에서 자신의 기술과 도구를 테스트하고, 웹 개발자가 웹 응용 프로그램 보안 프로세스를 더 잘 이해할 수 있도록 돕고, 교사/학생이 교실 환경 웹 응용 프로그램에서 가르치고 배울 수 있도록 돕는 것입니다. 보안. DVWA의 목표는 다양한 난이도의 간단하고 간단한 인터페이스를 통해 가장 일반적인 웹 취약점 중 일부를 연습하는 것입니다. 이 소프트웨어는

SecList

SecList

SecLists는 최고의 보안 테스터의 동반자입니다. 보안 평가 시 자주 사용되는 다양한 유형의 목록을 한 곳에 모아 놓은 것입니다. SecLists는 보안 테스터에게 필요할 수 있는 모든 목록을 편리하게 제공하여 보안 테스트를 더욱 효율적이고 생산적으로 만드는 데 도움이 됩니다. 목록 유형에는 사용자 이름, 비밀번호, URL, 퍼징 페이로드, 민감한 데이터 패턴, 웹 셸 등이 포함됩니다. 테스터는 이 저장소를 새로운 테스트 시스템으로 간단히 가져올 수 있으며 필요한 모든 유형의 목록에 액세스할 수 있습니다.

SublimeText3 Mac 버전

SublimeText3 Mac 버전

신 수준의 코드 편집 소프트웨어(SublimeText3)

메모장++7.3.1

메모장++7.3.1

사용하기 쉬운 무료 코드 편집기