重写jQuery中的本机JavaScript [英] rewrite native javascript in jQuery

查看:67
本文介绍了重写jQuery中的本机JavaScript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个本机JavaScript函数,我想用jQuery重写它.你能帮助我吗?远远超出我的理解...

I've got a native JavaScript function and I'd like to rewrite it in jQuery. Can you help me? Way beyond my understanding...

快速解决请为我重构代码"的评论-我不是要您重写工作,我只是想获得一些有关如何重写此内容的指导.正如大家都曾经经历过的那样,可能很难找到有用的文档,教程和书籍.任何建议都欢迎,但是..

Quickly addressing the "please refactor my code for me" comments- I'm not asking you to rewrite the work, I'd simply like some guidance on how to rewrite this. As you all have experienced at some point, documentation, tutorials, and books that are helpful can be difficult to find. Any advice is welcome, but..

if(you dont have anything nice to say){
    dont
}



 var RESIZER = function(){ 

    this.prevWidth = resizee.offsetWidth;
    this.prevHeight = resizee.offsetHeight;

    this.resizee = resizeeContainer.getElementsByTagName('video')[0];
    this.resizeeContainer = resizee.parentNode;
    this.resizeeStyle = this.resizee.style;

    var ratio = this.resizee.offsetHeight/this.resizee.offsetWidth;

    var that = this;

    this.Init = function(){
        if( that.resizeeContainer.className.lastIndexOf("resizerd")>=0 )
        {
            var resizeeContOffsetWidth = that.resizeeContainer.offsetWidth;
            var resizeeOffsetWidth = that.resizee.offsetWidth;
            var resizeeContOffsetHeight = that.resizeeContainer.offsetHeight;
            var resizeeOffsetHeight = that.resizee.offsetHeight;

            if(that.prevWidth!= resizeeContOffsetWidth)
            {
                that.prevWidth = resizeeContOffsetWidth;
                var desired = resizeeContainer.offsetHeight/resizeeContainer.offsetWidth;
                if(desired>ratio){
                    that.resizeeStyle.width=resizeeContOffsetWidth*desired+resizeeContOffsetWidth*desired+"px";
                    that.resizeeStyle.left = -1*(resizeeOffsetWidth-resizeeContOffsetWidth)/2+'px';
                }
                else{ 
                 that.resizeeStyle.cssText="width:100%;height:auto;position:fixed;";
                }
            }

            if(that.prevHeight!=resizeeContOffsetHeight)
            { 
                that.prevHeight = resizeeContOffsetHeight;
                var desired = resizeeContOffsetHeight/resizeeContOffsetWidth;  
                if(desired>ratio){  console.log(ratio);
                    //that.resizeeStyle.top = '0px';
                    that.resizeeStyle.left = -1*(resizeeOffsetWidth-resizeeContOffsetWidth)/2+'px';
                    that.resizeeStyle.width = resizeeContOffsetHeight*desired+resizeeContOffsetHeight/desired+'px';
                }
                else
                {
                    that.resizeeStyle.top = -1*(resizeeOffsetHeight-resizeeContOffsetHeight)/2+'px';

                }
            }

        }
    };
};

var myResizerObject = new RESIZER();
window.onresize = myResizerObject.Init;

推荐答案

开发jQuery插件虽然并不困难,但也不是一件容易的事.做到这一点的唯一方法是从教程开始并学习内容.然后,您可以编写一段代码,并将该代码转换为可正常运行的插件.但是您必须先学习一些东西.

Developing jQuery plugins, while not real difficult, is not trivial either. The only way to do it is to start with a tutorial and learn the ins and outs. Then you can take a piece of code and turn that code into a functioning plugin. But you have to learn some things first.

如果您还没有完成jQuery初学者插件教程,我将: http://docs. jquery.com/Plugins/Authoring 尝试首先开发一个简单的插件,例如输入字段验证插件或类似的东西.

If you haven't gone through the jQuery beginner plugin tutorial, I would: http://docs.jquery.com/Plugins/Authoring Try developing a simple plugin first, like an input field validation plugin or something.

我不确定本机脚本和浏览器以不同的方式解释的含义;一些JS与浏览器有关. jQuery本机函数应与浏览器无关.

I'm not sure what you mean by the native script and browsers interpreting differently; some JS is browser-dependent. jQuery-native functions should be browser-agnostic.

这篇关于重写jQuery中的本机JavaScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆