鼠标移动时底部图片旋转一定角度,上层字体不旋转,来实现视差效果
private void Image_MouseMove(object sender, MouseEventArgs e)
{
var moveX = (e.GetPosition(this.img).X / this.img.ActualWidth - 0.5) * (-25);
var moveY = -(e.GetPosition(this.img).Y / this.img.ActualHeight - 0.5) * (-20);
DoubleAnimation da = new DoubleAnimation();
da.Duration = new Duration(TimeSpan.FromSeconds(1));
da.To = 10d;
Vector3D axis = new Vector3D(moveX, moveY, 0);
AxisAngleRotation3D aar = this.FindName("MyAxisAngleRotation3D") as AxisAngleRotation3D;
if (aar != null)
{
aar.Axis = axis;
aar.BeginAnimation(AxisAngleRotation3D.AngleProperty, da);
}
}
评论