javascript - How to make the form scroll alongwith the page scroll -


i have mailchimp subscribe newsletter form. want form scroll down alongwith page scroll.

right fadein, fadeoutwhen page scrolled want move down when user scrolling page down.

this html.

<div class="container">     <div class="row">         <div class="pull-right">             <!-- begin mailchimp signup form -->             <link href="//cdn-images.mailchimp.com/embedcode/slim-10_7.css" rel="stylesheet" type="text/css">             <form id="subscribe-form" name="mc-embedded-subscribe-form" class="validate">                 <p>sign our newsletter</p>                 <div id="signup_scroll">                     <div class="mc-field-group">                         <label for="mce-email">email address  <span class="asterisk">*</span>                         </label>                         <input type="email" value="" name="email" class="required email" id="mce-email" required>                     </div>                     <div class="clear"><input type="submit" value="submit" name="subscribe" id="subscribe" class="button"></div>                 </div>             </form>         </div>     </div> </div> 

js

var amountscrolled = 300; $(window).scroll(function() {     if ( $(window).scrolltop() > amountscrolled ) {         $('#subscribe-form').fadein('slow');     } else {         $('#subscribe-form').fadeout('slow');     } });  $('#subscribe-form').click(function() {     $('html, body').animate({         scrolltop: 0     }, 700);     return false; }); 

i solved it.

html

<div class="row newsletter" id="scrollingdiv">         <!-- begin mailchimp signup form -->          <link href="//cdn-images.mailchimp.com/embedcode/slim-10_7.css" rel="stylesheet" type="text/css">         <form id="subscribe-form" name="mc-embedded-subscribe-form" class="validate">             <a id="close" onclick="closedialog()"><i class="fa fa-times" aria-hidden="true"></i></a>             <p>join our newsletter!</p>              <div id="signup_scroll">                 <div class="field-group">                     <label for="email">email address  <span class="asterisk">*</span>                     </label>                     <input type="email" value="" name="email" class="required email" id="email" required>                 </div>                 <div class="clear">                     <input type="submit" id="subscribe" class="button">                 </div>             </div>         </form>     </div> 

js

var $scrollingdiv = $("#scrollingdiv");      $(window).scroll(function(){         $scrollingdiv             .stop()             .animate({"margintop": ($(window).scrolltop()-30) + "px"}, "slow" );     }); 

Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -