When $errorAlerts are triggered - return to page location of alert.
2 posts by 2 authors in: Forums > CMS Builder Community
Last Post: March 31, 2016 (RSS)
By Zicky - March 26, 2016
Here's a little code for returning to the location of a page where your error alerts appear... when the $errorAlerts are triggered.
<?php if (@$errorsAlerts): ?>
<script type="text/javascript">
$(document).ready(function(){
// http://jsfiddle.net/gunderson/q6mryLc1/4/
//in order to get the last message to the top of the scroll box (body), we need to resize it
onResize();
var $lastMsg = $('#returnA .returnmsgA:last')
var scrollToElement = function($el, ms){
var speed = (ms) ? ms : 600;
$('body').animate({
scrollTop: $el.offset().top
}, speed);
}
scrollToElement($lastMsg, 600);
});
function onResize(){
var $lastMsg = $('#returnA .returnmsgA:last');
var $body = $("body");
$body.css("height", $body.height() + $(window).height() - $lastMsg.height());
}
</script>
<div id="returnA">
<p class="alertMessage returnmsgA"><?php echo $errorsAlerts; ?><br /></p>
</div>
<?php endif ?>
For sticky navigations use and adjust as need the following css:
.returnmsgA {
padding-top:80px;
margin-top:-80px;
}
.alertMessage {
color:#CC0000;
}
If you have suggestions for improvement, please share.
Zicky
By gregThomas - March 31, 2016
That's awesome! Thanks for sharing it with us Zicky.
Cheers,
Greg
PHP Programmer - interactivetools.com