Conceal social media icons when hovering over specific images similar to the feature on the website medium

I am facing an issue with fading out social links that appear over medium and large images on a webpage. I want the social links to fade out when they are over the images and fade back in once they move off the images. The number of medium and large images may vary on each page. To see an example, you can visit a post on Medium.com.

The code provided below currently only works for large images. When attempting to include medium images as well, it does not function properly. My social links are fixed at about 600px from the top of the page. Any help would be appreciated!

var large_images = $('img[src*="#large"]'),
        medium_images = $('img[src*="#medium"]'),
        social = $('.social-share'),
        $window = $(window),
        showSocial = function() {
            if (isHidden) {
                isHidden = false;
                social.fadeIn(200);
            }
        },
        hideSocial = function() {
            if (!isHidden) {
                isHidden = true;
                social.fadeOut(200);
            }
        },
        isHidden = true,
        scrollTop;

    if (large_images.length) {
        $window.on('scroll', function() {
            var flag = false;

            scrollTop = $window.scrollTop() + 400;
            $.each(large_images, function(i, large_image) {
                var $large_image = $(large_image),
                    offset = $large_image.offset().top;

                if (offset < scrollTop && offset + $large_image.height() > scrollTop) {
                    flag = true;
                    return false;
                }
            });

            if (flag) {
                hideSocial();
            } else {
                showSocial();
            }
        });
    }

Answer №1

If you're currently only cycling through images tagged with "large", consider expanding your loop to also include those labeled "medium". Your current approach for "large" images should work seamlessly with "medium" images, as long as the main distinction is their size.

An easy solution would be to update your variables from `large_images, medium_images` to `all_images = $('img[src*="#large"],img[src*="#medium"]')`, and then adjust the remaining instances of `large_images` in your jQuery code to `all_images`.

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

The left-floated image extends beyond the boundaries of the div

I have a situation where text and an image are combined but the cat image goes outside of the parent div. Is there a solution to this issue? View the code here <div style="border:1px solid #CCCCCC"> <img style="float: left;" src="http://plac ...

Tips for ensuring all images are the same size within a div element

https://i.stack.imgur.com/EkmWq.jpg Is there a way to make sure all the images fit perfectly inside their respective border boxes without appearing stretched? I've tried setting fixed height and width within a div, but they always end up looking off. ...

What sets the target property of the mousewheel event apart from other events like click, mousedown, and touchstart?

The mousewheel event's target property reveals the DOM element currently being hovered over when using the mousewheel or gesture-capable touchpad. In my experience (specifically in Safari 6, I will verify this in other browsers later), the target ret ...

When utilizing express-formidable to retrieve multipart data, it causes basic post requests with request body to hang indefinitely

app.js const express = require('express') const app = express() const appInstance = express() const PORT = process.env.SERVER_PORT || 8080 app.use(express.json()) app.use(express.urlencoded({ extended : true })) app.use(formidableMiddleware ...

Struggling to get this bootstrap carousel up and running

I can't seem to get this bootstrap carousel to switch slides, whether I use the indicators or arrows. My other carousel works perfectly fine and I've added all necessary Bootstrap and JavaScript CDNs. I'm puzzled as to why it's not func ...

Utilizing Express and ejs to display a JSON using the "<%" tag

I am facing an issue with the code in my index.ejs file. The current code snippet is as follows: var current_user = <%= user %> In my node.js file, I have the following code: app.get("/", function(req, res){ res.locals.user = req.user res. ...

Is it possible to vertically displace an element within a CSS Grid cell?

Here is the code snippet: .grid-container { display: grid; grid-template-columns: auto auto auto; background-color: #2196F3; padding: 10px; } .grid-item { background-color: rgba(255, 255, 255, 0.8); border: 1px solid rgba(0, 0, 0, 0.8); ...

Limiting Node.js entry with Express

I have a node.js script running on a server. I want to prevent it from being accessed directly from a browser and restrict access to only certain domains/IP addresses. Is this achievable? ...

Utilizing AWS SDK (S3.putObject) to transfer a Readable stream to Amazon S3 using node.js

I am aiming to successfully send a Readable stream to S3. However, I have encountered an issue where the AWS api only seems to accept a ReadStream as a stream argument. When using a ReadStream, everything works as expected, as shown in the following code ...

An error is being thrown by SetState when included within componentDidmount

I am currently learning React JS and have started working on a small application using it. I'm encountering an issue with the SetState method inside the componentDidMount lifecycle method. The scenario is that I have a parent/home component, which ca ...

What steps should I take to develop an Outlook add-in that displays read receipts for action items in sent emails?

Currently, I am in the process of developing an add-in that will enable me to track email activity using a tool called lead-boxer (). With this add-in, I am able to retrieve detailed information about users who have opened my emails by sending them with an ...

Clicking a link will trigger a page refresh and the loading of a new div

<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script> $(window).load(function () { var divs = $( #add_new, #details"); $("li a").click(function () { ...

Establishing communication from a node.js application to an Apache server with version 2.2

Each time I call the function dorequest during a request to my node server, I encounter an issue with requests to a webpage hosted on apache2.2.21. While most of the requests are successful, I am getting an error ECONNRESET on a few of them, and I am uns ...

Hapi/Node.js Reference Error for Request: Troubleshooting the Issue

I am facing an issue with my two API handlers: module.exports.loginWeb = function (request, reply, next) { if (request.auth.isAuthenticated) { return reply.redirect('/'); } if(request.method === 'get'){ rep ...

By default, the select option in AngularJS will have a value of either an object or null

This block of code is located in the js file: $scope.ListOption = []; $scope.ListOption.push({ Value: "0", Name: Car }); $scope.ListOption.push({ Value: "1", Name: House }); Below is the corresponding HTML code: <select class="form-control" id="Categ ...

Extract information from various webpages with identical URLs

I am struggling to extract data from a specific webpage (). Even though I can successfully gather information from the initial page, whenever I attempt to navigate to subsequent pages, it continues to display the same dataset. It seems to retrieve the iden ...

The changes made to jqGrid select editOptions may not reflect immediately

I am facing an issue with dynamically loading values into a select in a jqGrid. The challenge I am encountering is that the returned values from the server are not displayed until the user changes the row. Even though I can see the correct values being s ...

Retrieve targeted information array using jquery

Having an issue with JQuery, my PHP code looks like this: if($record2==0) { if($tmp_curr==$curr) { $reqvendor->inserttmp($json); $json[] = array('stat' => true, 'msg' => ''); //$app['data'] = true; //var_du ...

Tips for updating and inserting dynamically generated form textbox values into a MySQL database

In my PHP project, I have a MySQL DB with a bunch of features table. I retrieve the data using PHP and create a table with textboxes named after column names and record IDs in the photos table using the following code: functions.php Code: function m_html ...

What is causing the dropdown menu to change colors to blue when hovering over the dropdown items?

I've noticed that my Bootstrap is causing the dropdown color to turn blue when I hover over a dropdown item. Despite trying different solutions, all my attempts have been unsuccessful. I suspect that it is due to bootstrap but I can't seem to fin ...