how to extract single function from jquery library?

血红的双手。 提交于 2019-12-24 06:08:33

问题


I want to use only three methods from the jquery library without importing the whole library in my file, so is there any way to extract only fadeIn(), fadeOut(), load() from jquery?


回答1:


You could look at the source code and try to remove anything not required for the fadeIn and fadeOut methods, but you would likely end up with most of the library.

Overall jQuery is not designed to be taken ala cart, it is designed to be a single small footprint library. If it is not small enough for you needs, you might check out http://zeptojs.com.




回答2:


The fade methods are available a la cart, but they require "Effects Core". See the "dependencies" section here http://docs.jquery.com/UI/Effects/fade. You can bundle individual libraries for download here:

http://jqueryui.com/download

load appears to be part of jQuery (not jQuery UI), so you can just load the jQuery library. As @Karl Rosaen mentions, you can review the source and try to extract an individual function (find its dependencies too!). Or you can go a little more native and start using XHR, or find a library that accomplishes the same functionality.




回答3:


You'll find the source for the jQuery effects here, and you will notice that fadeIn/fadeOut are just shortcuts for animating opacity. So basicly what you need is the animate function, and that will need some of the other core functions etc.

The Ajax source is here, and it' basicly the same, load() is just a shortcut for jQuery.ajax, wich in turn uses other core jQuery functions.

You'd probably be better of just using the library as is, or searching the web and try to find similar plain JS functions for what you need.



来源:https://stackoverflow.com/questions/10281231/how-to-extract-single-function-from-jquery-library

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!