本文主要介绍了jQuery返回定位插件的相关知识,具有很好的参考价值。下面跟着小编一起来看下吧,希望能帮助到大家。
一、jQuery 提供开发者开发插件的几种模式
1.$.extend(); //这个方法是绑定在$上面的。可以通过$直接调用
2.$.fn.方法名 //这个方法是绑定在Dom对象上面的可以通过$('').方法名();调用
3.$.widget //通过jQuery UI 部件工厂模式创建。
二、插件的开发过程
1.$.extend();
这个方法其实很简单,只是像$上面添加了一个静态的方法而已。主要用途是对插件api的扩展.
eg:
//$.extend();为了防止,变量和方法之间的相互污染,我们采用闭包的模式。 (function($,factory){ var obj = factory(); $.extend({ sayHelloWorld:obj.firstApply, }) $.secondApply = obj.secondApply; })(jQuery,function(){ var obj = { firstApply(){ console.log('hello world'); }, secondApply(){ console.log('直接绑定到$上'); }, }; return obj; }); $.sayHelloWorld();//hello world $.secondApply(); //直接绑定到$上 /*从上面的2种绑定方式可以看出用$.extend();对jQuery方法进行拓展, 其实和直接绑定到$上是一样的效果*/
2.$.fn.方法名。 (方法名 其实就是插件名)。
a.插件结构
<p>app</p> //$.fn.插件名字 (logText); (function($,factory){ $.fn.logText = factory(); })(jQuery,function(){ var logText = function(){ console.log(this.text()); return this; } return logText; }); $("#app").logText(); //app 通过DOM元素之间调用该方法。并返回该对象。这也是jQuery实现链式操作的技巧。 var h = $("#app").logText().height(); // app console.log(h); //18 //这样就可以自定义方法了。
在jQuery插件的开发过程中,其实主要是通过第二种模式($.fn.插件名)开发的。因为jQuery的强大之处就是对Dom的操作.
b.一个插件的强大之处就是参提供周全的参数。以及方便使用者对参数进行扩展。
<p>app</p> //$.fn.插件名字 (myPuglin); (function(global,$,factory){ var common = factory(); //封装插件使用到的函数。 $.fn.myPuglin = function(opts){ //插件的名称 var defaults = {}; //默认的api opts = $.extend(defaults,opts || {}); //对api的拓展 /* * * 要执行的功能 * */ console.log(opts.hello); return this; } })(window,jQuery,function(){ var common = { a(opt){ return opt; }, }; return common; }); $("#app").myPuglin({hello:'hello world'}); //hello world
准备工作已经完毕。那么下面会一个插件为列子,来讲解
3.工作中经常用到的列表到详情。返回来需要保留该位置的插件。(返回定位) savePositon(); $.fn.savePosition
nbsp;html> <meta> <meta> <title>Title</title> <style> @media screen and (max-width: 319px) { html { font-size: 85.33333px; } } @media screen and (min-width: 320px) and (max-width: 359px) { html { font-size: 85.33333px; } } @media screen and (min-width: 360px) and (max-width: 374px) { html { font-size: 96px; } } @media screen and (min-width: 375px) and (max-width: 383px) { html { font-size: 100px; } } @media screen and (min-width: 384px) and (max-width: 399px) { html { font-size: 102.4px; } } @media screen and (min-width: 400px) and (max-width: 413px) { html { font-size: 106.66667px; } } @media screen and (min-width: 414px) { html { font-size: 110.4px; } } /*CSS Reset*/ body, p, dl, dt, dd, ul, ol, li, h1, h2, h3, h4, h5, h6, pre, code, form, fieldset, legend, input, textarea, p, blockquote, th, td, header, hgroup, nav, section, article, aside, footer, figure, figcaption, menu, button { margin: 0; padding: 0; } li{ list-style: none; } #app{ width: 100%; max-width: 640px; } li { height: 1.2rem; width: 100%; border-bottom: 1px solid #cccccc; text-align: center; line-height: 1.2rem; font-size: 20px; } </style> <script></script> <p> </p>
- 第一页 第1个li
- 第一页 第2个li
- 第一页 第3个li
- 第一页 第4个li
- 第一页 第5个li
- 第一页 第6个li
- 第一页 第7个li
- 第一页 第8个li
- 第一页 第9个li
- 第一页 第10个li
- 第一页 第11个li
- 第一页 第12个li
- 第一页 第13个li
- 第一页 第14个li
- 第一页 第15个li
- 第二页 第1个li
- 第二页 第2个li
- 第二页 第3个li
- 第二页 第4个li
- 第二页 第5个li
- 第二页 第6个li
- 第二页 第7个li
- 第二页 第8个li
- 第二页 第9个li
- 第二页 第10个li
- 第二页 第11个li
- 第二页 第12个li
- 第二页 第13个li
- 第二页 第14个li
- 第二页 第15个li
这个返回定位的插件基本就开发完毕了。当然对于实际的项目中,还有很多的改动。比如返回的时候,一定要把设置的标志参数去掉。
相关推荐:
jQuery scrollFix滚动定位插件_javascript技巧
The above is the detailed content of jQuery return positioning plug-in example tutorial. For more information, please follow other related articles on the PHP Chinese website!

The shift from C/C to JavaScript requires adapting to dynamic typing, garbage collection and asynchronous programming. 1) C/C is a statically typed language that requires manual memory management, while JavaScript is dynamically typed and garbage collection is automatically processed. 2) C/C needs to be compiled into machine code, while JavaScript is an interpreted language. 3) JavaScript introduces concepts such as closures, prototype chains and Promise, which enhances flexibility and asynchronous programming capabilities.

Different JavaScript engines have different effects when parsing and executing JavaScript code, because the implementation principles and optimization strategies of each engine differ. 1. Lexical analysis: convert source code into lexical unit. 2. Grammar analysis: Generate an abstract syntax tree. 3. Optimization and compilation: Generate machine code through the JIT compiler. 4. Execute: Run the machine code. V8 engine optimizes through instant compilation and hidden class, SpiderMonkey uses a type inference system, resulting in different performance performance on the same code.

JavaScript's applications in the real world include server-side programming, mobile application development and Internet of Things control: 1. Server-side programming is realized through Node.js, suitable for high concurrent request processing. 2. Mobile application development is carried out through ReactNative and supports cross-platform deployment. 3. Used for IoT device control through Johnny-Five library, suitable for hardware interaction.

I built a functional multi-tenant SaaS application (an EdTech app) with your everyday tech tool and you can do the same. First, what’s a multi-tenant SaaS application? Multi-tenant SaaS applications let you serve multiple customers from a sing

This article demonstrates frontend integration with a backend secured by Permit, building a functional EdTech SaaS application using Next.js. The frontend fetches user permissions to control UI visibility and ensures API requests adhere to role-base

JavaScript is the core language of modern web development and is widely used for its diversity and flexibility. 1) Front-end development: build dynamic web pages and single-page applications through DOM operations and modern frameworks (such as React, Vue.js, Angular). 2) Server-side development: Node.js uses a non-blocking I/O model to handle high concurrency and real-time applications. 3) Mobile and desktop application development: cross-platform development is realized through ReactNative and Electron to improve development efficiency.

The latest trends in JavaScript include the rise of TypeScript, the popularity of modern frameworks and libraries, and the application of WebAssembly. Future prospects cover more powerful type systems, the development of server-side JavaScript, the expansion of artificial intelligence and machine learning, and the potential of IoT and edge computing.

JavaScript is the cornerstone of modern web development, and its main functions include event-driven programming, dynamic content generation and asynchronous programming. 1) Event-driven programming allows web pages to change dynamically according to user operations. 2) Dynamic content generation allows page content to be adjusted according to conditions. 3) Asynchronous programming ensures that the user interface is not blocked. JavaScript is widely used in web interaction, single-page application and server-side development, greatly improving the flexibility of user experience and cross-platform development.


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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SublimeText3 Linux new version
SublimeText3 Linux latest version

Atom editor mac version download
The most popular open source editor

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.

SublimeText3 Mac version
God-level code editing software (SublimeText3)