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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T21:52:39+00:00 2026-06-03T21:52:39+00:00

I have a block of code, no complicated stuff is going on in it,

  • 0

I have a block of code, no complicated stuff is going on in it, and it is based on three different numbers ( viewport widths in my case ) :

if(viewport_width > 1224) {
    $(".shop-items-navigation").initiate_shop({ containerID: "shop-items-wrapper", perPage: 8 }, function(pages){
        current_page = pages.current;
        total_pages = pages.count;
    });
}
if(viewport_width < 1224 && viewport_width > 954) {
    $(".shop-items-navigation").initiate_shop({ containerID: "shop-items-wrapper", perPage: 6 }, function(pages){
        current_page = pages.current;
        total_pages = pages.count;
    });
}
if(viewport_width < 954 && viewport_width > 624) {
    $(".shop-items-navigation").initiate_shop({ containerID: "shop-items-wrapper", perPage: 4 }, function(pages){
        current_page = pages.current;
        total_pages = pages.count;
    });
}
if(viewport_width < 624) {
    $(".shop-items-navigation").initiate_shop({ containerID: "shop-items-wrapper", perPage: 2 }, function(pages){
        current_page = pages.current;
        total_pages = pages.count;
    });
}

So I though ( one method ) to place those three numbers in an array like this :

var widths = [1224, 954, 624];

And after apply an foreach function on it :

for(var i in widths ) {
   ...
}

But I cannot really figure how to wrap that up around those three numbers. The only thing that changes depending on the number in the array is another number :

{ ... perPage: 6 ... }

Which can vary from 8 down to 2. I would like a little help with this if possible, or maybe another way of writing it would be just fine.

  • 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-06-03T21:52:40+00:00Added an answer on June 3, 2026 at 9:52 pm

    You could make a list of objects:

    var limits = [
      { min: 1224, perPage: 8 },
      { min: 954, perPage: 6 },
      { min: 624, perPage: 4 },
      { min: 0, perPage: 2 }
    ];
    

    Then:

    for (var i = 0; viewport_width <= limits[i].min, i++);
    $(".shop-items-navigation").initiate_shop({ containerID: "shop-items-wrapper", perPage: limits[i].perPage }, 
       function(pages){
          current_page = pages.current;
          total_pages = pages.count;
     });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the same block of code repeated with two different variables. This block
I have a block of code that serializes a type into a Html tag.
I have a block of code that works great in 32bit, and I'm trying
I have this block of code where when I hover (click for purposes of
I have a block of code that worked outside of a function, but not
If I have a block of code like this: def show @post = Post.find(params[:id])
Let's say that I have a block of code like this: keysPressed = new
Any way I can get this working? I have a block of code: <p><a
I have a code block that checks certain elements before allowing a form to
i have the following block of code: $(#contact_container form, #contact_details form).live( submit, function(event) {

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.