Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 814427
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T01:31:11+00:00 2026-05-15T01:31:11+00:00

I want to make this script to work as LIVE() function. Please help me!

  • 0

I want to make this script to work as LIVE() function.
Please help me!

 $(".img img").each(function() {
    $(this).cjObjectScaler({
   destElem: $(this).parent(),
      method: "fit"
    });
 });

the cjObjectScaler script (called in the html header) is this: (thanks for Doug Jones)

(function ($) {
 jQuery.fn.imagesLoaded = function (callback) {
  var elems = this.filter('img'),
   len = elems.length;
  elems.bind('load', function () {
   if (--len <= 0) {
    callback.call(elems, this);
   }
  }).each(function () {
   // cached images don't fire load sometimes, so we reset src.
   if (this.complete || this.complete === undefined) {
    var src = this.src;
    // webkit hack from http://groups.google.com/group/jquery-dev/browse_thread/thread/eee6ab7b2da50e1f
    this.src = '#';
    this.src = src;
   }
  });
 };
})(jQuery);

/*
 CJ Object Scaler
*/
(function ($) {
 jQuery.fn.cjObjectScaler = function (options) {

  /* 
   user variables (settings)
  ***************************************/
  var settings = {
   // must be a jQuery object
   method: "fill",
   // the parent object to scale our object into
   destElem: null,
   // fit|fill
   fade: 0 // if positive value, do hide/fadeIn
  };

  /* 
   system variables
  ***************************************/
  var sys = {
   // function parameters
   version: '2.1.1',
   elem: null
  };

  /* 
   scale the image
  ***************************************/

  function scaleObj(obj) {

   // declare some local variables
   var destW = jQuery(settings.destElem).width(),
    destH = jQuery(settings.destElem).height(),
    ratioX, ratioY, scale, newWidth, newHeight, 
    borderW = parseInt(jQuery(obj).css("borderLeftWidth"), 10) + parseInt(jQuery(obj).css("borderRightWidth"), 10),
    borderH = parseInt(jQuery(obj).css("borderTopWidth"), 10) + parseInt(jQuery(obj).css("borderBottomWidth"), 10),
    objW = jQuery(obj).width(),
    objH = jQuery(obj).height();

   // check for valid border values. IE takes in account border size when calculating width/height so just set to 0
   borderW = isNaN(borderW) ? 0 : borderW;
   borderH = isNaN(borderH) ? 0 : borderH;

   // calculate scale ratios
   ratioX = destW / jQuery(obj).width();
   ratioY = destH / jQuery(obj).height();

   // Determine which algorithm to use
   if (!jQuery(obj).hasClass("cf_image_scaler_fill") && (jQuery(obj).hasClass("cf_image_scaler_fit") || settings.method === "fit")) {
    scale = ratioX < ratioY ? ratioX : ratioY;
   } else if (!jQuery(obj).hasClass("cf_image_scaler_fit") && (jQuery(obj).hasClass("cf_image_scaler_fill") || settings.method === "fill")) {
    scale = ratioX < ratioY ? ratioX : ratioY;
   }

   // calculate our new image dimensions
   newWidth = parseInt(jQuery(obj).width() * scale, 10) - borderW;
   newHeight = parseInt(jQuery(obj).height() * scale, 10) - borderH;

   // Set new dimensions & offset
   jQuery(obj).css({
    "width": newWidth + "px",
    "height": newHeight + "px"//,
   // "position": "absolute",
//    "top": (parseInt((destH - newHeight) / 2, 10) - parseInt(borderH / 2, 10)) + "px",
//    "left": (parseInt((destW - newWidth) / 2, 10) - parseInt(borderW / 2, 10)) + "px"
   }).attr({
    "width": newWidth,
    "height": newHeight
   });

   // do our fancy fade in, if user supplied a fade amount
   if (settings.fade > 0) {
    jQuery(obj).fadeIn(settings.fade);
   }

  }

  /* 
   set up any user passed variables
  ***************************************/
  if (options) {
   jQuery.extend(settings, options);
  }

  /* 
   main
  ***************************************/
  return this.each(function () {

   sys.elem = this;

   // if they don't provide a destObject, use parent
   if (settings.destElem === null) {

    settings.destElem = jQuery(sys.elem).parent();
   }

   // need to make sure the user set the parent's position. Things go bonker's if not set.
   // valid values: absolute|relative|fixed
   if (jQuery(settings.destElem).css("position") === "static") {
    jQuery(settings.destElem).css({
     "position": "relative"
    });
   }

   // if our object to scale is an image, we need to make sure it's loaded before we continue.
   if (typeof sys.elem === "object" && typeof settings.destElem === "object" && typeof settings.method === "string") {

    // if the user supplied a fade amount, hide our image
    if (settings.fade > 0) {
     jQuery(sys.elem).hide();
    }

    if (sys.elem.nodeName === "IMG") {

     // to fix the weird width/height caching issue we set the image dimensions to be auto;
     jQuery(sys.elem).width("auto");
     jQuery(sys.elem).height("auto");

     // wait until the image is loaded before scaling
     jQuery(sys.elem).imagesLoaded(function () {
      scaleObj(this);
     });

    } else {

     scaleObj(jQuery(sys.elem));
    }

   } else {

    console.debug("CJ Object Scaler could not initialize.");
    return;

   }

  });

 };
})(jQuery);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T01:31:12+00:00Added an answer on May 15, 2026 at 1:31 am

    .live() doesn’t work for this, you need to either fire the function again when needed, e.g. in your $.ajax() success or complete callbacks, in .ajaxSuccess(), .ajaxComplete(), or use the .livequery() plugin.

    .live() listens for events to bubble…it doesn’t have any interaction when new elements are added, so it’s not suited for plugins, at least ones that aren’t triggered based on an event.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 440k
  • Answers 440k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You could try using expect to wrap it and see… May 15, 2026 at 5:17 pm
  • Editorial Team
    Editorial Team added an answer // define a function... function ganttEach() { $("td.gantt").each(function() { //… May 15, 2026 at 5:17 pm
  • Editorial Team
    Editorial Team added an answer hg revert will do the trick. It will revert you… May 15, 2026 at 5:17 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.