jQuery animation for a hover with 'mouse direction'

后端 未结 7 567
有刺的猬
有刺的猬 2021-01-30 00:01

I\'m trying to simulate the effect where I hover on an image an overlayed semi-transparent image will fade in from the direction where your mouse came from. Vice versa when your

7条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-30 00:09

    If I were going to implement this functionality, here's how I'd approach it:

    1. Create image map areas defining the top, bottom, left, and right borders for the image.
    2. For each image where you want this intelligence (i.e. what side was it entered on, what side was it departed from): a) track the sideEntered -- this value is assigned once and only once; whenever an image-map border area is entered its mouseover handler will consult sideEntered and assign it only if it has not yet been assigned; b) track the lastSideTouched -- whenever an image map area is entered its mouseoverhandler reassigns this variable c) when the mouse leaves the rectangle, the leave handler consults lastSideTouched and resets sideEntered to null

    Each rectangle should have its own handlers so the two important values, sideEntered and lastSideTouched, are encapsulated within the scope of its handler.

提交回复
热议问题