Display varying amounts of pictures in varying resolutions

On my website, I want to display a row of 5 images that are resized using media queries to fit the screen. The challenge is that on smaller screens like an iPhone 5S, I only want to show 3 images instead of 5. On larger screens like iPad or other devices, all 5 images should be shown. How can I achieve this without creating a separate mobile site? Should I use JavaScript to determine screen size and send that information to my server to decide how many images to retrieve from the database, or is there a better way?

In addition to the visual aspect, these images need to be updated every X seconds, requiring me to fetch a different number of images from the database based on the screen size.

Any suggestions would be greatly appreciated!

Answer №1

To determine the size of the window, you can utilize JQuery as shown below:

$(window).width()
$(window).height()

If you prefer not to use JQuery, you can achieve the same with plain JavaScript:

window.screen.availHeight
window.screen.availWidth

You can then send these dimensions to your server to determine which images to load.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Having trouble retrieving the value of the second dropdown in a servlet through request.getParameter

I am facing an issue with storing the value of the second dropdown in a servlet after utilizing an ajax call in Java to populate it based on the selection made in the first dropdown. While I was able to successfully store the value of the first dropdown ...

Double Triggering JQuery Event

I have a question regarding changing a property or attribute value and the execution of a change listener. Despite what I've read, in my case, it seems to trigger the listener. $(document).on('keyup change', '.fire', function( ...

I am having trouble getting Vue.js to function properly within HTML when using Django. Can someone please lend me a

The code run Here is the HTML document: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Register</title> <!--javascript extensions--> <script src=' ...

Unable to locate Vue.js $ref reference

I am attempting to dynamically adjust the padding of an element through inline styles, depending on the height of its parent. My approach involves: <div class="stock-rating positive" ref="stockRating"> <div class="stoc ...

Express.js fails to recognize the HTML meta viewport tag

I am currently facing an issue with the code I have written. I am testing it on Chrome 67 on Android 8.1 from two different sites. One site, served by Apache, has the following URL: The other site, served by express.js, has the following URL: Both sites ...

The Django error known as MultiValueDictKeyError occurs when a key

I encountered a MultiValueDictKeyError while working in Django. The issue arises when trying to logout a user from my website using the following code: In HTML </li> <li class="nav-item mr-3"> ...

What is the process of displaying a view using jQuery in an MVC framework?

When I create an area, I use jQuery to call the action to create and save data to the database, and then return JSON. Now, once it is saved, I want it to be rendered in my index view. How can I achieve that with my current code? Is it possible? [HttpPo ...

A design featuring two columns and a fixed footer

I'm struggling to make my 2-column layout display properly with a footer that sticks to the bottom of the page. Despite following all the usual advice, my columns keep expanding beyond their container div, which causes the footer to get pushed off the ...

Manipulating jQuery datepicker settings programmatically from the codebehind

I am in the process of developing a custom user control that incorporates the jQuery date picker widget. The current implementation is as follows: $(function () { $("#datePickerYearMonth").datepicker({ changeMonth: true, changeYear: tr ...

Challenges when working with AJAX/jQuery in terms of fetching JSON data and setting dataType

I am currently facing a challenge with my practice of AJAX/jQuery coding. Despite my efforts to learn and improve, I find the concepts of jQuery and AJAX quite perplexing. Specifically, I am struggling to understand dataTypes and how to manage different ty ...

Switch out the view div element with ui-router

Currently, I am utilizing Angular ui-router to manage various views in the following manner: <div ui-view="header"></div> <div ui-view="nav"></div> <div ui-view></div> Upon Angular loading, the divs are automatically p ...

Show/Hide All Actions in a Vue.js table using Bootstrap styling

In my Vue.js project, I created a bootstrap table to display data loaded from local JSON files. One of the features I added is the ability to Show/Hide details of specific rows, which shows a full message for that row. Now, I'm looking for a way to im ...

Manipulate the text within a canvas element using JavaScript

In this scenario, suppose json.mes represents the received message from Ajax. There is a button implemented to display the message in a canvas box. Although I have attempted to retrieve the message using getElementById (as shown below), it seems to be in ...

Encountering an issue with rendering a custom Ag Grid component in Angular

I am working with 2 components, where one component includes a grid and the other component contains D3 charts. The component in which I am trying to render the chart has a build Column definition function as shown below. I have shared the component that I ...

Create a function in JavaScript that generates all possible unique permutations of a given string, with a special consideration

When given a string such as "this is a search with spaces", the goal is to generate all permutations of that string where the spaces are substituted with dashes. The desired output would look like: ["this-is-a-search-with-spaces"] ["this ...

Receiving a Javascript Promise from a $.ajax request

Trying to convert a $.ajax() statement into an es6 Promise and return it as an es6 promise. The goal is to have an application layer with Create, Update, Delete calls to the Microsoft Dynamics Web API that return an es6 Promise for reuse across multiple pa ...

The Gulp task is failing to generate the CSS file

Greetings! I have a task set up in my gulpfile.js as shown below: const gulp = require('gulp'); const sass = require('gulp-sass'); gulp.task('sass', function(){ return gulp.src('sass/*.scss') .pipe(sass()) ...

Extracting data from websites by manipulating the Document Object Model with the help of Javascript and Ajax

Currently, I am in search of data for educational purposes from a website. Specifically, the website focuses on statistics in web development. The challenge lies in the fact that this particular site uses Javascript/Ajax to constantly update numbers. I w ...

Initiate automatic speech-to-text conversion using HTML5

Is there a way to begin the speech input session without manually clicking on the microphone icon? Perhaps triggering it on window load or document load event instead of the default click event? <input type="text" id="autoStart" x-webkit-speech /> ...

When importing data from a jQuery AJAX load, the system inadvertently generates duplicate div tags

Currently, I am utilizing a script that fetches data from another page and imports it into the current page by using the .load() ajax function. Here is the important line of code: $('#content').load(toLoad,'',showNewContent()) The issu ...