Fancybox :TypeError: $(…).Fancybox is not a function

筅森魡賤 提交于 2019-12-21 02:52:09

问题


I want to open a fancy box, But it give a Type error, can you please help me to solve this problem

view page contain following code

<script type="text/java script">
$(document).ready(function() {
$('.fancybox').fancybox();
});
</script>

HTML code

<a class="fancybox" href="#inline1" title="Add New Vessel">
    <div class="right-head-buton" style="color:#fff">Add New Vessel</div>
    </a>

I want to open inline id div in fancy box

<div id="inline1" style="width:800px;display: none;">
    <div class="lightbox">
    <?php echo $this->action('add', 'agency', NULL); ?>
    </div>
    </div>

In Bootstrap I include two files

$view->headScript()->appendFile($view->baseUrl('/public/js/jquery-1.10.1.min.js'));
$view->headScript()->appendFile($view->baseUrl('/public/js/jquery.fancybox.js?v=2.1.5'));

回答1:


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

noconflict in your jQuery in a single page may be this answer will help you. and one more thing use highest version of a javascript file like only use jquery 1.3.min.js between jquery 1.3.min.js and jquery 1.3.5.min.js




回答2:


The "no conflict" trick helps. To use an author's existing plugin code, you can wrap it in an IIFE:

// IIFE passing in jQuery.noConflict()
(function(jQuery){

     // Original author's plugin code
     // ...
     jQuery("a.fancybox").fancybox({ ... }
     // ...

})(jQuery.noConflict());

I've had to do this for two WordPress plugins to get them working with Firefox: Easy FancyBox and FancyBox for Wordpress. I hope this helps.



来源:https://stackoverflow.com/questions/21926225/fancybox-typeerror-fancybox-is-not-a-function

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