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 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

This script is supposed to get the current popularity from Mysql, add one digit
My script is supposed to find all related posts from the current posts categories
I'm working on a script that is supposed to install some software from a
I have a script (python) supposed to build up two paths - one in
I have a PHP script that's supposed to take in a URL and search
I'm writing a script that is supposed to run around a bunch of servers
I have a script that is supposed to sit there, happily running in a
I am writing a bash script that is supposed to do some confirmation and
I have a function in a powershell script that is supposed to untar my
I have a Ruby 1.8.6 script that is supposed to take a filename that

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.