php - javascript: scroll to top of page if div becomes visible? -


i using following javascript check see if div visible , if scroll top of page?

jquery.php

<script> $(document).ready(function() { if ($(".message_box_prompt").is(":visible"); ) { $(".message_box_prompt").scrollintoview();            }); }); </script> 

my div message_box_prompt being echoed out using session after mysql query executes:

mysql / process.php

    $_session['message'] = '<div class="message_box_prompt"><div class="boxclose2" id="boxclose2" style="float:right; margin:10px; cursor:pointer; cursor:hand;" onclick="this.parentnode.parentnode.removechild(this.parentnode);">&#10006;</div><div class="message_box_text"><strong>oooops!</strong> account limited. cannot make changes account @ time.</div></div>'; header('location: ' . $_server['http_referer']); 

my session echoed in index.php page includes jquery.php file

index.php:

<?php include 'jquery.php';?> <?php if (isset($_session['message'])) { echo $_session['message']; unset($_session['message']); } ?>   

at moment div being displayed through session javascript won't work , page wont scroll top of page div when it's on show. please can show me going wrong? thanks

i don't think there's scrollintoview method in jquery. can use native js method, need dom node reference, not jquery object. take note of capitalization:

$(function() {     if ($(".message_box_prompt").is(":visible") ) {        $(".message_box_prompt").get(0).scrollintoview();            } }); 

http://jsfiddle.net/2gazue6d/

if use scrollintoview jquery plugin capitalization important.


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -