JQuery는 왼쪽 및 오른쪽 스크롤 메뉴 효과를 구현합니다.
반나절이 지나 JQuery를 이용하여 개발한 좌우 스크롤 메뉴 기능이 완성되었는데, 아직까지 오류는 발견되지 않았습니다. 이제 전체 코드를 꺼내서 공유해보세요!
scrollable.js
JQuery 왼쪽 및 오른쪽 스크롤 메뉴 특수 효과 스크립트 코드 참조 조각:
scrollable = function(content, render, options, beforeScroll) { /* * @author: selfimpr * @blog: http://blog.csdn.net/lgg201 * @e-mail: lgg860911@yahoo.com.cn * * 注意: * 1. content必须自己指定宽度. 如果其中的元素使用块元素, 请使用float: left向左浮动. * 2. 使用时, 尽量自定义样式, 由于本人水平欠佳, 不能作出更加通用的东西, 呵呵. * * 参数解释 * content: 内容元素, 可以是选择器或JQUERY封装的DOM元素 * render: 渲染到的目标容器, 可以是选择器或JQUERY封装的DOM元素 * options: 选项 * scrollable_class: 整体scrollable的外框架样式 , 默认: ui-scrollable * scrollable_left_class: 左按钮的样式, 默认: ui-scrollable-left * scrollable_container_class: 内容容器的样式, 默认: ui-scrollable-container * scrollable_right_class: 右按钮的样式, 默认: ui-scrollable-right * delay: 鼠标放上或点击按钮时两次移动之间的时间间隔, 整数 * speed: 鼠标放上按钮时, 一次移动的距离, 整数 * speedup: 鼠标点下按钮时, 一次移动的距离, 整数 * resizeEvent: 是否监听窗口改变大小的事件, 布尔值, * 监听窗口改变大小时, 在刷新页面后, 感觉显示有点别扭, 所以默认了false * beforeScroll: 内容滚动时候的事件回调方法. * 接受参数(两个对象): 第一个是滚动前内容左右位置, 第二个是滚动后内容左右位置. * 注意: 该事件可以使内容不受边界限制的滚动. */ options.scrollable_class = options.scrollable_class || 'ui-scrollable'; options.scrollable_left_class = options.scrollable_left_class || 'ui-scrollable-left'; options.scrollable_container_class = options.scrollable_container_class || 'ui-scrollable-container'; options.scrollable_right_class = options.scrollable_right_class || 'ui-scrollable-right'; options.leftText = options.leftText || ''; options.rightText = options.rightText || ''; options.delay = options.delay || 20; options.speed = options.speed || 5; options.speedup = options.speedup || 10; options.resizeEvent = options.resizeEvent || false; var render = (typeof render == 'string' ? $(render) : render); var content = (typeof content == 'string' ? $(content) : content); var scrollable = $('<div></div>') .attr('id', 'scrollable_' + content.attr('id')) .attr('className', options.scrollable_class); var left = $('<div></div>') .attr('id', 'scrollable_left_' + content.attr('id')) .attr('className', options.scrollable_left_class); left.text(options.leftText); var container = $('<div></div>') .attr('id', 'scrollable_container_' + content.attr('id')) .attr('className', options.scrollable_container_class); content.css('line-height', '29px') .css('position', 'relative') .css('left', '0px') .css('overflow', 'hidden') .css('float', 'left'); var right = $('<div></div>') .attr('id', 'scrollable_right_' + content.attr('id')) .attr('className', options.scrollable_right_class); right.text(options.rightText); show = function() { scrollable.appendTo(render); container.appendTo(scrollable); left.css('display', ''); right.css('display', ''); content.appendTo(container); left.prependTo(scrollable); right.appendTo(scrollable); if(content.width() <= container.width() + 20) { scrollable.remove('.' + options.scrollable_left_class); scrollable.remove('.' + options.scrollable_right_class); left.css('display', 'none'); right.css('display', 'none'); container.width(content.width()); scrollable.width(container.width()); } container.position = {left: container.css('left').substr(0, -2)} container.position.right = container.position.left + container.width(); content.position = {left: new Number(content.css('left').substr(0, -2))} content.position.right = content.position.left + content.width(); }; show(); var originalBroswerWidth = document.body.clientWidth; window.onresize = function() { if(options.resizeEvent) { var newBroswerWidth = document.body.clientWidth; var percent = newBroswerWidth / originalBroswerWidth; container.width(container.width() * percent); scrollable.width(container.width() + left.width() + right.width()); show(); } originalBroswerWidth = document.body.clientWidth; } var scroll = false; move = function(distance) { var newLeft = content.position.left + distance; var newRight = content.position.right + distance; if(distance > 0 && newLeft > container.position.left) { distance = container.position.left - content.position.left; scroll = false; } else if(distance < 0 && newRight < container.position.right) { distance = content.position.right - container.position.right; scroll = false; } newLeft = content.position.left + distance; newRight = content.position.right + distance; scorll = beforeScroll ? beforeScroll( {left: content.position.left, right: content.position.right}, {left: newLeft, right: newRight}) : scroll; if(scroll) { content.css('left', newLeft + 'px'); content.position.left += distance; content.position.right += distance; setTimeout('move(' + distance + ')', options.delay); } } left.mouseover(function() { scroll = true; move(options.speed); }); right.mouseover(function() { scroll = true; move(-options.speed); }); left.mouseout(function() { scroll = false; }); right.mouseout(function() { scroll = false; }); left.mousedown(function() { scroll = true; move(options.speedup); }); right.mousedown(function() { scroll = true; move(-options.speedup); }); left.mouseup(function() { scroll = false; }); right.mouseup(function() { scroll = false; }); }
Default.aspx
JQuery 왼쪽 및 오른쪽 스크롤 메뉴 특수 효과 페이지 코드 참조 스니펫:
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>JQuery左右滚动菜单特效</title> <script language="javascript" type="text/javascript" src="jquery-1.4.2.min.js"></script> <script language="javascript" type="text/javascript" src="scrollable.js"></script> <style type="text/css"> .scrollable-render{} .button{cursor: hand;} .button:hover > * {background-position: 0 -42px;} .button_left{float: left; background: url(menu_out_left.gif) no-repeat 0 0; width: 4px; height: 26px;} .button_center{float: left; background: url(menu_out_bj.gif) repeat-x 0 0; width: 80px; text-align: center} .button_right{float: left; background: url(menu_out_right.gif) no-repeat 0 0; width: 4px; height: 26px;} .ui-scrollable{width: 800px; height: 29px;} .ui-scrollable-container{float: left; width: 780px; height: inherit; position: relative; overflow: hidden; border-bottom: 1px solid #DDDDDD;} .ui-scrollable-content{float: left; width: 1770px; height: inherit;} .ui-scrollable-left{float: left; background: url(scrollable_left_out.gif) no-repeat 0 0; width: 10px; height:29px; cursor: hand;} .ui-scrollable-right{float: left; background: url(scrollable_right_out.gif) no-repeat 0 0; width: 10px; height:29px; cursor: hand;} .ui-scrollable-left:hover{ float: left; background: url(scrollable_left_on.gif) no-repeat 0 0; width: 10px; height:29px; cursor: hand;} .ui-scrollable-right:hover{float: left; background: url(scrollable_right_on.gif) no-repeat 0 0; width: 10px; height:29px; cursor: hand;} </style> <script type="text/javascript"> $(function() { scrollable('#scrollable_content', '#scrollable_render', { }, function(originalPosition, newPosition) { return true; }); }); </script> </head> <body> <center> <div id="scrollable_render" class="scrollable-render"></div> <div id="scrollable_content" class="ui-scrollable-content"> <div class="button"> <div class="button_left"></div> <div class="button_center">菜单一</div> <div class="button_right"></div> </div> <div class="button"> <div class="button_left"></div> <div class="button_center">菜单二</div> <div class="button_right"></div> </div> <div class="button"> <div class="button_left"></div> <div class="button_center">菜单三</div> <div class="button_right"></div> </div> <div class="button"> <div class="button_left"></div> <div class="button_center">菜单四</div> <div class="button_right"></div> </div> <div class="button"> <div class="button_left"></div> <div class="button_center">菜单五</div> <div class="button_right"></div> </div> <div class="button"> <div class="button_left"></div> <div class="button_center">菜单六</div> <div class="button_right"></div> </div> <div class="button"> <div class="button_left"></div> <div class="button_center">菜单七</div> <div class="button_right"></div> </div> <div class="button"> <div class="button_left"></div> <div class="button_center">菜单八</div> <div class="button_right"></div> </div> <div class="button"> <div class="button_left"></div> <div class="button_center">菜单九</div> <div class="button_right"></div> </div> <div class="button"> <div class="button_left"></div> <div class="button_center">菜单十</div> <div class="button_right"></div> </div> <div class="button"> <div class="button_left"></div> <div class="button_center">菜单一</div> <div class="button_right"></div> </div> <div class="button"> <div class="button_left"></div> <div class="button_center">菜单二</div> <div class="button_right"></div> </div> <div class="button"> <div class="button_left"></div> <div class="button_center">菜单三</div> <div class="button_right"></div> </div> <div class="button"> <div class="button_left"></div> <div class="button_center">菜单四</div> <div class="button_right"></div> </div> <div class="button"> <div class="button_left"></div> <div class="button_center">菜单五</div> <div class="button_right"></div> </div> <div class="button"> <div class="button_left"></div> <div class="button_center">菜单六</div> <div class="button_right"></div> </div> <div class="button"> <div class="button_left"></div> <div class="button_center">菜单七</div> <div class="button_right"></div> </div> <div class="button"> <div class="button_left"></div> <div class="button_center">菜单八</div> <div class="button_right"></div> </div> <div class="button"> <div class="button_left"></div> <div class="button_center">菜单九</div> <div class="button_right"></div> </div> <div class="button"> <div class="button_left"></div> <div class="button_center">菜单十</div> <div class="button_right"></div> </div> </div> </center> </body> </html>
물론 JQuery 프레임워크 파일도 참조해야 합니다. 저는 jquery-1.4.2.min.js를 사용하고 있습니다. 온라인에서 검색하고 다운로드할 수 있지만 여기에는 업로드하지 않겠습니다. . 전체 JQuery 왼쪽 및 오른쪽 스크롤 메뉴 효과는 다음과 같습니다. 괜찮다고 생각하며 도움이 필요한 친구들에게 도움이 되기를 바랍니다.

핫 AI 도구

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

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

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

Video Face Swap
완전히 무료인 AI 얼굴 교환 도구를 사용하여 모든 비디오의 얼굴을 쉽게 바꾸세요!

인기 기사

뜨거운 도구

메모장++7.3.1
사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전
중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기
강력한 PHP 통합 개발 환경

드림위버 CS6
시각적 웹 개발 도구

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

뜨거운 주제











프론트 엔드 개발시 프론트 엔드 열지대 티켓 인쇄를위한 자주 묻는 질문과 솔루션, 티켓 인쇄는 일반적인 요구 사항입니다. 그러나 많은 개발자들이 구현하고 있습니다 ...

기술 및 산업 요구에 따라 Python 및 JavaScript 개발자에 대한 절대 급여는 없습니다. 1. 파이썬은 데이터 과학 및 기계 학습에서 더 많은 비용을 지불 할 수 있습니다. 2. JavaScript는 프론트 엔드 및 풀 스택 개발에 큰 수요가 있으며 급여도 상당합니다. 3. 영향 요인에는 경험, 지리적 위치, 회사 규모 및 특정 기술이 포함됩니다.

JavaScript는 현대 웹 개발의 초석이며 주요 기능에는 이벤트 중심 프로그래밍, 동적 컨텐츠 생성 및 비동기 프로그래밍이 포함됩니다. 1) 이벤트 중심 프로그래밍을 사용하면 사용자 작업에 따라 웹 페이지가 동적으로 변경 될 수 있습니다. 2) 동적 컨텐츠 생성을 사용하면 조건에 따라 페이지 컨텐츠를 조정할 수 있습니다. 3) 비동기 프로그래밍은 사용자 인터페이스가 차단되지 않도록합니다. JavaScript는 웹 상호 작용, 단일 페이지 응용 프로그램 및 서버 측 개발에 널리 사용되며 사용자 경험 및 크로스 플랫폼 개발의 유연성을 크게 향상시킵니다.

동일한 ID로 배열 요소를 JavaScript의 하나의 객체로 병합하는 방법은 무엇입니까? 데이터를 처리 할 때 종종 동일한 ID를 가질 필요가 있습니다 ...

이 기사에서 시차 스크롤 및 요소 애니메이션 효과 실현에 대한 토론은 Shiseido 공식 웹 사이트 (https://www.shiseido.co.jp/sb/wonderland/)와 유사하게 달성하는 방법을 살펴볼 것입니다.

Console.log 출력의 차이의 근본 원인에 대한 심층적 인 논의. 이 기사에서는 Console.log 함수의 출력 결과의 차이점을 코드에서 분석하고 그에 따른 이유를 설명합니다. � ...

JavaScript를 배우는 것은 어렵지 않지만 어려운 일입니다. 1) 변수, 데이터 유형, 기능 등과 같은 기본 개념을 이해합니다. 2) 마스터 비동기 프로그래밍 및 이벤트 루프를 통해이를 구현하십시오. 3) DOM 운영을 사용하고 비동기 요청을 처리합니다. 4) 일반적인 실수를 피하고 디버깅 기술을 사용하십시오. 5) 성능을 최적화하고 모범 사례를 따르십시오.

프론트 엔드에서 VSCODE와 같은 패널 드래그 앤 드롭 조정 기능의 구현을 탐색하십시오. 프론트 엔드 개발에서 VSCODE와 같은 구현 방법 ...
