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 583355
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:47:01+00:00 2026-05-13T14:47:01+00:00

My script is supposed to dynamically change the background-position when clicking on a button

  • 0

My script is supposed to dynamically change the background-position when clicking on a button (adding or substracting 1 percent from the current value). Works fine in Fx and Chrome, and ie8 too (i believe), though not in ie7.

Here’s my code:

function makeClicker(index) {
    $('#leftbutton' + index).click(function() {
        var bPos = $('#div' + index).css('background-position');
        bPos = bPos.replace(/%/g, '').split(' ');
        var bPosResult = (1 + parseInt(bPos[0], 0));
        bPos = bPosResult + '% ' + bPos[1] + '%';
        $('#div' + index).css('background-position', bPos);
        $('#vposition' + index).attr("value", bPosResult + '%');
    });
    $('#rightbutton' + index).click(function() {
        var bPos = $('#div' + index).css('background-position');
        bPos = bPos.replace(/%/g, '').split(' ');
        var bPosResult = (-1 + parseInt(bPos[0], 0));
        bPos = bPosResult + '% ' + bPos[1] + '%';
        $('#div' + index).css('background-position', bPos);
        $('#vposition' + index).attr("value", bPosResult + '%');
    });
    $('#upbutton' + index).click(function() {
        var bPos = $('#div' + index).css('background-position');
        bPos = bPos.replace(/%/g, '').split(' ');
        var bPosResult = (1 + parseInt(bPos[1], 0));
        bPos = bPos[0] + '% ' + bPosResult + '%';
        $('#div' + index).css('background-position', bPos);
        $('#hposition' + index).attr("value", bPosResult + '%');
    });
    $('#downbutton' + index).click(function() {
        var bPos = $('#div' + index).css('background-position');
        bPos = bPos.replace(/%/g, '').split(' ');
        var bPosResult = (-1 + parseInt(bPos[1], 0));
        bPos = bPos[0] + '% ' + bPosResult + '%';
        $('#div' + index).css('background-position', bPos);
        $('#hposition' + index).attr("value", bPosResult + '%');
    });
}

for(var i = 1; i <= 5; i++)
    makeClicker(i);

Thanks for any advices on what could cause this.
-Simon

  • 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-13T14:47:02+00:00Added an answer on May 13, 2026 at 2:47 pm

    For Internet Explorer, you need to use the background-position-x and background-position-y attributes.

    Here’s an example on how you can support IE also. I also refactored your code a bit to reduce redundancy:

    function makeClicker(index) {
    
        var el = ['#leftbutton'+index, '#rightbutton'+index, '#upbutton'+index, '#downbutton'+index];
    
        $(el).click(function() {
            var bPosResult;
            var bPos = $('#div' + index).css('background-position').replace(/%/g, '').split(' ');
    
            switch($(this).attr('id')) {
                case 'leftbutton':
                    bPosResult = (1 + parseInt(bPos[0], 0));
                    bPos = bPosResult + '% ' + bPos[1] + '%';
                    break;
                case 'rightbutton':
                    bPosResult = (-1 + parseInt(bPos[0], 0));
                    bPos = bPosResult + '% ' + bPos[1] + '%';
                    break;
                case 'upbutton':
                    bPosResult = (1 + parseInt(bPos[1], 0));
                    bPos = bPos[0] + '% ' + bPosResult + '%';
                    break;
                case 'downbutton':
                    bPosResult = (-1 + parseInt(bPos[1], 0));
                    bPos = bPos[0] + '% ' + bPosResult + '%';
                    break;
            }
    
            // Detect IE
            if(!$.support.cssFloat) {
                $('#div' + index).css({
                    backgroundPositionX: bPos.split[' '][0],
                    backgroundPositionX: bPos.split[' '][1]
                });
            } else {
                $('#div' + index).css('background-position', bPos);
            }
            $('#vposition' + index).attr("value", bPosResult + '%');
        });
    }
    

    I haven’t tested that but it should work.

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

Sidebar

Related Questions

I need to write a java script. This is supposed to validate if the
I have a script that retrieves objects from a remote server through an Ajax
Suppose a shell script (/bin/sh or /bin/bash) contained several commands. How can I cleanly
Suppose there are two scripts Requester.php and Provider.php, and Requester requires processing from Provider
I have the following script. It replaces all instances of @lookFor with @replaceWith in
The following shell script takes a list of arguments, turns Unix paths into WINE/Windows
I have a script that parses the filenames of TV episodes (show.name.s01e02.avi for example),
I'd like to script, preferably in rake, the following actions into a single command:
I need to script the creation of app pools and websites on IIS 6.0.
I have a Perl script that I'm attempting to set up using Perl Threads

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.