Endless rotation with stunning magnification feature

My goal is to create a responsive carousel with auto-play infinite loop functionality, where the center item always occupies 70% of the viewport width.

Currently, I have achieved a similar result using the Slick library:

https://codepen.io/anon/pen/pBvQBM

$('.slick')
  .on('init', () => {
    $('.slick-slide[data-slick-index="-2"]').addClass('lt2');
    $('.slick-slide[data-slick-index="-1"]').addClass('lt1');
    $('.slick-slide[data-slick-index="1"]').addClass('gt1');
    $('.slick-slide[data-slick-index="2"]').addClass('gt2');
})
  .slick({
  centerMode: true,
  centerPadding: 0,
  slidesToShow: 3,
  autoplay: true,
  autoplaySpeed: 500,
}).on('beforeChange', (event, slick, current, next) => {
  // Logic for adding classes based on current and next slide index
});
// CSS styling for the carousel elements
...
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.9.0/slick.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.9.0/slick.js"></script>
<div class="slick">
  <div><span>1</span></div>
  <div><span>2</span></div>
  <div><span>3</span></div>
  <div><span>4</span></div>
</div>

Although the current setup is close, I aim to have the center item occupy 70% width instead of equal widths. A visual representation can be seen in this image: https://i.stack.imgur.com/xHsIn.png

I welcome suggestions on how I can achieve this layout, whether through modifications to the Slick library or exploring alternative options such as pure CSS or JQuery.

Answer №1

Your approach is almost there, but a bit inconsistent in applying styles. I made adjustments by removing some styles from the spans and adding new styles to the slide divs:

Check out the updated CSS code here: https://codepen.io/anon/pen/PgwXbV

You may need to fine-tune some details, but this CSS should bring you closer to the desired effect:


*, *::before, *::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 20vh 0;
}

.slick span {
  display: block;
  background: #3498db;
  color: #fff;
  font-size: 36px;
  height: 100px;
  line-height: 100px;
  position: relative;
  text-align: center;
  opacity: .5; /* make non-centered slides transparent */
}

.slick-slide {
  border: solid 1px #2dc37f;
  transform: scale(.5); /* make non-centered slides smaller */
  transition: transform .4s ease;
}

.slick-slide.slick-center {
  transform: scale(1); /* make center slide full size */
}

.slick-slide.slick-center span {
  z-index: 1;
  transform: scale(1);
  opacity: 1; /* make centered slides solid */
  color: #e67e22;
}

.slick-prev,
.slick-next{
  position: absolute;
  top: 50%;
  appearance: none;
  margin-top: -10px;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  color: transparent;
  outline: none;
  z-index: 100;
}

.slick-prev {
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 15px 15px 15px 0;
  border-color: transparent #007bff transparent transparent;
  left: 0;
}

.slick-next {
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 15px 0 15px 15px;
  border-color: transparent transparent transparent #007bff;
  right: 0;
}

The additional styling for specific slides seemed unnecessary with the changes made:


.slick-slide.lt2 span {
  transform: translate(10%, 0) scale(.6);
}

.slick-slide.lt1 span {
  opacity: .7;
  transform: translate(5%, 0) scale(.8);
}

.slick-slide.gt1 span {
  opacity: .7;
  transform: translate(-5%, 0) scale(.8);
}

.slick-slide.gt2 span {
  transform: translate(-10%, 0) scale(.6);
}

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

Is there a way to prevent the "undefined" message from displaying in the console when this code is run?

Help needed! Can someone assist me in resolving the issue where the word 'undefined' is being displayed in the console? I'm a beginner in programming and struggling with this. Here's what I'm currently seeing: You are not getti ...

How to enable the Copy to Clipboard feature for multiple buttons and transition from using an ID to a class identifier

Can someone please assist me? I have a copy to clipboard function that works well for IDs and a single button on my website. However, I need to modify it to work for multiple buttons and values with a class identifier. Unfortunately, I am unsure how to mak ...

JavaScript: Increasing the date by a certain number of days

I've been researching various topics and so far, I haven't come across one that addresses my specific issue. Here's the task at hand: 1) Extract a bill date in the mm/dd/yy format, which is often not today's date. 2) Add a dynamic ...

Trouble with Angular 7: Form field not displaying touched status

I am encountering an issue while trying to input data into a form, as it is not registering the touched status. Consequently, an error always occurs when attempting to send a message back to the user. In my TypeScript file, I am utilizing FormBuilder to c ...

The final position of the Angular increment animation does not hold

Is there a way to trigger an animation when the value of countAllOrders changes? Specifically, I am attempting to adjust the margin of a list using keyframes in an Angular animation. Here is my HTML code: <ul class="digits" [@ordersValue]=&q ...

What is the best way to create a circular to square gradient and save it within a two-dimensional array?

Can anyone guide me on creating a circle/square gradient and storing the data in a 2D array? I want to incorporate this gradient with simplex-noise to develop a procedural island by subtracting the gradient from the generated noise. Here are some visual re ...

How to vertically center a div within a parent div with a fixed position?

I am facing an issue where I have a div positioned on top of another fixed position div, and I am looking for a way to vertically align the first div. Below is the code snippet that I am currently working with: <div class="overlay"> <div id=" ...

The selection elements fail to reset correctly

I'm currently working on an Angular 4 application where I have a form that includes a select element inside a box. <div class="form-group"> <label for="designation">Designation</label> <select [class.red-borde ...

Using jQuery and $.ajax to update <td> contents

I need assistance with updating the content of a table using jQuery. Here is an example of my table structure: <table id="table-name"> <tr><td id="td-name">something</td></tr> <tr><td id="td-name">somethin ...

Selecting the initial item of every nested tag repeatedly for a total of n times

Is there a way to stop coloring elements after 'tue 7-1-1' using CSS? I am only allowed to manipulate the first child of every element up until a certain point through CSS, without modifying the existing code. Note: Span elements are nested wit ...

What is the best way to manage zoom settings following a completed search query?

Whenever I try to search for an address using this map, it zooms in way too much making the map unusable. Despite my efforts to adjust the map bounds, I have not been successful. It seems like I am on the right track but for some reason, it just isn't ...

unable to make a request to the express server with axios

I am in the process of developing a chat application similar to whatsapp. One of the key features I'm working on is that when a user clicks on another person's name, their chats will be displayed. However, currently, I'm facing an issue wher ...

Images refusing to display within the div

I am attempting to insert an image onto my website, however, I am encountering issues with the code I have written: div#planet { z-index: -10; width: 450px; height: 549px; position: absolute; background: url("https://example.com/im ...

Is there a way to stop these symbols (♈♉♊♋♌♍♎♏♐♑♒♓) from being substituted with emojis?

I am currently working on a project involving the simulation of the Prague Astronomical Clock (). My goal is to display the glyphs representing signs of the zodiac, which are in the Unicode range U+263C-2653 along with other astronomical symbols. My prefe ...

How do I switch back and forth between displaying content as 'none' and 'block' using JQUERY?

Take a look at this code snippet. <div class="sweet-overlay" tabindex="-1" style="opacity: 1;display: none;"></div> Is there a way to switch the style attribute value from none to block and back? ...

Animating a dotted border path in SVG for a progress bar effect

I am attempting to create an animation for a dotted SVG circle that resembles a progress bar, where it fills itself over a duration of 3 seconds. However, I am facing difficulties in achieving this effect with the dotted border. The current code I have doe ...

JavaScript code for computing the error function of Gauss

Are there any freely available implementations of the Gauss error function in JavaScript under a BSD or MIT license? ...

Sorting through a list of strings by checking for a specific character within each string

After spending years dabbling in VBA, I am now delving into Typescript. I currently have an array of binary strings Each string represents a binary number My goal is to filter the array and extract all strings that contain '1' at position X I ...

Clicking anywhere outside a popup menu in JavaScript will deactivate a toggle and hide it

I have three different menu options: home,Clinic, and About. When I click on the Clinic option, a Megamenu appears, and if I click on it again, the Megamenu is hidden. I want the Megamenu to hide when clicking anywhere on the webpage. The issue is that cu ...

Struggling to create a basic website design using Flex within Bootstrap 5

As a newcomer to Bootstrap and web development, I am eager to create a simple welcome-page with a specific design in mind. The layout should resemble the image found https://i.sstatic.net/AAEQ4.png. The colors in the image indicate where flex rows could b ...