Attempting to simulate a camera shutter effect using div elements

I've been attempting to create a circular camera shutter, but I'm facing difficulties in making it look accurate.

This is the desired outcome:

https://i.sstatic.net/oS7gT.jpg

The first 'petal' should be positioned lower than the last one and higher than the next. How can I achieve this effect?

Here's what I have experimented with so far:

let partAmount = 10;
let cont = document.getElementById('cont');
let parts = [];
for(let i = 1; i <= partAmount; i++){
  let partCont = createElement('div','partCont');
  let part = createElement('div','part');
  parts.push(part);
  partCont.appendChild(part);
  cont.appendChild(partCont);
  partCont.style.transform = 'rotate('+ 360 / partAmount * i+'deg) translatey(-250px)';
}
function createElement(tag,className){
  let elem = document.createElement(tag);
  elem.classList.add(className);
  return elem;
}
#cont{
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%,-50%);
  
  border-radius: 50%;
}
.dia{
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%,-50%);
  width: 300px;
  height: 300px;
  border-radius: 50%;
  overflow: hidden;
}
.partCont{
  position: absolute;
  transform-origin: left top;
}
.part{
  width: 500px;
  height: 100px;
  background-color: lightgray;
  border-bottom: 3px solid gray;
  box-sizing: border-box;
  transform-origin: left bottom;
  transform: rotate(60deg);
  transition-duration: 1s;
}
<div class="dia">
  <div id="cont">
  </div>
</div>

Answer №1

section, a clever technique is presented that revolves around the concept of symmetry in shapes. By utilizing two distinct elements and applying similar transformations to both while rotating one, the impression of a single shape can be created. A previous query on this same topic was explored in detail in a separate question found at this link. The strategy involved leveraging multiple background elements as well as incorporating linear gradients to achieve the desired effect. To better understand the intricate calculations necessary for precise results, it becomes essential to recognize that the internal design actually forms an Octagon shape. By determining the appropriate rotation angles, such as starting at 45deg/2 for the initial rotation, subsequent adjustments can be made by increments of 45deg for other sections. The evolving code then takes shape accordingly, adapting to different scenarios like transitioning to a Decagon form through strategic layering and degree calculations. Furthermore, with the inclusion of animations, a dynamic shutter-like movement can be introduced for added visual appeal. Alternatively, an innovative approach combines the principles discussed above with a symmetrical pattern implementation. This creative fusion produces a visually engaging outcome that showcases the versatility of combining shapes and geometric manipulations effectively. Overall, these techniques highlight the power of employing thoughtful design strategies and mathematical precision to craft stunning visual effects with CSS.

Answer №2

using SVG makes the implementation process much easier

let r = 80, 
    arc = (x,y,s) => `A${r},${r},0,0,${s},${x},${y}`,
    path = (i,d) => `<path transform='rotate(${i/+count.value*360})' ${d}></path>`;

function updateVal (val) {
    
    let step = Math.PI*(0.5 + 2/+count.value);
    let p1x = Math.cos(step)*r; 
    let p1y = Math.sin(step)*r;
    let cos = Math.cos(-val);
    let sin = Math.sin(-val);
    let c1x = p1x - cos * p1x - sin * p1y;
    let c1y = p1y - cos * p1y + sin * p1x;
    let dx = - sin * r - c1x;
    let dy = r - cos * r - c1y;
    let dc = Math.sqrt(dx*dx + dy*dy);
    let a = Math.atan2(dy, dx) - Math.acos(dc/2/r);
    let x = c1x + Math.cos(a)*r;
    let y = c1y + Math.sin(a)*r;
    
    let edge = `M${p1x},${p1y}${arc(0,r,0)}${arc(x,y,1)}`;
    edges.innerHTML = bodies.innerHTML = '';
    for (let i = 0; i < +count.value; i++) {
        edges.innerHTML += path(i, `fill=none stroke=black d='${edge}'`);
        bodies.innerHTML += path(i, `fill=lightgray d='${edge}${arc(p1x,p1y,0)}'`); 
    }
};

updateVal(0.5);

addEventListener('mousemove', e => updateVal(e.y/innerHeight*1.04));
<svg viewbox=-100,-100,200,200 style="height:90vh" id=svg>
    <g id=bodies></g><g id=edges></g>
</svg><br>
<input id=count type=range min=2 max=13 value=5 style="position:absolute;top:2px">

Answer №3

One creative approach involves incorporating a basic image (or svg for sharpness) and utilizing straightforward css animations. To achieve this effect, you can design an overlay image like the following:

https://i.sstatic.net/0vi4A.png

Enclose this within a circle and apply a simple zoom in and out animation to the overlay using css:

div {
width:150px;
height:150px;
background:#dbdbdb;
border-radius:50%;
overflow:hidden;
position:relative;
transform: translateZ(0);
}

div::after {
position:absolute;
left:0;
top:0;
right:0;
bottom:0;
content:'';
background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='36' height='38' fill='%2354595f' fill-rule='evenodd'%3E%3Cpath d='M21.5 12.938L25 19l-3.5 6.062h-7L11 19l3.5-6.062z'/%3E%3Cpath d='M18 24h18v1H18zM0 13h18v1H0zm13.67 8.5l9 15.588-.866.5-9-15.588zM14.196.412l9 15.588-.866.5-9-15.588zM13.67 16.5l-9 15.588-.866-.5 9-15.588zM32.196 6.412l-9 15.588-.866-.5 9-15.588z'/%3E%3C/svg%3E") no-repeat center;
background-size:cover;
transition:transform ease 0.3s;
border-radius:50%;
overflow:hidden;
transform:scale(1.5);
}

div:hover::after {
transform:scale(1);
}
<div></div>

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

What is the best way to incorporate component-specific CSS styles in React?

This is the layout that I am attempting to replicate (originally from react-boilerplate): component |Footer |style.css |Footer.js In Footer.js, the styles are imported in a very elegant manner like this: import React from 'react'; im ...

The anchor for the circular image is oversized

Currently, I have a PHP code that displays a user's profile picture, and when clicked, it takes them to their own profile. The image is displayed correctly, and the link works fine. However, there seems to be an issue with the area covered by the anch ...

Comparison of Chrome's compatibility with Bootstrap and Edge

Firefox Safari I am facing an issue that seems obvious, but I am unable to pinpoint the exact cause. It just doesn't seem right for no apparent reason. is the website in question. I have tried various troubleshooting methods such as inspecting th ...

Issue with custom page not displaying summary image in Moodle

Whenever I try to fetch a summary image on my customized page, it does not show the image's name and instead displays a small icon image. echo format_text($course->summary); Click here for an example image ...

The Safari 7.1+ browser seems to be having trouble with the spotlight effect

Why is the CodePen not functioning properly in Safari? Despite working well in Chrome and Firefox, it completely fails to work in Safari 7.1+. Can anyone provide some insights? http://codepen.io/cchambers/pen/Dyldj $(document).on("mousemove", function( ...

MUI useStyles/createStyles hook dilemma: Inconsistent styling across components, with styles failing to apply to some elements

I have been trying to style my MUI5 react app using the makeStyles and createStyles hooks. The root className is being styled perfectly, but I am facing an issue with styling the logoIcon. Despite multiple attempts to debug the problem, I have not been suc ...

Creating a dynamic sidebar menu with clickable submenus through jQuery and CSS for a user-friendly experience

<div id="sidebar" class="sidebar"> <div class="slimScrollDiv" style="position: relative; overflow: hidden; width: auto; height: 100%;"> <div data-scrollbar="true" data-height="100%" data-init="true" style="overflow: hidden; width: a ...

Embed schema information into HTML tags using JavaScript

Is there a way to insert text, specifically schema data, into an HTML div tag using JavaScript? While I know how to modify existing values within a tag like class, href, and title, I am struggling to find a method to add something entirely new. Essentiall ...

Understanding the flow of block-level elements in documents when utilizing CSS :after pseudo selectors

What is the reason behind the block level element box appearing after the blue container's content instead of directly after the content box itself? Is it possible to achieve this using the CSS :after selector? TEST AREA CSS div{ background:#59 ...

Experiencing problems with web page layout when using bootstrap on IE8?

Here is a code snippet that functions correctly in IE9 and later versions, but encounters issues in IE8: <div class="col-lg-5 col-md-5 col-sm-6 col-xs-6" id="div1"> <div class="panel panel-default" style="" id="panel1"> ...

Guide on utilizing the list of names in a POST request

<td class="widht200"> <input type="text" name="agg" size="2" disabled="disabled"/> </td><td class="widht200"> <input type="text" name="agg" size="2" disabled="disabled"/></td><td class="widht200"> <input type=" ...

margin around the masterpage

Currently, I am utilizing a master page in ASP.NET (using Visual Studio Express 2015) and overall everything is functioning properly. However, there seems to be an unsightly space around the edges when viewing it in a browser. While not a critical issue, ...

Change the font style of individual characters within a string using CSS or JavaScript, instead of applying it to the entire

Is it feasible to assign a specific font to a particular character? I would like: #test_id{ font-family: "digitalfont"; font-family-of-, : "HelveticaNeue-Light"; } In order to set a font for a comma and a separate font for the rest, do I need to ...

What is the best approach to reverse the selection of <li> elements by utilizing :not() and :contains

I am looking to implement a live search feature using jQuery. Below is the code snippet I have written: $("#searchInput").on("keyup", function () { var searchTerm = $("#searchInput").val(); $('li:contains("' + searchTerm + ' ...

Incorporating Bootstrap into a fresh project

I'm completely new to the world of development, so I'll do my best to phrase this question correctly! Last month, I successfully created my first web application using RoR and Bootstrap for some visual enhancements. Currently, I am working on a ...

Loading dynamic CSS on WordPress frontend only

I am facing an issue with the dynamic css file in my WordPress theme that is loaded using Ajax. The problem is that it also loads this dynamic css file for the backend. Can someone help me modify my code so that it only loads the dynamic css file for the f ...

Issues with implementing Dark mode in TailwindCSS with Nuxt.js

After spending a couple of days on this, I'm still struggling to get the dark mode working with Tailwind CSS in Nuxt.js. It seems like there might be an issue with the CSS setup rather than the TypeScript side, especially since I have a toggle that sw ...

Ensure that buttons appear neat and organized when viewed on mobile devices

As a CSS beginner utilizing the Bootstrap framework, I have encountered an issue with my button layout on mobile devices. I have successfully created a set of buttons that display correctly on both desktop and mobile views. In the desktop view, you can se ...

The PHP script is exhausting memory resources and triggering a fatal error

I encountered the following error message: Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 528384 bytes) in /home/u234536193/domains/monetizingonline.com/public_html/wp-includes/wp-db.php on line 2024 The problematic cod ...

Is there a way to retrieve the disabled drop-down field value after submitting the form?

I'm struggling with a dropdown field that becomes disabled once an item is selected. After submitting the form, the dropdown field loses its value and I'm left with an empty field. Any suggestions on how to keep a value in the dropdown after subm ...