简体   繁体   English

Easyslider 1.7实施问题

[英]Easyslider 1.7 implementation issues

I have been trying to implement the easyslider 1.7 plugin from cssglobe. 我一直在尝试从cssglobe实现easyslider 1.7插件。 Sorry could not post hyperlink because im a new user. 抱歉,因为我是新用户,所以无法发布超链接。

I uploaded the test files within the download and everything worked fine as expected. 我在下载中上传了测试文件,并且一切正常。 I then started to implement on my test site. 然后,我开始在测试站点上实施。 I included all files and added the slider id within my site under the header "my work". 我包括了所有文件,并在标题“我的工作”下的站点内添加了滑块ID。 It seems as if no scripts are being initialized. 似乎没有脚本正在初始化。 I've tried so many variations with no avail. 我已经尝试了很多变化,但无济于事。 A fresh set of eyes would be great. 新鲜的眼睛会很棒。

The only thing i did different is i changed the name of "jquery.js" to "jqueryslider.js". 我所做的唯一不同是我将“ jquery.js”的名称更改为“ jqueryslider.js”。 I did this so it would not conflict with other plugins. 我这样做是为了不会与其他插件冲突。 I made this change on the demo site as well and it functioned properly. 我也在演示站点上进行了此更改,并且功能正常。

I have also tried stripping all other scripts and styles with only the easyslider 1.7 styles and scripts with no luck. 我也尝试过仅使用easyslider 1.7样式和脚本来去除所有其他脚本和样式,但是没有运气。

Here is my test site 这是我的测试地点

Here is the demo for easyslider. 这是Easyslider的演示。 www.symplebytes.com/sliderdemo/01.html www.symplebytes.com/sliderdemo/01.html

Thank you, 谢谢,

Here is the code for easySlider1.7.js 这是easySlider1.7.js的代码

(function($) {

$.fn.easySlider = function(options){

    // default configuration properties
    var defaults = {            
        prevId:         'prevBtn',
        prevText:       'Previous',
        nextId:         'nextBtn',  
        nextText:       'Next',
        controlsShow:   true,
        controlsBefore: '',
        controlsAfter:  '', 
        controlsFade:   true,
        firstId:        'firstBtn',
        firstText:      'First',
        firstShow:      false,
        lastId:         'lastBtn',  
        lastText:       'Last',
        lastShow:       false,              
        vertical:       false,
        speed:          800,
        auto:           false,
        pause:          2000,
        continuous:     false, 
        numeric:        false,
        numericId:      'controls'
    }; 

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

    this.each(function() {  
        var obj = $(this);              
        var s = $("li", obj).length;
        var w = $("li", obj).width(); 
        var h = $("li", obj).height(); 
        var clickable = true;
        obj.width(w); 
        obj.height(h); 
        obj.css("overflow","hidden");
        var ts = s-1;
        var t = 0;
        $("ul", obj).css('width',s*w);          

        if(options.continuous){
            $("ul", obj).prepend($("ul li:last-child", obj).clone().css("margin-left","-"+ w +"px"));
            $("ul", obj).append($("ul li:nth-child(2)", obj).clone());
            $("ul", obj).css('width',(s+1)*w);
        };              

        if(!options.vertical) $("li", obj).css('float','left');

        if(options.controlsShow){
            var html = options.controlsBefore;              
            if(options.numeric){
                html += '<ol id="'+ options.numericId +'"></ol>';
            } else {
                if(options.firstShow) html += '<span id="'+ options.firstId +'"><a href=\"javascript:void(0);\">'+ options.firstText +'</a></span>';
                html += ' <span id="'+ options.prevId +'"><a href=\"javascript:void(0);\">'+ options.prevText +'</a></span>';
                html += ' <span id="'+ options.nextId +'"><a href=\"javascript:void(0);\">'+ options.nextText +'</a></span>';
                if(options.lastShow) html += ' <span id="'+ options.lastId +'"><a href=\"javascript:void(0);\">'+ options.lastText +'</a></span>';              
            };

            html += options.controlsAfter;                      
            $(obj).after(html);                                     
        };

        if(options.numeric){                                    
            for(var i=0;i<s;i++){                       
                $(document.createElement("li"))
                    .attr('id',options.numericId + (i+1))
                    .html('<a rel='+ i +' href=\"javascript:void(0);\">'+ (i+1) +'</a>')
                    .appendTo($("#"+ options.numericId))
                    .click(function(){                          
                        animate($("a",$(this)).attr('rel'),true);
                    });                                                 
            };                          
        } else {
            $("a","#"+options.nextId).click(function(){     
                animate("next",true);
            });
            $("a","#"+options.prevId).click(function(){     
                animate("prev",true);               
            }); 
            $("a","#"+options.firstId).click(function(){        
                animate("first",true);
            });             
            $("a","#"+options.lastId).click(function(){     
                animate("last",true);               
            });             
        };

        function setCurrent(i){
            i = parseInt(i)+1;
            $("li", "#" + options.numericId).removeClass("current");
            $("li#" + options.numericId + i).addClass("current");
        };

        function adjust(){
            if(t>ts) t=0;       
            if(t<0) t=ts;   
            if(!options.vertical) {
                $("ul",obj).css("margin-left",(t*w*-1));
            } else {
                $("ul",obj).css("margin-left",(t*h*-1));
            }
            clickable = true;
            if(options.numeric) setCurrent(t);
        };

        function animate(dir,clicked){
            if (clickable){
                clickable = false;
                var ot = t;             
                switch(dir){
                    case "next":
                        t = (ot>=ts) ? (options.continuous ? t+1 : ts) : t+1;                       
                        break; 
                    case "prev":
                        t = (t<=0) ? (options.continuous ? t-1 : 0) : t-1;
                        break; 
                    case "first":
                        t = 0;
                        break; 
                    case "last":
                        t = ts;
                        break; 
                    default:
                        t = dir;
                        break; 
                };  
                var diff = Math.abs(ot-t);
                var speed = diff*options.speed;                     
                if(!options.vertical) {
                    p = (t*w*-1);
                    $("ul",obj).animate(
                        { marginLeft: p }, 
                        { queue:false, duration:speed, complete:adjust }
                    );              
                } else {
                    p = (t*h*-1);
                    $("ul",obj).animate(
                        { marginTop: p }, 
                        { queue:false, duration:speed, complete:adjust }
                    );                  
                };

                if(!options.continuous && options.controlsFade){                    
                    if(t==ts){
                        $("a","#"+options.nextId).hide();
                        $("a","#"+options.lastId).hide();
                    } else {
                        $("a","#"+options.nextId).show();
                        $("a","#"+options.lastId).show();                   
                    };
                    if(t==0){
                        $("a","#"+options.prevId).hide();
                        $("a","#"+options.firstId).hide();
                    } else {
                        $("a","#"+options.prevId).show();
                        $("a","#"+options.firstId).show();
                    };                  
                };              

                if(clicked) clearTimeout(timeout);
                if(options.auto && dir=="next" && !clicked){;
                    timeout = setTimeout(function(){
                        animate("next",false);
                    },diff*options.speed+options.pause);
                };

            };

        };
        // init
        var timeout;
        if(options.auto){;
            timeout = setTimeout(function(){
                animate("next",false);
            },options.pause);
        };      

        if(options.numeric) setCurrent(0);

        if(!options.continuous && options.controlsFade){                    
            $("a","#"+options.prevId).hide();
            $("a","#"+options.firstId).hide();              
        };              

    });

};

})(jQuery);
$("#slider").easySlider is not a function

from firebug 从萤火虫

looks like script is not linked properly 看起来脚本未正确链接

Put this line right after title tag (and before the jquery plugin), and remove the original that you have in your code : 将这一行放在title标签之后(在jquery插件之前),然后删除代码中包含的原始代码:

<script src="http://code.jquery.com/jquery-latest.pack.js" type="text/javascript"></script>

You must always load jquery core files before any plugin, otherwise they wont work. 您必须始终在加载任何插件之前加载jquery核心文件,否则它们将无法工作。

Thanks for the replies, much appreciated. 感谢您的答复,非常感谢。 I ended up using the framework from google code and included all libraries 1. . 我最终使用了来自Google代码的框架,并包含了所有库1 .。

This seemed to have made all my scripts run with no problems. 这似乎使我所有的脚本都能正常运行。

<script src="http://www.google.com/jsapi"></script>  
    <script type="text/javascript">  
        // Load jQuery  
        google.load("jquery", "1");  

                google.setOnLoadCallback(function() {  
                // Your code goes here.  
                });  
        </script>

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

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