Grid featuring interactive irregular shapes

I'm facing a challenge in developing this functionality because it needs to be compatible with IE9+ so using css clip-path is not an option ( http://caniuse.com/#feat=css-clip-path ).

The problem at hand:

  • I have to create a grid made up of 6 elements.
  • Each element consists of an image.
  • The images may vary based on user responses prior to accessing the grid page.
  • Each element/image should be clickable and upon clicking, will receive a "selected" class that overlays a div with text and background image.

image:

What is the most effective way to accomplish this task?

Answer №1

To handle the required combinations of six images, one approach is to create a single large image containing all variations. Depending on the user's input, you can then display the corresponding section of the image within a div element and place clickable areas that match the division lines.

This method may not always be practical, especially with a larger number of answers or images to manage.

Alternatively, you could utilize SVG shapes and fill them with the necessary images for a more flexible solution.

You might find Raphael.js helpful for this purpose; the documentation provides guidance on implementation.

Another option involves using HTML5 canvas:

http://jsfiddle.net/julienbidoret/GKP7X/1/

(credit goes to julienbidoret for the jsfiddle)

Javascript:

var canvas = document.getElementById('c');
var ctx = canvas.getContext('2d');
var img = document.createElement('IMG');

img.onload = function () {
    ctx.save();
    ctx.beginPath();
    ctx.moveTo(20, 0);
    ctx.lineTo(240, 0);
    ctx.lineTo(220, 240);
    ctx.lineTo(0, 240);
    ctx.closePath();
    ctx.clip();
    ctx.drawImage(img, 0, 0);
    ctx.restore();
}

img.src = "http://upload.wikimedia.org/wikipedia/commons/2/2b/Clouds.JPG";

HTML:

<canvas id="c" width="300" height="300" ></canvas>

Both SVG and canvas elements are compatible with IE9.

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

AJAX callback error: Uncaught TypeError - object is not callable

I have been working on updating a FullCalendar object by implementing a function that takes an array of events as input. $('#sh1_cal').fullCalendar({ events: function(updateEvents) { $.ajax({ type: 'GET', ...

Express Router end points facing a CORS dilemma

I am facing an issue with my React app that is communicating with an Express Node server via a REST API. The endpoints are defined in the express router and work fine when tested using Postman. However, when I try to access the endpoint from my React app ...

Error encountered with JSON.stringify in the Chrome web browser

Here is some JSON data that I am working with: var jsonData = { 'user_id' : userId, 'app_id' : '1', 'entry_channel' : 'web', ...

Is it possible to combine JavaScript objects using TypeScript?

Currently, I am dealing with two objects: First Object - A { key1 : 'key1', key2 : 'key2' } Second Object - B { key1 : 'override a' } I am looking to combine them to create the following result: The Merged Re ...

The most effective way to code overlapping html buttons

Can you help me figure out how to make clickable areas on my HTML5 web page without them overlapping? Here's what I'm trying to do: I want the red, blue, and green areas to be clickable links, but not overlap. For example, when clicking on the f ...

The parseFloat function only considers numbers before the decimal point and disregards

I need my function to properly format a number or string into a decimal number with X amount of digits after the decimal point. The issue I'm facing is that when I pass 3.0004 to my function, it returns 3. After reviewing the documentation, I realized ...

Enhancing the Speed of JQuery Mobile

Currently, my JQM application is designed to only showcase content that remains constant. To achieve this, I have created a static website with an HTML file size of 500kb or less. I have opted for the multipage architecture and have not included any custo ...

Transforming JQuery text upon selecting preloaded content with fire

When I copy the first name into the last name field, everything works fine for new names on the page. However, once a few names have been entered and the browser starts showing a history of names, the function doesn't work anymore if a pre-filled or o ...

How can indexes be updated in a nested jQuery UI sortable?

In my HTML code, there is a nested structure of divs that I want to reorder using jQuery UI sortable. <div class="sortable"> <div> <span class="sortableIndex">1</span> <div class="sortable"> &l ...

The GET API is functioning properly on Google Chrome but is experiencing issues on Internet Explorer 11

Upon launching my application, I encountered an issue with the v1/validsColumns endpoint call. It seems to be functioning properly in Chrome, but I am getting a 400 error in IE11. In IE v1/validCopyColumns?category=RFQ&columns=["ACTION_STATUS","ACTIO ...

Dealing with Three.JS, Amazon S3, and the challenges of access control origin errors in hosting JavaScript files

Overview In order to showcase models stored on Amazon S3, we rely on the use of the Three.JS Javascript library for visualization. For loading models, I exclusively utilize the JSONLoader due to its comprehensive toolchain support. Other formats such as ...

Different ways to display a PHP value that has been passed to an Ajax call within a radio button

I am facing an issue with my PHP code and Ajax script. I have a list of values being passed from the PHP code to the Ajax script, but the gender value is not being checked in the radio button. Here is an example of the passed values: {"name":"Okay","age": ...

Simple Steps for Making a Get Request using Vuex in Vue.js

I'm trying to figure out how to store products in Vuex within my index component. import Vue from 'vue' import Vuex from 'vuex' import cart from "./modules/cart"; import createPersistedState from "vuex-persistedstate ...

Why does the JSON loader in Three js work in the example but not in my own code?

Attempting to import a model with animations from Blender into Three.js is my current task. I am following the steps outlined in After downloading the code, I noticed that the author uses: var jsonLoader = new THREE.JSONLoader(); jsonLoader. ...

Having trouble using Selenium for Chrome to locate an element in an HTML file using C#?

I am currently utilizing Selenium to locate elements within an HTML document that is being displayed in the Chrome browser. Unfortunately, the HTML code is not created by me and appears to have numerous issues. I do not have the ability to modify how it is ...

Disappearing input field in DateTimePicker Bootstrap when blurred

Currently, I am utilizing the Bootstrap DateTimePicker plugin to enable users to select a specific date and time. The plugin functions well with one minor issue - whenever the user clicks outside or loses focus on the calendar box, both the box itself and ...

Utilize Node Package to Dispatch Firebase Push Notifications

I am currently experimenting with a NodeJS module for sending Push Notifications. I have been exploring the 'node-sender' module but have not been able to find an option for sending notifications to a web browser for testing purposes: https://w ...

What is the best way to incorporate caching for AJAX responses, specifically in Internet Explorer?

While most people focus on preventing AJAX caching in IE, I am interested in implementing this technique for other browsers. I have attempted to use HTTP headers without success and am now feeling confused. Any assistance would be greatly appreciated. ...

Pass the output of canvas.toDataURL function in JavaScript to the $mail->addAttachment method in PHP

Currently, I am working on a web application that allows users to customize a pool by dragging different icons onto a blueprint (such as stairs, skimmer, light...). Once the customization is complete, users can click on a button to receive the blueprint v ...

Create a container and add two div elements with absolute positioning inside

Utilizing bootstrap 3, I am looking to incorporate two shadows within a container. The first shadow will be positioned at the top of the container, followed by the second shadow at the bottom using absolute positioning. CSS: .section-st1 { padding: 0 ...