jQuery

[jQuery] How to move object to desired position using jquery

OOQ 2022. 7. 22. 16:50
728x90
SMALL

You need the ability to move to the desired position by pressing a specific button while developing the Web.
The logic is not difficult.
After receiving the position value of the corresponding area, the scroll may be moved to that position.



Below is the code.

<script>
	//It receives the position value with the class name of t1 in the variable named height.
	var height = $(".t1").offset();

	//The parameters that go into animate are the first position to move and the second speed.
	//Move to the top position of height.
	$("html, body").animate({scrollTop: height.top}, 400};
</script>

 

728x90
LIST