얼렁뚱땅코드/그누보드

특정 이상 스크롤 내리면 동작하게 하는 스크립트 2

얼렁뚱땅 디자이너 2021. 11. 25. 10:34
<div id="left_banner">
	<img src="<?php echo G5_IMG_URL ?>/left_banner01.png" alt="<?php echo $config['cf_title']; ?>"/>
</div>
<style>
	#left_banner{position:absolute;top:80px;left:calc(50% - 740px);z-index:99;}
</style>
<script>
	$(function(){
		$layer=$("#left_banner");
		var speed      = '300';
		var easing     = 'linear';
		$(window).on("scroll", function(){
			top_limit=$("#main_wrap").position().top;
			scroll_y=$(window).scrollTop();
			if(scroll_y>top_limit){
				yPosition=scroll_y-top_limit;
			}else{
				yPosition=20;
			}
			$layer.animate({"top":yPosition }, {duration:speed, easing:easing, queue:false});
		});
	});
</script>

참고 http://monkeyad.shop/index.php