Is it possible to use JQuery and Zepto library at the same time?

怎甘沉沦 提交于 2019-12-10 11:14:58

问题


<script src="jsv3/jquery-1.7.1.min.js"></script>
<script src="jsv3/jquery-ui-1.9.2.custom.min.js"></script>
<script src="jsv3/jquery.mobile-events.js"></script>
<script src="jsv3/jquery.ui.touch-punch.js"></script>
<script src="jsv3/turn.js"></script>
<script src="jsv3/jquery.viewport.min.js"></script>
<script src="jsv3/jquery.scraggable.js"></script>
<script src="jsv3/history.js"></script>
<script src='http://vod.hkheadline.com/player/jwplayer/jwplayer.js'></script>
<script src="jsv3/libs/zepto.js"></script>  //  Can not use
<script src="jsv3/zepto.flickable.js"></script>
<script src="jsv3/onload_mobile.js"></script>

Currently I am using several jquery plugins to implement a webapp. I recently find a library call flickable.js and add to the app . However, it use zepto library, so when I add it , it return error of Uncaught TypeError: Object [object Object] has no method 'flickable' , How to fix it? thanks


回答1:


use jQuery's function noConflict.

jQuery.noConflict();

more details here.. http://docs.jquery.com/Using_jQuery_with_Other_Libraries

<script src="jsv3/jquery-1.7.1.min.js"></script>
<script src="jsv3/jquery-ui-1.9.2.custom.min.js"></script>
<script src="jsv3/jquery.mobile-events.js"></script>
<script src="jsv3/jquery.ui.touch-punch.js"></script>
<script src="jsv3/turn.js"></script>
<script src="jsv3/jquery.viewport.min.js"></script>
<script src="jsv3/jquery.scraggable.js"></script>
<script src="jsv3/history.js"></script>
<script src='http://vod.hkheadline.com/player/jwplayer/jwplayer.js'></script>

<script type="text/javascript">
  $.noConflict(false);
</script>

<script src="jsv3/libs/zepto.js"></script>   
<script src="jsv3/zepto.flickable.js"></script>
<script src="jsv3/onload_mobile.js"></script>



回答2:


you can do this.

jQuery.noConflict();
delete window.$;

and then load the zepto script.



来源:https://stackoverflow.com/questions/14210588/is-it-possible-to-use-jquery-and-zepto-library-at-the-same-time

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