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

JQuery validation inspecting which submission button is activated

How can I implement validation and determine which button the user has clicked? I have a submit button with the following HTML: <form id="form-post"> <button type="submit" id="one"> ONE </button> <button type="submit" id="two ...

prompting users in a node.js application

I need help with querying the user multiple times in my Node.js application. Currently, all responses get printed out together and the first response is processed by both functions. I suspect this issue arises from the asynchronous nature of Node.js. Can s ...

What is the reason for the loss of jQuery $.ajax data when the URL is changed in the beforeSend function?

I am having an issue with an ajax call using jQuery, where the URL changes based on a selection from an input dropdown. Below is the code snippet causing the problem: $.ajax({ dataType: 'json', data: { ...

It appears that the anchors and fragment identifiers are not functioning as expected

On my page somepage.html, I have the following markup: <div class='someclass' id='hashtag1'> <h1>somecontent</h1> </div> <div class='someclass' id='hashtag2'> <h1>somecontent& ...

Using npm to trigger the package.json file will activate both the harp and browser-sync applications

I am looking for a way to simultaneously start a harp.js server and run a browser-sync process. This setup works perfectly on Linux with the following package.json configuration: { "scripts": { "dev": "bash ./serve.sh" } } Here is the content of ...

How to Modify the Data in a Dynamic Object within the Vuex Store in a Nuxt Application

Within my Vue/Nuxt project, I have implemented a form where users can add and update dynamic fields for calculating price offers. Upon loading the form, one field is created using the beforeMount lifecycle, with the option for users to add more fields as n ...

Styling the body element in Material UI: A guide to customizing the

I'm having trouble figuring out how to target the root elements using the ThemeProvider in Material UI. const theme = createMuiTheme({ palette: { background: { default: "#00000", backgroundColor : 'black', b ...

Revamp the Side Navigation Feature to Identify the Currently Viewed Section of the Page

My website currently features a side navigation bar that dynamically updates based on the user's scroll position. When the user reaches a specific height, a class is added to a div in the sidebar, turning it orange and indicating which part of the pag ...

SapUI5: Implementing a toggle functionality to display/hide one list item based on another list item's action

UI5 is a versatile framework with numerous possibilities, but sometimes I find myself struggling to implement ideas that would be easier in traditional HTML. Here's the scenario: I want to create a List with ListItems that display cities like Berlin, ...

Can a layer be sliced to create a text-shaped cutout?

I want to achieve a cool text effect where the background is visible through the letters. I have explored options with background images and colors, but I haven't found any examples where the underlying layer is revealed. Is this even possible? Imag ...

Calculating the duration of time using JQuery with provided start and end times

I am currently utilizing a jQuery time picker to gather start and end times in a 12hr format. My goal is to calculate the time duration between the start and end times in HH:MM:SS format. The code snippet I have below is providing me with a duration like ...

What are the ways to personalize the material UI select component?

I am looking to customize a MUI select component that I have rendered on a dark background. My goal is to make the outline and all its contents light colors, specifically grey and white. So far, I have successfully changed the outline and text contents to ...

What are the steps to generate a multiline chart using d3.js with json data specifically formatted for nvd3?

I attempted to create a multi-line chart using nvd3, but encountered roadblocks when trying to make significant modifications. I am considering building my own chart using d3js directly, but I'm finding it challenging to grasp the concept of 'thi ...

"The Vue component's data is successfully updating within a method using setInterval(), however, the changes are not reflected in the DOM

I have a function in my methods that gets triggered with a @click in the view. The function starts a timer, and although it seems to work fine in the DevTools, the timer only updates in the DevTools when I refresh the page. Moreover, in the view, the time ...

Playing embedded YouTube videos automatically in Safari 11 without user interaction

I’m encountering an issue with a simple modal dialog: When a user clicks on a button, the modal overlay appears. An embedded YouTube <iframe> is then added. Everything works smoothly in most browsers, except for Safari 11.1. Safari’s new auto ...

Creating a reusable anonymous self-invoking function

Here is a function that I am working with: (function(e, t) { var n = function() { //code, code, code }; //code, code, code e.fn.unslider = function(t) { //code, code, code }; })(jQuery, false) To execute this function, I have impleme ...

Using a combination of functions to ensure synchronicity in JavaScript operations

Here is the function I have created: $scope.saveManualResendDraft = function(todo) { if ($scope.editMode) { updateStartJobManual(); byeSendManualInputDirectly(); } else { console.log('bye'); } }; I have defin ...

Extracting specific data from a JSON subnode within an HTML document

I have been attempting to retrieve product data (name, price, url), along with information on available sizes and colors, from a website that is formatted in JSON (https://www.bergzeit.de/marken/salewa/). However, I am struggling to locate the 'elemen ...

In the event of any unexpected errors while utilizing an API, a ticket will be automatically generated on Jira through the use of Vue.js

After successfully hitting the API through Postman and creating a ticket on Jira, I encountered a CORS error when attempting to do the same using an index.js file in VueJS. The flow is unclear to me as generating a demo error results in nothing being sho ...

"Error encountered: Array is undefined when using the map and subscribe functions in Ionic

I have developed a service that is supposed to retrieve data from a JSON file and assign it to an array called 'countries', which will be used throughout the application on multiple pages. However, when I call the method getCountries, the countri ...