Lara Baldwin

Lara Baldwin

1585279980

How to Change Image Dynamically when User Scrolls using JavaScript?

We are going to add the functionality to our web-page so that whenever the user scrolls up or scrolls down on the image, then the image changes. We have used only 3 images but it can easily be expanded for multiple images.

We are keeping the images on top of each other, this makes sure only one image is visible at a time. When we scroll, we decrement the z-coordinate of the current image and increments the z-coordinate of the new image. By doing this the new image overlays the old image and it comes on top of all images and becomes visible.

  • HTML Code: It is used to create a basic structure to include images.
<!DOCTYPE html> 
<html> 

<head> 
	<meta charset="utf-8" /> 
	<title> 
		Change Image Dynamically 
		when User Scrolls 
	</title> 
</head> 

<body> 
<h1>GeeksforGeeks</h1> 
<b>A Computer Science Portal for Geeks</b> 
	<div id="scroll-image"> 
		<img src="CSS.png" class="test" /> 
		<img src="html.png" class="test" /> 
		<img src="php.png" class="test" /> 
	</div> 
</body> 

</html>					 
  • CSS Code: Css is used to desing the structure. The position propety is the most important things here. It will make all the images to appear on top of each other.
<style> 
	body { 
		text-align: center; 
	} 
	h1 { 
		color: green; 
	} 
	img { 
		position: absolute; 
		left: 300px; 
	} 
</style> 
  • Javscript code: In this section we will add JavaScript code to perform the scrolling on the image.
<script> 
	window.onload = function() { 

		// Index of current image 
		// which is on display 
		var imageIndex = 0; 

		// Object array of all the 
		// images of class test 
		var images = 
			document.getElementsByClassName('test'); 

		// This tells us if mouse if over 
		// image or not, We only change 
		// image if mouse if over it 
		var isMouseOverImage = false; 

		// Object of parent element 
		// containing all images 
		var scrollImages = 
			document.getElementById('scroll-image'); 

		// Stores the current scoll co-ordinates 
		// so that the window don't scroll down 
		// while scrolling the images 
		var x, y; 

		// This function sets the scroll to x, y 
		function noScroll() { 
			window.scrollTo(x, y); 
		} 

		// The following event id fired once when 
		// We hover mouse over the images 
		scrollImages.addEventListener( 
				"mouseenter", function() { 

			// We store the current page 
			// offset to x,y 
			x = window.pageXOffset; 
			y = window.pageYOffset; 

			// We add the following event to 
			// window object, so if we scroll 
			// down after mouse is over the 
			// image we can avoid scrolling 
			// the window 
			window.addEventListener("scroll", noScroll); 
			
			// We set isMouseOverImage to 
			// true, this means Mouse is 
			// now over the iamge 
			isMouseOverImage = true; 
		}); 

		// The following function is fired 
		// when mouse is no longer over 
		// the images 
		scrollImages.addEventListener( 
				"mouseleave", function() { 

			// We set isMouseOverImage to 
			// false, this means mouse is 
			// not over the iamge 
			isMouseOverImage = false; 

			// We remove the event we previously 
			// added because we are no longer 
			// over the image, the scroll will 
			// now scroll the window 
			window.removeEventListener( 
						"scroll", noScroll); 
		}); 

		// The following function is called 
		// when we move mouse wheel over 
		// the images 
		scrollImages.addEventListener( 
					"wheel", function(e) { 
							
			// We check if we are over 
			// image or not 
			if (isMouseOverImage) { 
				var nextImageIndex; 

				// The following condition 
				// finds the next image 
				// index depending if we 
				// scroll up or scroll down 
				if (e.deltaY > 0) 
					nextImageIndex = (imageIndex + 1) 
									% images.length; 
				else
					nextImageIndex = 
							(imageIndex - 1 
							+ images.length) 
							% images.length; 

				// We set the z index of current 
				// image to 0 
				images[imageIndex].style.zIndex = "0"; 
					
				// We set the z index of next 
				// image to 1, this makes 
				// The new image appear on top 
				// of old image 
				images[nextImageIndex].style.zIndex = "1"; 
				imageIndex = nextImageIndex; 
			} 
		}); 
	} 
</script> 

Final Solution: In this section we will combine the avobe three section.

<!DOCTYPE html> 
<html> 

<head> 
	<meta charset="utf-8" /> 
	<title> 
		Change image dynamically 
		when user scrolls 
	</title> 
	
	<style> 
		body { 
			text-align: center; 
		} 
		h1 { 
			color: green; 
		} 
		img { 
			position: absolute; 
			left: 300px; 
		} 
	</style> 
</head> 

<body> 
	<h1>GeeksforGeeks</h1> 
	
	<b>A Computer Science Portal for Geeks</b> 
	
	<div id="scroll-image"> 
		<img src="CSS.png" class="test" /> 
		<img src="html.png" class="test" /> 
		<img src="php.png" class="test" /> 
	</div> 
	
	<script> 
		window.onload = function() { 
	
			// Index of current image 
			// which is on display 
			var imageIndex = 0; 
	
			// Object array of all the 
			// images of class test 
			var images = 
				document.getElementsByClassName('test'); 
	
			// This tells us if mouse if over 
			// image or not, We only change 
			// image if mouse if over it 
			var isMouseOverImage = false; 
	
			// Object of parent element 
			// containing all images 
			var scrollImages = 
				document.getElementById('scroll-image'); 
	
			// Stores the current scoll co-ordinates 
			// so that the window don't scroll down 
			// while scrolling the images 
			var x, y; 
	
			// This function sets the scroll to x, y 
			function noScroll() { 
				window.scrollTo(x, y); 
			} 
	
			// The following event id fired once when 
			// We hover mouse over the images 
			scrollImages.addEventListener( 
					"mouseenter", function() { 
	
				// We store the current page 
				// offset to x,y 
				x = window.pageXOffset; 
				y = window.pageYOffset; 
	
				// We add the following event to 
				// window object, so if we scroll 
				// down after mouse is over the 
				// image we can avoid scrolling 
				// the window 
				window.addEventListener("scroll", noScroll); 
				
				// We set isMouseOverImage to 
				// true, this means Mouse is 
				// now over the iamge 
				isMouseOverImage = true; 
			}); 
	
			// The following function is fired 
			// when mouse is no longer over 
			// the images 
			scrollImages.addEventListener( 
					"mouseleave", function() { 
	
				// We set isMouseOverImage to 
				// false, this means mouse is 
				// not over the iamge 
				isMouseOverImage = false; 
	
				// We remove the event we previously 
				// added because we are no longer 
				// over the image, the scroll will 
				// now scroll the window 
				window.removeEventListener( 
							"scroll", noScroll); 
			}); 
	
			// The following function is called 
			// when we move mouse wheel over 
			// the images 
			scrollImages.addEventListener( 
						"wheel", function(e) { 
								
				// We check if we are over 
				// image or not 
				if (isMouseOverImage) { 
					var nextImageIndex; 
	
					// The following condition 
					// finds the next image 
					// index depending if we 
					// scroll up or scroll down 
					if (e.deltaY > 0) 
						nextImageIndex = (imageIndex + 1) 
										% images.length; 
					else
						nextImageIndex = 
								(imageIndex - 1 
								+ images.length) 
								% images.length; 
	
					// We set the z index of current 
					// image to 0 
					images[imageIndex].style.zIndex = "0"; 
						
					// We set the z index of next 
					// image to 1, this makes 
					// The new image appear on top 
					// of old image 
					images[nextImageIndex].style.zIndex = "1"; 
					imageIndex = nextImageIndex; 
				} 
			}); 
		} 
	</script> 
</body> 

</html> 

Output:

Note: The above code will change image only if mouse if over the image.

Originally published at https://www.geeksforgeeks.org

#javascript #web-development #image

What is GEEK

Buddha Community

How to Change Image Dynamically when User Scrolls using JavaScript?
Lara Baldwin

Lara Baldwin

1585279980

How to Change Image Dynamically when User Scrolls using JavaScript?

We are going to add the functionality to our web-page so that whenever the user scrolls up or scrolls down on the image, then the image changes. We have used only 3 images but it can easily be expanded for multiple images.

We are keeping the images on top of each other, this makes sure only one image is visible at a time. When we scroll, we decrement the z-coordinate of the current image and increments the z-coordinate of the new image. By doing this the new image overlays the old image and it comes on top of all images and becomes visible.

  • HTML Code: It is used to create a basic structure to include images.
<!DOCTYPE html> 
<html> 

<head> 
	<meta charset="utf-8" /> 
	<title> 
		Change Image Dynamically 
		when User Scrolls 
	</title> 
</head> 

<body> 
<h1>GeeksforGeeks</h1> 
<b>A Computer Science Portal for Geeks</b> 
	<div id="scroll-image"> 
		<img src="CSS.png" class="test" /> 
		<img src="html.png" class="test" /> 
		<img src="php.png" class="test" /> 
	</div> 
</body> 

</html>					 
  • CSS Code: Css is used to desing the structure. The position propety is the most important things here. It will make all the images to appear on top of each other.
<style> 
	body { 
		text-align: center; 
	} 
	h1 { 
		color: green; 
	} 
	img { 
		position: absolute; 
		left: 300px; 
	} 
</style> 
  • Javscript code: In this section we will add JavaScript code to perform the scrolling on the image.
<script> 
	window.onload = function() { 

		// Index of current image 
		// which is on display 
		var imageIndex = 0; 

		// Object array of all the 
		// images of class test 
		var images = 
			document.getElementsByClassName('test'); 

		// This tells us if mouse if over 
		// image or not, We only change 
		// image if mouse if over it 
		var isMouseOverImage = false; 

		// Object of parent element 
		// containing all images 
		var scrollImages = 
			document.getElementById('scroll-image'); 

		// Stores the current scoll co-ordinates 
		// so that the window don't scroll down 
		// while scrolling the images 
		var x, y; 

		// This function sets the scroll to x, y 
		function noScroll() { 
			window.scrollTo(x, y); 
		} 

		// The following event id fired once when 
		// We hover mouse over the images 
		scrollImages.addEventListener( 
				"mouseenter", function() { 

			// We store the current page 
			// offset to x,y 
			x = window.pageXOffset; 
			y = window.pageYOffset; 

			// We add the following event to 
			// window object, so if we scroll 
			// down after mouse is over the 
			// image we can avoid scrolling 
			// the window 
			window.addEventListener("scroll", noScroll); 
			
			// We set isMouseOverImage to 
			// true, this means Mouse is 
			// now over the iamge 
			isMouseOverImage = true; 
		}); 

		// The following function is fired 
		// when mouse is no longer over 
		// the images 
		scrollImages.addEventListener( 
				"mouseleave", function() { 

			// We set isMouseOverImage to 
			// false, this means mouse is 
			// not over the iamge 
			isMouseOverImage = false; 

			// We remove the event we previously 
			// added because we are no longer 
			// over the image, the scroll will 
			// now scroll the window 
			window.removeEventListener( 
						"scroll", noScroll); 
		}); 

		// The following function is called 
		// when we move mouse wheel over 
		// the images 
		scrollImages.addEventListener( 
					"wheel", function(e) { 
							
			// We check if we are over 
			// image or not 
			if (isMouseOverImage) { 
				var nextImageIndex; 

				// The following condition 
				// finds the next image 
				// index depending if we 
				// scroll up or scroll down 
				if (e.deltaY > 0) 
					nextImageIndex = (imageIndex + 1) 
									% images.length; 
				else
					nextImageIndex = 
							(imageIndex - 1 
							+ images.length) 
							% images.length; 

				// We set the z index of current 
				// image to 0 
				images[imageIndex].style.zIndex = "0"; 
					
				// We set the z index of next 
				// image to 1, this makes 
				// The new image appear on top 
				// of old image 
				images[nextImageIndex].style.zIndex = "1"; 
				imageIndex = nextImageIndex; 
			} 
		}); 
	} 
</script> 

Final Solution: In this section we will combine the avobe three section.

<!DOCTYPE html> 
<html> 

<head> 
	<meta charset="utf-8" /> 
	<title> 
		Change image dynamically 
		when user scrolls 
	</title> 
	
	<style> 
		body { 
			text-align: center; 
		} 
		h1 { 
			color: green; 
		} 
		img { 
			position: absolute; 
			left: 300px; 
		} 
	</style> 
</head> 

<body> 
	<h1>GeeksforGeeks</h1> 
	
	<b>A Computer Science Portal for Geeks</b> 
	
	<div id="scroll-image"> 
		<img src="CSS.png" class="test" /> 
		<img src="html.png" class="test" /> 
		<img src="php.png" class="test" /> 
	</div> 
	
	<script> 
		window.onload = function() { 
	
			// Index of current image 
			// which is on display 
			var imageIndex = 0; 
	
			// Object array of all the 
			// images of class test 
			var images = 
				document.getElementsByClassName('test'); 
	
			// This tells us if mouse if over 
			// image or not, We only change 
			// image if mouse if over it 
			var isMouseOverImage = false; 
	
			// Object of parent element 
			// containing all images 
			var scrollImages = 
				document.getElementById('scroll-image'); 
	
			// Stores the current scoll co-ordinates 
			// so that the window don't scroll down 
			// while scrolling the images 
			var x, y; 
	
			// This function sets the scroll to x, y 
			function noScroll() { 
				window.scrollTo(x, y); 
			} 
	
			// The following event id fired once when 
			// We hover mouse over the images 
			scrollImages.addEventListener( 
					"mouseenter", function() { 
	
				// We store the current page 
				// offset to x,y 
				x = window.pageXOffset; 
				y = window.pageYOffset; 
	
				// We add the following event to 
				// window object, so if we scroll 
				// down after mouse is over the 
				// image we can avoid scrolling 
				// the window 
				window.addEventListener("scroll", noScroll); 
				
				// We set isMouseOverImage to 
				// true, this means Mouse is 
				// now over the iamge 
				isMouseOverImage = true; 
			}); 
	
			// The following function is fired 
			// when mouse is no longer over 
			// the images 
			scrollImages.addEventListener( 
					"mouseleave", function() { 
	
				// We set isMouseOverImage to 
				// false, this means mouse is 
				// not over the iamge 
				isMouseOverImage = false; 
	
				// We remove the event we previously 
				// added because we are no longer 
				// over the image, the scroll will 
				// now scroll the window 
				window.removeEventListener( 
							"scroll", noScroll); 
			}); 
	
			// The following function is called 
			// when we move mouse wheel over 
			// the images 
			scrollImages.addEventListener( 
						"wheel", function(e) { 
								
				// We check if we are over 
				// image or not 
				if (isMouseOverImage) { 
					var nextImageIndex; 
	
					// The following condition 
					// finds the next image 
					// index depending if we 
					// scroll up or scroll down 
					if (e.deltaY > 0) 
						nextImageIndex = (imageIndex + 1) 
										% images.length; 
					else
						nextImageIndex = 
								(imageIndex - 1 
								+ images.length) 
								% images.length; 
	
					// We set the z index of current 
					// image to 0 
					images[imageIndex].style.zIndex = "0"; 
						
					// We set the z index of next 
					// image to 1, this makes 
					// The new image appear on top 
					// of old image 
					images[nextImageIndex].style.zIndex = "1"; 
					imageIndex = nextImageIndex; 
				} 
			}); 
		} 
	</script> 
</body> 

</html> 

Output:

Note: The above code will change image only if mouse if over the image.

Originally published at https://www.geeksforgeeks.org

#javascript #web-development #image

I am Developer

1597469369

Crop and Resize Image Before Upload In Laravel Using with jQuery Copper JS

Crop and resize image size before upload in laravel using jquery copper js. In this post, i will show you how to crop and resize image size in laravel using jQuery copper js in laravel.

This laravel crop image before upload using cropper js looks like:

laravel crop image before upload

Laravel Crop Image Before Uploading using Cropper js Tutorial

Laravel crop image before upload tutorial, follow the following steps and learn how to use cropper js to crop image before uploading in laravel app:

  • Step 1: Install New Laravel App
  • Step 2: Add Database Details
  • Step 3: Create Migration & Model
  • Step 4: Add Route
  • Step 5: Create Controller By Artisan
  • Step 6: Create Blade View
  • Step 7: Make Upload Directory
  • Step 8: Start Development Server

Read More => https://www.tutsmake.com/laravel-crop-image-before-upload-using-jquery-copper-js/

Live Demo Laravel Crop image Before Upload.

#laravel crop image before upload, #laravel crop and resize image using cropper.js #ajax image upload and crop with jquery and laravel #crop and upload image ajax jquery laravel #crop image while uploading with jquery laravel #image crop and upload using jquery with laravel ajax

CSS Boss

CSS Boss

1606912089

How to create a calculator using javascript - Pure JS tutorials |Web Tutorials

In this video I will tell you How to create a calculator using javascript very easily.

#how to build a simple calculator in javascript #how to create simple calculator using javascript #javascript calculator tutorial #javascript birthday calculator #calculator using javascript and html

Bhakti Rane

1624530835

User Adoption Monitor - Manage & Analyze Dynamics 365 CRM Process

User Adoption Monitor is a productivity app for Dynamics 365 CRM. It allows you to track Dynamics 365 CRM usage by monitoring the actions performed by users in Dynamics CRM. It helps to significantly improve user adoption of Microsoft Dynamics 365 CRM. All the data tracked by User Adoption Monitor is stored in a format that is easy to report on. It offers the ability to track user actions in Dynamics 365 CRM on daily, weekly or monthly basis. With the included intuitive dashboard, this tool is best suited for Managers to oversee and evaluate the work performed by users.
Salient Features of User Adoption Monitor:
• Dashboard Reporting per Entity/ Action/ Period
• Dashboard Reporting per User/ Period
• User Adoption Report Creation
• Monitor Usage Without Disrupting On-going Activity
• Track OOB and Custom Entities Records
• Define Monitoring Period for Entities
• Define Users you want to monitor
• Define Entities and Associated Actions
• Monitor Usage on Daily, Weekly or Monthly basis

https://www.inogic.com/product/productivity-apps/user-adoption-monitor-in-dynamics-crm

#dynamics 365 user activity tracker #dynamics crm user activity #usage report dynamics crm #microsoft dynamics 365 user adoption

Rahul Jangid

1622207074

What is JavaScript - Stackfindover - Blog

Who invented JavaScript, how it works, as we have given information about Programming language in our previous article ( What is PHP ), but today we will talk about what is JavaScript, why JavaScript is used The Answers to all such questions and much other information about JavaScript, you are going to get here today. Hope this information will work for you.

Who invented JavaScript?

JavaScript language was invented by Brendan Eich in 1995. JavaScript is inspired by Java Programming Language. The first name of JavaScript was Mocha which was named by Marc Andreessen, Marc Andreessen is the founder of Netscape and in the same year Mocha was renamed LiveScript, and later in December 1995, it was renamed JavaScript which is still in trend.

What is JavaScript?

JavaScript is a client-side scripting language used with HTML (Hypertext Markup Language). JavaScript is an Interpreted / Oriented language called JS in programming language JavaScript code can be run on any normal web browser. To run the code of JavaScript, we have to enable JavaScript of Web Browser. But some web browsers already have JavaScript enabled.

Today almost all websites are using it as web technology, mind is that there is maximum scope in JavaScript in the coming time, so if you want to become a programmer, then you can be very beneficial to learn JavaScript.

JavaScript Hello World Program

In JavaScript, ‘document.write‘ is used to represent a string on a browser.

<script type="text/javascript">
	document.write("Hello World!");
</script>

How to comment JavaScript code?

  • For single line comment in JavaScript we have to use // (double slashes)
  • For multiple line comments we have to use / * – – * /
<script type="text/javascript">

//single line comment

/* document.write("Hello"); */

</script>

Advantages and Disadvantages of JavaScript

#javascript #javascript code #javascript hello world #what is javascript #who invented javascript