简体   繁体   English

插件不与div交互

[英]Plugin doesn't interacting with div

I use a plugin called grid rotator it works with div objects that are already have been declared in the html page. 我使用一个名为grid rotator的插件,该插件可用于html页面中已经声明的div对象。 But the issue is if I append a div with jquery into my html and when I initialize the plugin again to the div. 但是问题是,如果我将带有jquery的div附加到我的html中,以及当我再次将插件初始化到div时。 The plugin stopts working for the div. 插件停止为div工作。 How can I fix this problem so that the plugin works even after I append divs with jquery later when the page is loaded? 我如何解决此问题,以便即使稍后在加载页面时用jQuery附加div后仍能正常工作该插件? Anyone? 任何人?

    <script type="text/javascript">
      $(function() {

        var BASE_PATH = 'js/brands/';
        var array_brands = <?php echo json_encode($array_brands); ?>;
        var directory = null;
        $.each(array_brands, function(key, value) {
            arr = array_brands[key];
            if($('.' + arr['directories'])) {
                $.each($(this), function (key, value) {
                    var res = $(this)[key]['filenames'].split(',');
                    directory = $(this)[key]['directories'];
                    console.log($(this)[key]['filenames']);
                    $.each(res, function(key, value) {
                        $('<li><a href="#"><img src="' + BASE_PATH + directory + '/' + res[key] + '"/></a></li>').clone().appendTo($('#' + 'ri-grid-' + directory + ' ul');
                     });
                });
            }
$.each($('#' + 'ri-grid-' + directory + ' ul li'), function() {
    console.log($(this));
});
console.log($('#ri-grid-' + directory).gridrotator());
            $('#ri-grid-' + directory).gridrotator( {
                  rows    : 3,
                  columns   : 15,
                  animType  : 'fadeInOut',
                  animSpeed : 1000,
                  interval  : 600,
                  step    : 1,
                  w320    : {
                    rows  : 3,
                    columns : 4
                  },
                  w240    : {
                    rows  : 3,
                    columns : 4
                  }
                } );



        });

Thanks in advance. 提前致谢。

I assume you are using http://tympanus.net/codrops/2012/08/02/animated-responsive-image-grid/ Correct me if I am wrong. 我假设您使用的是http://tympanus.net/codrops/2012/08/02/animated-sensitive-image-grid/如果我错了,请纠正我。 The issue sounds to me like the div is being added to your document after grid rotator is initialized. 在我看来,这个问题听起来像是在初始化Grid Rotator之后将div添加到您的文档中。 If this is your plugin you want to put the initialization function after the div being added in jquery. 如果这是您的插件,则要在jQuery中添加div之后放置初始化函数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM