Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/85.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Jquery插件开发,附加浏览器事件和方法_Javascript_Jquery_Jquery Plugins - Fatal编程技术网

Javascript Jquery插件开发,附加浏览器事件和方法

Javascript Jquery插件开发,附加浏览器事件和方法,javascript,jquery,jquery-plugins,Javascript,Jquery,Jquery Plugins,好吧,我正在学习编写插件,而用于插件编写的jQuery站点非常混乱。我真的想弄清楚如何在我的插件中添加基于浏览器事件触发的方法。所以基本上我有一个插件,可以为移动设备构建一个可滑动的幻灯片。当设备旋转时,我需要它重建新尺寸的幻灯片。现在我有了它,所以它是第一次构建它,但我无法(a)为不同的函数添加方法,以及(b)将事件绑定到那些特定的方法。这是我的密码 (function( $ ){ $.fn.jCarousel = function( options ) { var empt

好吧,我正在学习编写插件,而用于插件编写的jQuery站点非常混乱。我真的想弄清楚如何在我的插件中添加基于浏览器事件触发的方法。所以基本上我有一个插件,可以为移动设备构建一个可滑动的幻灯片。当设备旋转时,我需要它重建新尺寸的幻灯片。现在我有了它,所以它是第一次构建它,但我无法(a)为不同的函数添加方法,以及(b)将事件绑定到那些特定的方法。这是我的密码

(function( $ ){

    $.fn.jCarousel = function( options ) {
    var empty = {} 

    var defaults = { 
        height: $(window).height(),
        width: $(window).width(),
        count: 1,
        amount: $('.swiper', this).length,
        thisone:this,
    };

    var options = $.extend(empty, defaults, options);

    return this.each(function() {

        options.thisone = this;

        amount = $('.swiper', this).length;
        holdWidth = options.width * options.amount;

        $('.swiper', this).height(options.height);
        $(this).height(options.height);
        $('.swiper', this).width(options.width);
        $(this).width(holdWidth);
        $('.swipe_slide',this).width(holdWidth);

      //==================================================================================================================
        //==================================================================================================================

        $('.swiper', this).each(function(i) {
            var nwidth = options.width*i;
            $(this).css('left',nwidth);
        });
        //==================================================================================================================
        //==================================================================================================================     
        //==================================================================================================================
        //==================================================================================================================

        $('.swipe_slide', this).swipe(function(evt, data) {
            if(data.direction=='left'){
                //alert('count: '+options.count+" amount: "+options.amount);
                if(options.count != options.amount){
                    moveWidth = options.count * -options.width;
                    $('.swipe_slide',options.thisone).css( "left" ,moveWidth );
                    options.count++
                }else{
                    return    
                }
            }else{
                if(options.count!=1){    
                    moveWidth = moveWidth+ options.width;
                    $('.swipe_slide',options.thisone).css( "left" ,moveWidth );
                    options.count--
                }
                else{
                    return
                }
            }
        });    
        //==================================================================================================================    
        //==================================================================================================================  
        });
    };

})( jQuery );
您必须稍微重构插件,以便该函数存储传递给它的选项,否则在方向更改时再次运行该函数会将选项重置为默认值

您必须稍微重构插件,以便该函数存储传递给它的选项,否则在方向更改时再次运行该函数会将选项重置为默认值

$(window).bind('orientationchange', $.fn.jCarousel);