Framer Motion whileHover animation resets on click

I am animating two elements, which are visually on top of each other.

  • a text div, that onClick toggles to display a paragraph

  • a “book cover” div, that covers the text div until you hover above it and then rotates to the side

the book cover I was able to animate, by giving it a parent-div as well, to expand the “hover area” a bit more

but because the parent div now covers up the text div partially it required me to add the onClick-function, which opens the text div; as there were layout shifts when I tried to include the text div inside the parent.

when I click on the book cover div or the parent element now, the text div expands as expected, but the book cover rotation animation appears to reset, which I am trying to prevent.

How can I stop the book cover hover animation from resetting?

'use Client'
import {motion} from 'framer-motion'
import styled from "styled-components"
import {useState} from 'react'

function Book() {

    const [isOpen, setOpen] = useState(false)

    const Container = styled(motion.div)`
    position: absolute
    max-width: 18rem
    cursor: pointer
    pointer-event: none
    `
    const BookContainer = styled(motion.div)`
    position: relative
    `

    const bookMotion = {
        rest: {ease: "easeOut", duration: 0.2, type: "tween"},
        hover: {
            rotate: 30, x: 50,
            transition: {
                duration: 0.2,
                type: "tween",
                ease: "easeIn"
            }
        }
    };

    return (
        <div className='flex min-h-72 items-center justify-center'>
            <motion.div layout
                        className='absolute max-w-72 bg-white flex justify-center rounded-md cursor-pointer select-none'>
                <motion.div
                    className='flex min-h-20 flex-col items-center w-72 px-0.5 py-1'
                    transition={{layout: {duration: 2}}}
                    onClick={() => setOpen(!isOpen)}>
                    <motion.h2 layout='size'>*Framer Motion*</motion.h2>
                    {isOpen && (
                        <motion.div>
                            <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Aliquid animi delectus eligendi
                                fuga
                                hic impedit iste minus molestiae repudiandae saepe?
                            </p>
                            <p>Lorem ipsum dolor sit amet.</p>
                        </motion.div>
                    )}
                </motion.div>
            </motion.div>
            <Container initial="rest" whileHover="hover" animate="rest" onClick={() => setOpen(!isOpen)}>
                <BookContainer variants={bookMotion}>
                    <motion.div
                        className='max-w-72 bg-red-800 flex justify-center rounded-md cursor-pointer select-none'
                    >
                        <div className='flex flex-col items-center w-72 px-2 py-1'>
                            <h2>*Framer Motion*</h2>
                        </div>
                    </motion.div>
                </BookContainer>
            </Container>
        </div>
    )
}

export default Book

I have tried to remove pointer events – no change

I have tried to move the text div into the parent element, to circumvent the need of adding the onClick method to the container at all – this causes a reset of the rotation animation, as well as some unintentional shifting of the book cover div

The video I have attached here shows the state where my text div is sibling to the container of the book cover and the container has the onClick method to toggle the text div

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật