javascript - How to show and hide an element when scrolling the window using jquery -
i want show border effect when i'll scroll down , reach on desired section.and it'll hide when i'll leave section. possible using jquery?
using $(document).on('scroll'), this:
<html> <head> <script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script> <style> html,body { height:101%; } #box-1 { width:200px; height:200px; background-color:#333; } .border-1 { border: 10px solid #696969; } </style> <body> <h1 id="mytarget">this desire section</h1> <p>lorem ipsum dolor amit. lorem ipsum dolor amit. lorem ipsum dolor amit. </p> <p>lorem ipsum dolor amit. lorem ipsum dolor amit. lorem ipsum dolor amit. </p> <p>lorem ipsum dolor amit. lorem ipsum dolor amit. lorem ipsum dolor amit. </p> <p>lorem ipsum dolor amit. lorem ipsum dolor amit. lorem ipsum dolor amit. </p> <div id="box-1"></div> <script> $(document).on('scroll', function() { var pos = $(this).scrolltop(); if( pos >= $('#mytarget').offset().top){ $("#box-1").addclass("border-1").show(); } else { $("#box-1").removeclass("border-1").hide(); } }) </script> </body> </html>
Comments
Post a Comment