Fancybox navigation link section

I'm currently in the process of creating a photo gallery website with fancybox. As it stands, the navigation for moving to the next/previous image is tied to the position of the arrow icons. Clicking anywhere from the middle of each image to the y-axis of the arrow icon will allow you to navigate. My current setup involves adjusting the position of the arrows in the CSS file itself. However, my client has requested the ability to click on the extreme edges of the browser window to move between images, without having the arrows positioned too far away from the photos.

Is there a way to achieve this? The following snippet of code from the CSS file controls the location of the arrow images:

a.fancybox-prev {
left: 0px;
}

a.fancybox-next {
right: 0px;
}

The above code determines whether the arrows are moved closer or further away from the photos.

a.fancybox-nav span {
position: absolute;
top: 50%;
width: 46px;
height: 46px;
margin-top: -23px;
cursor: pointer;
z-index: 8040;
}

This section of the code relates to the sprite and vertical positioning of the elements.

a.fancybox-prev span {
left: 0;
background-position: 0 -50px;
}

a.fancybox-next span {
right: 0;
background-position: 0 -100px;
}

In addition, the above code also affects the appearance of the arrows, close button, and enlarge icons.

I've experimented with different combinations for hours now but haven't found a solution yet. Does anyone have any suggestions on how I can make the left half of the browser window act as the 'previous' link, and the right side function as the 'next' link?

Kirk

Answer №1

This might seem like an unusual request, but I can help with it.

First, we can disable the closing option of fancybox when clicking on the overlay outside of it. Next, we can bind a click event to the overlay of the fancybox to determine if the visitor clicked on the left or right side of the content. Depending on this, we can then call either the $.fancybox.prev() or $.fancybox.next() methods like so:

$(".fancybox").fancybox({
    margin: [20, 60, 20, 60], // Adjusting arrow positions
    helpers: {
        overlay: {
            closeClick: false // Disables closing via overlay click
        }
    },
    afterShow: function () {
        var offset = $(".fancybox-inner").offset(),
            offset_Right = offset.left + $(".fancybox-inner").width();
        $(".fancybox-overlay").css("cursor", "pointer").on("click", function (e) {
            if ( e.pageX < offset.left ) {
                $.fancybox.prev();
            } else if ( e.pageX > offset_Right ) {
                $.fancybox.next();
            }
        });
    }
});

You can further customize the arrow placements using CSS as needed.

To see a demonstration, check out this JSFIDDLE link.

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

Execute a function following the subscription's finalization

I have data stored in a Firebase Realtime Database that I want to display in my Angular application upon startup. My TripService is responsible for loading the data, and I am facing an issue with passing this data to the main AppComponent. I attempted to c ...

What is the best way to import an external file from the project's root directory using webpack?

I am currently working on a unique npm package that will allow for the integration of custom rules from the project root. This functionality is similar to how prettier searches for a .prettierrc file in the project root. For this particular package, I am ...

Tips for storing STL geometry in a cache outside of the STLLoader event listener

I am attempting to read and cache a geometry from an STL file using Three.js STLLoader. I am utilizing an event loop callback to retrieve the data (similar to the STLLoader example). My intention is to store it in an external variable called "cgeom". Howev ...

Vue composable yields a string value

I am currently using a Vue composable method that looks like this: import { ref } from 'vue'; const useCalculator = (num1: number, num2: number, operation: string) => { const result = ref(0); switch (operation) { case 'add& ...

Tips for embedding query values within a mongoose query

I have a database in MongoDB that contains an array with company names. I need to remove a specific element from the array based on its position. So, I crafted a query to achieve this. { company: [ {name: "exist"}, {name: "cool"}, {name: "h ...

URL endpoint resource containing a parameter enclosed in parentheses for a RESTful API

For a current project I am tackling, the client has provided a specific HTTP POST command that needs to be integrated into the existing webserver built on a MEAN STACK. The request is as follows: ({{Host}}/Products('{{ProductId}}')/Data.Order). I ...

Obtaining the referring URL after being redirected from one webpage to another

I have multiple pages redirecting to dev.php using a PHP header. I am curious about the source of the redirection. <?php header(Location: dev.php); ?> I attempted to use <?php print "You entered using a link on ".$_SERVER["HTTP_REFERER"]; ?> ...

"Utilizing SharePoint's JSOM to retrieve taxonomy in a recursive manner

I am facing an issue with retrieving a tree of terms recursively from a term group using JSOM / JavaScript. The challenge lies in the fact that all values are being fetched recursively, but the order is completely incorrect. function recurseTerms(curre ...

a function that repeats every single second

A challenge I am facing is creating a countdown timer with a time that refreshes every second. My current implementation uses setInterval, but it only seems to run once instead of every second. Can anyone help me identify the issue in my code? var countDo ...

The iFrame is set to a standard width of 300 pixels, with no specific styling to dictate the size

My current challenge involves utilizing the iframe-resizer package to adjust the size of an iframe dynamically based on its content. However, even before attempting any dynamic resizing, I encounter a fundamental issue with the basic iframe: it stubbornly ...

Selecting the label "for" will activate both the anchor tag and input tag simultaneously

It seems like I'm having trouble making this work, and it appears to not be possible. That's why I'm reaching out for help... Here is the CSS that is being used: label.btn { cursor:pointer; display:inline-block; } label.btn>inpu ...

Issue with md-stretch-tabs in Angular-Material causing a problem

I am in the process of developing an Angular-based application. ISSUE: I included md-stretch-tabs in my md-tabs element, but when I switch to tab#2, the tab retracts as if there is not enough space to flex. Is this problem related to dependencies or the c ...

numerous items sharing identical key values

I am dealing with an array of objects: [object, object, object, object, object] and I need to assign a unique key to each object based on its title: {test:object, tester:object, foo:object, bar:object, test:object} This way, instead of accessing the ob ...

Error message: WebTorrent encountered an issue and was unable to pipe to multiple destinations at once

Upon attempting to stream video from a provided torrent file, I encountered some unexpected issues. The example was taken from the official site, so one would naturally assume it should work seamlessly. To troubleshoot, I tried setting up a default site u ...

Locate the word or phrase without a comma

I am currently working on a code that involves finding keys with string values separated by commas. var db = { "name": "Nkosana", "middle": "Baryy", "surname": "walked", "batch_number": "test,b", "temp": ",,67,6,87,86,5,67865,876,67" ...

Display a string variable in a field using JavaScript and JQuery

I am currently coding in JavaScript using JQuery, and I am facing an issue when trying to display the content of variables in a field. Here is my code snippet: function editEvolution(pos, nature, desc, di) { $('#diE').val(di); $(&apo ...

Is it possible to exclusively target a child div using JavaScript in CSS, without affecting the parent div?

I'm in the process of developing a calendar feature where users can select a specific "day" element to access a dropdown menu for time selection. The functionality is working fine, but I've encountered an issue. When a user selects a time from th ...

Local comparison causing unit test failure

Uncertain as to why this is not working properly with Dojo doh.t(formatedValue.localeCompare("16,91 $CA") === 0, "incorrect french formatting") The value of formattedValue is definitely "16,91 $CA" so I am certain it should be a match. However, when I at ...

The link in the navbar isn't functioning properly, which indicates that it's not redirecting to the specified ID on this one-page application

<!-- NAVBAR --> <nav class="navbar navbar-expand-lg py-3 sticky-top navbar-light bg-white"> <div class="container-fluid"> <a class="navbar-brand" href="#acasa"> <img class="logo" src="./assets/img/xxxxx_psiholog_logo. ...

jquery did not load properly in the Google Chrome extension

Why am I unable to use a jQuery script inside my "myscript.js" file in the following Google Chrome extension? Is jQuery not loaded within the "myscript.js" file? What changes need to be made in the manifest file to enable the usage of jQuery inside "myscri ...