javascript - ScrollTo function scrolls past element -
i have simple contact form set and, since don't have development time @ moment, set 1 using jquery verification instead of ajax. works fine.
but have page scroll down when there errors in form. i've downloaded jquery.scrollto.js , added header.php file. , have following script scrollto:
if ($("#front_page_contactformulier span").hasclass("error")) { $('body').scrollto('#fp_content_006',4000); } now weird thing is, when #front_page_contactformulier span has class error scrolls past element (like literally bottom of page).
if change script element:
if ($("#front_page_contactformulier span").hasclass("error")) { $('body').scrollto('#fp_content_005',4000); } it works?
i cant life of me find out why happening? here full code:
html
<section id="fp_content_006"> <div class="container"> <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12"> <article> <?php if( get_field('koptekst_6') ): ?> <h2><?php the_field('koptekst_6'); ?></h2> <div style="display:block;height:2px;width:30px;background:#f60;margin-left:auto;margin-right:auto;margin-bottom:15px;margin-top:15px;"></div> <?php endif; ?> <?php if( get_field('content_koptekst_6') ): ?> <?php the_field('content_koptekst_6'); ?> <?php endif; ?> </article> </div> <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12"> <div class="row"> <div id="front_page_contactformulier"> <span class="error">error</span> </div> </div> </div> </div> </section> css:
#fp_content_006 { position:relative; margin-bottom:90px; text-align:center; margin-top:90px; } jquery:
if ($("#front_page_contactformulier span").hasclass("error")) { $('body').scrollto('#fp_content_006',4000); } here fiddle, , super weird thing is, works here.
check if jquery.scrollto.js included in header.php file , remember php documentation:
remember header() must called before actual output sent, either normal html tags, blank lines in file, or php. common error read code include, or require, functions, or file access function, , have spaces or empty lines output before header() called. same problem exists when using single php/html file.
you can find documentation here
Comments
Post a Comment