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

  • SEARCH
  • Home
  • 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 7496451
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T18:37:06+00:00 2026-05-29T18:37:06+00:00

I’m working with a jQuery plug-in useful to zoom the resized background images with

  • 0

I’m working with a jQuery plug-in useful to zoom the resized background images with the mouse interaction.

To make it work, I thought to use an array of objects with the width and height of a background-image of every element I bring to it.

To do this I’ve created an empty img element, set the src attribute to the background image, and once it’s loaded getting width and height.

I’ve thought to handle it starting in a for loop which prepares every image, when the jQuery event load is called I create the new array element with every info about the loaded image.

It seems the load event sets the first loaded image, and apply the same properties to every element loaded after it, how can I avoid this problem?

// this is a portion of the plugin

var setImageSize = function (i) {
    return function (e) {
        // I use the extend method only to get different zoom animation if they are added by the user
        instances[i] = {id:i, element:this_obj.get(i), settings:$.extend(true, defaults, options)};
        instances[i].settings.bg.url = getBackgroundUrl(i);
        instances[i].settings.bg.width = parseInt($(this).width());
        instances[i].settings.bg.height = parseInt($(this).height());
        updateDefaultValues(instances[i]);
        $(instances[i].element).hover(setRollOver(i), setRollOut(i));
        $(window).resize(getUpdateDefaultValues(i));
        $('#debug').html($('#debug').html() + 'image loaded: ' + i + ' url:' + instances[i].settings.bg.url +'<br/>width: '+ instances[i].settings.bg.width +' height: '+ instances[i].settings.bg.height +'<br>- - - - - <br>');
        $(this).remove();
    }
}

var prepareImageSize = function (i) {
    var img = $('<img id="jquery-background-zoom-'+i+'"/>');
    img.hide();
    img.bind('load', setImageSize(i));
    $('body').append(img);
    img.attr('src', getBackgroundUrl(i));
}

var init = function () {
    for (var i = 0; i < this_obj.length; i ++) {
        prepareImageSize (i);
    }
}

init();

I’ve reported a full working example here at http://jsfiddle.net/tonino/CFPTa/

In the plug-in I’ve added a script to see how the images are set, then if you try to interact with the images you’ll notice the props of every images are overwritten by the last loaded image, I’m not sure how?

It seems like the load event overwrite previous load event or something, how can I fix it?

  • 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-29T18:37:07+00:00Added an answer on May 29, 2026 at 6:37 pm

    One thing I notice is you pass options into the init function, but never use them…

    I think

    $.extend(true, defaults, options) 
    

    isn’t doing what you want. That says take options and add it to defaults. You actually want

    $.extend(true, new Object(), defaults, options)
    

    or if you want your code to be less legible you could do it the way they suggest in the jQuery API docs

    $.extend(true, {}, object1, object2);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example

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.