Moving background-image on mousemove
How do I make an moving background-image on mousemove?
This was in response to a StackOverflow question: http://stackoverflow.com/questions/16743479/moving-background-with-my-cursor/16744057#16744057. What is a moving background-image on mousemove? How do you make a moving background-image on mousemove? This script and codes were developed by Chris Boon on 29 October 2022, Saturday.
Moving background-image on mousemove - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>moving background-image on mousemove</title> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/meyer-reset/2.0/reset.min.css"> <link rel="stylesheet" href="css/style.css">
</head>
<body> <div id="top-image"></div> <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script> <script src="js/index.js"></script>
</body>
</html>
Moving background-image on mousemove - Script Codes CSS Codes
#top-image {
background:url('https://d3ui957tjb5bqd.cloudfront.net/images/screenshots/products/0/8/8905/red-rocks-park-o.jpg') -25px -50px;
position:fixed ;
top:0;
width:100%;
z-index:0; height:100%; background-size: calc(100% + 50px);
}
Moving background-image on mousemove - Script Codes JS Codes
$(document).ready(function() {
var movementStrength = 25;
var height = movementStrength / $(window).height();
var width = movementStrength / $(window).width();
$("#top-image").mousemove(function(e){ var pageX = e.pageX - ($(window).width() / 2); var pageY = e.pageY - ($(window).height() / 2); var newvalueX = width * pageX * -1 - 25; var newvalueY = height * pageY * -1 - 50; $('#top-image').css("background-position", newvalueX+"px "+newvalueY+"px");
});
});
Developer | Chris Boon |
Username | chrisboon27 |
Uploaded | October 29, 2022 |
Rating | 4.5 |
Size | 2,040 Kb |
Views | 28,336 |
Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!
Name | Size |
Cursor transitions on click | 2,775 Kb |
Chrome flexbox bug - not redrawing when window height reduces | 2,368 Kb |
DDCP homepage tiles | 3,686 Kb |
Text-transform is presentational | 2,700 Kb |
Temporary example for Julie | 2,388 Kb |
On The Move UI | 8,412 Kb |
HOM Date Calculator | 7,517 Kb |
Chrome flexbox bug - breaking layout when repainting | 2,741 Kb |
Alter bg opacity on hover... | 2,054 Kb |
Scaling Enumeration | 3,565 Kb |
Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!
Name | Username | Size |
Haml Calendar | Katydecorah | 5,643 Kb |
Coburg Banks SVG Logo | Mjtweaver | 3,875 Kb |
React Vote Component | Souporserious | 5,465 Kb |
Donald Trump - The New Yorker | Agbales | 2,502 Kb |
A Pen by Alex Edwards | Exards | 8,218 Kb |
Process Accordion | Devilskitchen | 31,432 Kb |
Pruebas de d3.js | Juanmanuelcarnerero | 2,485 Kb |
A Pen by Alexandru Pora | Axpro | 1,615 Kb |
Mobile Sub Menu Concept | Berdejitendra | 2,790 Kb |
TestTube CSS | EZPK | 2,710 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!