I'm trying to assign two actions to a button in jQuery. The button is supposed to:
- open a hidden div, and...
- scroll down to get said div into view.
While both actions are working on the button, they currently require 2 clicks. On the first click the div appears, but to scroll it into view I need to click the button a second time.
Any suggestions how I am going wrong?
jQuery
$(document).ready(function () {
"use strict";
$('.footer a').click(function (event) {
event.preventDefault();
$('.impr-text').hide(); // hide previous popup div
var id = $(this).data("id"); // get the div id which to show
$('#' + id).fadeIn(function () { // show cuurent click link's popup
$(this).css({
'display': 'block'
});
});
$.scrollTo( '#impressum-footer', 800, {easing:'elasout'} );
});
});
HTML
<div id="impressum-footer">
<div class="footer">
<div class="inner-wrap-imp">
<ul class="impressum-links">
<li><a href="#impressum-footer" class="impr-link" data-id="impr-text">Impressum</a></li>
<li>|</li>
<li><a href="#impressum-footer" class="impr-link" data-id="impr-text">Datenschutz</a></li>
<li class="impressum-button" ><a href="#impressum-footer" class="impr-link" data-id="impr-text"></a></li>
</ul>
</div>
</div>
<div id="impr-text" class="impr-text">
<div class="inner-wrap"> ...
if you want to assign 2 different actions on one button, set it 2 different classes (or IDs), lets say
After, in jQuery you will be able to do:
JsFiddle: http://jsfiddle.net/g2wdd2cb/