Interactive Image Hover - CSS and JQuery

After finding a tutorial on creating an image-hover plugin using jQuery and CSS (), I successfully implemented it on my website.

However, I encountered an issue with responsiveness as I would like the images to scale according to my 960gs grid system.

You can view the progress I've made so far in this fiddle: http://jsfiddle.net/Ak94R/6/

.viewport {
    float: left;
    height: 360px;
    margin: 0 9px 9px 0;
    overflow: hidden;
    position: relative;
    width: 360px;

}

My goal is to adjust the image scaling from 200% to 100%, rather than going from 730px to 360px. Additionally, I need the main clipping div (.viewport) to be sized at 100%. Any suggestions or assistance on how to achieve this would be greatly appreciated!

Answer №1

After investing some time, I managed to come up with a CSS-only solution that achieves the desired outcome without the need for JavaScript. This solution is fully responsive as it utilizes percentages for sizing. Here is what the HTML looks like:

<div class="viewport_css">
    // To ensure square dimensions, a dummy image is used 
    <img class="dummy" src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" />
    <a class="imgwrapper" href="#">
        <img src="http://www.lorempixel.com/730/730/" alt="More Info" />
    </a>
</div>

Below is the CSS code:

.viewport_css {
    position: relative;
    max-width: 360px;
    height: auto;
    overflow: hidden;
}

// Ensuring the viewport_css remains square-shaped
.viewport_css .dummy {
    width: 100%;
    height: auto;
    display: block;
}

.viewport_css a,
.viewport_css a:hover:before,
.viewport_css a:hover:after {
    position: absolute;
    left: 0;
    right: 0;
}
.viewport_css a,
.viewport_css a:hover:after {
    top: 0;
    bottom: 0;
}

.viewport_css a:hover:after {
    content: '';
    display: block;
    z-index: 100;
    background-color: rgba(255, 0, 0, .5);    
}

.viewport_css a:hover:before {
    content: 'View';
    color: #fff;
    top: 50%;
    text-align: center;
    z-index: 200;
    margin-top: -0.5em;
}

.viewport_css .imgwrapper {
    width: 200%;
    height: 200%;
    margin-left: -50%;
    margin-top: -50%;
    transition: all 1s ease-in;  
}

.viewport_css .imgwrapper img {
    width: 100%;
    height: auto;
    display: block;
}

.viewport_css .imgwrapper:hover {
    width: 100%;
    height: 100%;
    margin-left: 0;
    margin-top: 0;
}

Answer №2

By adjusting the background-size: 70px 80px; through media queries at different breakpoints, I was able to successfully address the problem.

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

Using regular expressions, is there a way to determine if my variable only contains the specific assigned string?

There is an object value that can be one of three strings: a) Unassigned b) ( Unassigned ) c) (unassigned). My query is how do I identify if my variable contains any one of these strings exclusively without any additional text? I attempted the following a ...

Modifying the CSS color value does not result in a change to the background color

Currently implementing this Jekyll theme, and I am interested in adjusting the vibrant yellow hue to a different color option (such as gray). Despite altering the CSS color value, it seems that the background color persists unchanged. https://github.com/ ...

Unable to pinch-zoom UIScrollView in iOS 6

Here is an example of my code in .m format. #import "ScrollZoomViewController.h" @interface ScrollZoomViewController () <UIScrollViewDelegate> @property (weak, nonatomic) IBOutlet UIImageView *imageView; @property (weak, nonatomic) IBOutlet UIScrol ...

Using Datatables with Jquery and Bootstrap 5 to generate a dynamic dropdown menu within a row and send the selected data to

Utilizing Datatables has been a great experience for me as I attempt to retrieve user details from the database using Php/Sql and generate a bootstrap 5 dropdown to display the employees as options. Fortunately, the dropdown is successfully showcasing the ...

Using the ng-repeat directive in AngularJS, Bootstrap collapse can target only a single <li> element at a time

Could it be that ng-repeat is causing the elements to be displayed after the DOM has loaded? It seems like only the first element is displayed if collapse is not expanded on load, and if it's expanded on load, only the first element collapses. Is the ...

Cover the entire page with a solid background color

Is there a way to extend the green color from top to bottom on the page? Also, how can I move the CRUD section to the left? https://i.sstatic.net/pXxhl.png I'm having trouble filling the entire page with the content. Below is my code written in Vue ...

Creating nested tabs with Bootstrap: A step-by-step guide on adding tabs within tabs

I am encountering a challenge with nested tabs. I am utilizing Bootstrap and not using custom CSS. Any assistance would be greatly appreciated. <div class="container-fluid"> <!-- Tabs --> <ul class="nav nav-t ...

In Vue.js, how can we divide data into separate groups and display the top 3 rows of each group followed by the remaining

Is there a way to use Vue.js to slice data into groups and display the top 3 rows from each group first before showing the rest? I have around 10 thousand data entries that I need to display. I would like to group them by date and show the top 3 rows of ...

Updating a dataview inside a Panel in extjs 3.4

I am facing an issue with my extjs Panel component that includes a dataview item. Initially, it works perfectly fine in displaying images from a store. However, upon reloading the imgStore with new image URLs (triggered by a user search for a different cit ...

What is the mechanism behind the functionality of the code when the action attribute is missing?

In my file named service.php, I have a code that functions as follows: if ((!empty($_POST)) && ($_POST['action'] == 'addRunner')) { // Code to add entry into database } function fail($message) { die(json_encode(array( ...

"Experiencing technical difficulties: Website not functioning properly on

I recently created this website. While it functions perfectly on desktop computers, I am encountering issues when trying to access it on mobile or tablet devices. My instinct tells me that the problem may be related to a large css animation on the homepa ...

How to prevent Bootstrap panel collapse from creating gaps

I am currently working on a layout with 2 columns, each containing 2 panels. Both of these columns are set to be 50% wide (col-md-6) with collapsible panels inside. The collapsing functionality works just fine, but the issue arises when I expand a panel. W ...

Refresh a chart in vue using the chart.js library

Within my Vue application, I have a function that generates a chart. This function looks like this: startChart: function (canvas, type) { // initialize chart.js var ctx = document.getElementById("myChart"); var myDoughnut = new Chart(ctx, { ...

A comprehensive guide on integrating jQuery with jsdom using TypeScript

I am struggling to use jQuery with jsdom in typescript. This is the snippet of code I currently have: import { JSDOM } from 'jsdom'; import jQueryFactory from 'jquery'; const jsdom = new JSDOM(html); const { window } = jsdom ...

Move the divs within the overflow container by sliding them, then take out the initial element and append it to the end

Currently, when I utilize .appendTo(".wrapper") as shown in the code below, it eliminates the animation effect. My goal is to have the div on the far left slide out of view, triggering an overflow hidden effect, and then be placed at the end of the slide c ...

Utilizing npm's package.json file to fetch the most recent version and ensuring the correct naming of the plugin

As a newcomer to NPM, I have a simple question for beginners. While reading an article, I stumbled upon the author's suggestion: Instead of running these commands: $ cd /path/to/the/project $ npm install mongoose $ npm install express $ npm install ...

Utilize jQuery ajax to target a particular recurring input

I am using HTML code along with another jQuery loop. Within this loop, there is an input element that is also being looped. I am trying to manipulate it using jQuery Ajax... but I am facing an issue where only the first input element works properly. The re ...

Interactive side menu with vertical scrolling functionality

Struggling with CSS code here. I want my website to be full screen and responsive, without any scrolling up and down. Tried different height settings like height:100vh, height: 100%, and height:1920px, but still facing the issue. Searched everywhere for a ...

What steps can be taken to resolve an issue with the background color?

Despite my hesitation, I have a question that may seem silly, but is actually quite significant to me. I am trying to create an effect on the background-image by using a gradient overlay with a fixed position underneath it. body{ background-image:url( ...

Adjust the transparency of an image within an overlay when clicked on the overlay

Having an overlay on a Google map with two images contained within it, I am looking to adjust the opacity of the images when a user clicks on the overlay or on top of an image within the overlay. I attempted to utilize domlistener, but it did not yield the ...