javascript - Broaden the scope of functions -
I have written some jQuery functions to change the size of the pictures, keeping their aspect ratio on pageload and changing window sizes. These works work great, but I made them specially for a scenario. Now, another similar scenario has arisen in which I should do almost the same functionality, only with IFrame In the interest of becoming a better coder, and not adding additional code, I can use this code for the iFrames of the site, as well as Here's the jQuery: What is @nnnnnn from comments: Update the function to take the selector as an argument rather than hard-coding? Turn it on: To do this: The above changes will make your work normal , in the sense that you can do this with other DOM objects as long as you specify that How to change the Selector argument to do the same thing you are currently doing, call And this, In addition to this, do not relate to your question, cache your jacose objects, do not re-select the same elements as the same function That means: This is your cache your object, which means that you can find it once, and you can reuse the same object. This makes a difference in performance, because every time you use the $ ('com-background & gt; img') briefly and efficiently. Am I Scenario?
function imageCalc () {$ imgWidth = $ ('com-badge & gt; IMG') width (); $ ImgHeight = $ ('com-badge & gt; IMG'). Height (); $ ImgAspectRatio = $ imgHeight / $ imgWidth; $ ('Com-badge & gt; IMG'). CSS ('margin-left', '-10px'); } Function setImageDims () {$ ('Com-badge & gt; IMG') CSS ('height', function (calshhite) {return $ IMA spacreito * $ ('# main-content'). Width ();}); $ ('Com-badge & gt; IMG'). CSS ('width', function (calvdath) {return $ ('# main-content'). Width () + 20;}); } Function imageResize () {$ ('com-badge & gt; IMG'). CSS ('width', function (resize with) {return $ ("body"). Width ()}); $ ('Com-badge & gt; IMG'). CSS ('Height', Function (Resize Heat) {Return $ IMGSpecretitio * $ ('Com-badge & gt; IMG'). Width ();}); }
function imageCalc () {$ imgWidth = $ ('com-badge & gt; IMG'). Width (); $ ImgHeight = $ ('com-badge & gt; IMG'). Height (); $ ImgAspectRatio = $ imgHeight / $ imgWidth; $ ('Com-badge & gt; IMG'). CSS ('margin-left', '-10px'); }
// Where the selector is your string query function, Choice comparison (selector) {$ imgWidth = $ (selector). Wide (); $ imgHeight = $ (selector). height (); $ ImgAspectRatio = $ imgHeight / $ imgWidth; $ (Selector) CSS ('margin-left', '-10px'); }
// Where the selector is your string query function image cache (selector) {var obj = $ (selector); $ ImgWidth = obj.width (); $ ImgHeight = obj.height (); $ ImgAspectRatio = $ imgHeight / $ imgWidth; Obj.css ('margin-left', '-10px'); }
$ (selector) , you are searching the DOM tree again to find that element, which takes time .
वेबमास्टर्स के लिए html css कोड उदाहरण
ReplyDeleteएक छवि HTML नमूना के आसपास फ़्लोविंग पाठ