This time I will bring you the effect of JQuery making the left and right scrolling of the menu. What are the things to pay attention to when using JQuery to make the left and right scrolling of the menu? The following is a practical case, let's take a look. After half a day, the left and right scrolling menu function developed using JQuery has been completed, and no errors have been found yet. Now take out the complete code and share it!
scrollable.js
JQuery left and right scrolling menu special effects script code reference fragment: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 = $('<p></p>')
.attr('id', 'scrollable_' + content.attr('id'))
.attr('className', options.scrollable_class);
var left = $('<p></p>')
.attr('id', 'scrollable_left_' + content.attr('id'))
.attr('className', options.scrollable_left_class);
left.text(options.leftText);
var container = $('<p></p>')
.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 = $('<p></p>')
.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() 0 && newLeft > container.position.left) {
distance = container.position.left - content.position.left;
scroll = false;
} else if(distance
Default.aspx
JQuery left and right scroll menu special effects page code reference fragment:
<meta>
<title>JQuery左右滚动菜单特效</title>
<script></script>
<script></script>
<style>
.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>
$(function() {
scrollable('#scrollable_content', '#scrollable_render', {
}, function(originalPosition, newPosition) {
return true;
});
});
</script>
<center>
<p></p>
<p>
</p>
<p>
</p>
<p></p>
<p>菜单一</p>
<p></p>
</center>
菜单二
菜单三
菜单四
菜单五
菜单六
菜单七
菜单八
菜单九
菜单十
菜单一
菜单二
菜单三
菜单四
菜单五
菜单六
菜单七
菜单八
菜单九
菜单十
Of course, we also need to quote JQuery framework file, I use jquery-1.4.2.min.jshere. You can search and download it on the Internet, but I will not upload it here. The entire JQuery left and right scrolling menu effect looks like this. I think it's okay, and I hope it can help some friends in need. I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!
Recommended reading:
jQuery implements the function of enlarging the picture when the mouse passes over itjQuery implements the sliding switching of pictures (with code)The above is the detailed content of JQuery makes menu scrolling effect left and right. For more information, please follow other related articles on the PHP Chinese website!

The power of the JavaScript framework lies in simplifying development, improving user experience and application performance. When choosing a framework, consider: 1. Project size and complexity, 2. Team experience, 3. Ecosystem and community support.

Introduction I know you may find it strange, what exactly does JavaScript, C and browser have to do? They seem to be unrelated, but in fact, they play a very important role in modern web development. Today we will discuss the close connection between these three. Through this article, you will learn how JavaScript runs in the browser, the role of C in the browser engine, and how they work together to drive rendering and interaction of web pages. We all know the relationship between JavaScript and browser. JavaScript is the core language of front-end development. It runs directly in the browser, making web pages vivid and interesting. Have you ever wondered why JavaScr

Node.js excels at efficient I/O, largely thanks to streams. Streams process data incrementally, avoiding memory overload—ideal for large files, network tasks, and real-time applications. Combining streams with TypeScript's type safety creates a powe

The differences in performance and efficiency between Python and JavaScript are mainly reflected in: 1) As an interpreted language, Python runs slowly but has high development efficiency and is suitable for rapid prototype development; 2) JavaScript is limited to single thread in the browser, but multi-threading and asynchronous I/O can be used to improve performance in Node.js, and both have advantages in actual projects.

JavaScript originated in 1995 and was created by Brandon Ike, and realized the language into C. 1.C language provides high performance and system-level programming capabilities for JavaScript. 2. JavaScript's memory management and performance optimization rely on C language. 3. The cross-platform feature of C language helps JavaScript run efficiently on different operating systems.

JavaScript runs in browsers and Node.js environments and relies on the JavaScript engine to parse and execute code. 1) Generate abstract syntax tree (AST) in the parsing stage; 2) convert AST into bytecode or machine code in the compilation stage; 3) execute the compiled code in the execution stage.

The future trends of Python and JavaScript include: 1. Python will consolidate its position in the fields of scientific computing and AI, 2. JavaScript will promote the development of web technology, 3. Cross-platform development will become a hot topic, and 4. Performance optimization will be the focus. Both will continue to expand application scenarios in their respective fields and make more breakthroughs in performance.

Both Python and JavaScript's choices in development environments are important. 1) Python's development environment includes PyCharm, JupyterNotebook and Anaconda, which are suitable for data science and rapid prototyping. 2) The development environment of JavaScript includes Node.js, VSCode and Webpack, which are suitable for front-end and back-end development. Choosing the right tools according to project needs can improve development efficiency and project success rate.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Dreamweaver Mac version
Visual web development tools

WebStorm Mac version
Useful JavaScript development tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.
