Background scale as mouse cursor moves towards center

65 views Asked by At

I am trying to get my background image to slowly "zoom in" as the mouse cursor approaches the center of the viewport and vice versa. I have been all of google and the forums, but all I can find are examples of scroll zooming or position changing with mouse move. This is the closest example I can find, but instead of the background position changing I want to change the background image scale. Anybody know how to do this or at least have any ideas?

This is not the image I am using, but for the purpose of this post I just used a random image from Unsplash. This is how my code for my background looks though.

It should be noted that I am fairly new to coding, so I apologize if this is a simple task and I am just overlooking something.

.bg {
  height: 100%;
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
  background-color: rgba(255,255,255,0.5);
  background-blend-mode: lighten;
 }
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">

<body background="https://images.unsplash.com/photo-1520531158340-44015069e78e?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=500&q=60" class="bg" style="height: 100vh">
</body>

<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>

0

There are 0 answers