/post

Making a Pop-up Ask Box

Posted by adrengski on Friday, June 8th, 2012
Tagged as: advance tutorials


Wouldn’t it be convenient if instead of going to another page to ask someone, all you’ll have to do is click on a link and a pop up ask box would appear? It saves a lot of seconds and that awful background music wouldn’t have to reload all over again. So for anyone who likes that, here’s a little treat.   

This trick would involve a lot of copy-paste on your custom HTML so be sure to follow all the instructions carefully. The Pop-up jQuery codes was created by the awesome Soh Tanaka by the way so all the credits on the pop-up div goes to him.

First, proceed to your customize page, click on Edit HTML button, then add this set of codes just ABOVE the </style> tag.

#fade { 
 display: none; 
 background: #000;
 position: fixed;
 left: 0;
 top: 0;
 width: 100%;
 height: 100%;
 opacity: .60;
 z-index: 9999;
}
.popup_block{
 display: none; 
 background: #fff;
 padding: 20px;
 border: 20px solid #ddd;
 float: left;
 font-size: 1.2em;
 position: fixed;
 top: 50%; left: 50%;
 z-index: 99999;
 -webkit-box-shadow: 0px 0px 20px #000;
 -moz-box-shadow: 0px 0px 20px #000;
 box-shadow: 0px 0px 20px #000;
 -webkit-border-radius: 10px;
 -moz-border-radius: 10px;
 border-radius: 10px;
}
img.btn_close {
 float: right;
 margin: -55px -55px 0 0;
}
*html #fade {
 position: absolute;
}
*html .popup_block {
 position: absolute;
}

You can change the color of the fade div to any color you like by replacing hex color in the underlined part(background: #000). You can use Colorpicker to choose a color then replace the #000 part.

Next, add these jQuery codes at the bottom of your custom HTML, just above </body> tag.

<div id="popup_name" class="popup_block">
    <h2>Ask me Anything!</h2>
    <p><iframe frameborder="0" border="0" scrolling="no" width="400" height="190" allowtransparency="true" src="http://www.tumblr.com/ask_form/{Name}.tumblr.com" style="background-color:transparent; overflow:hidden;"></iframe></p>
</div>
<script type="text/javascript"
src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
    //Code goes here
});
//When you click on a link with class of poplight and the href starts with a # 
$('a.poplight[href^=#]').click(function() {
    var popID = $(this).attr('rel'); //Get Popup Name
    var popURL = $(this).attr('href'); //Get Popup href to define size
    //Pull Query & Variables from href URL
    var query= popURL.split('?');
    var dim= query[1].split('&');
    var popWidth = dim[0].split('=')[1]; //Gets the first query string value
    //Fade in the Popup and add close button
    $('#' + popID).fadeIn().css({ 'width': Number( popWidth ) }).prepend('<a href="#" class="close"><img src="http://static.tumblr.com/qrevc1p/SEBlsqdsu/close_button.png" class="btn_close" title="Close Window" alt="Close" /></a>');
    //Define margin for center alignment (vertical   horizontal) - we add 80px to the height/width to accomodate for the padding  and border width defined in the css
    var popMargTop = ($('#' + popID).height() + 80) / 2;
    var popMargLeft = ($('#' + popID).width() + 80) / 2;
    //Apply Margin to Popup
    $('#' + popID).css({
        'margin-top' : -popMargTop,
        'margin-left' : -popMargLeft
    });
    //Fade in Background
    $('body').append('<div id="fade"></div>'); //Add the fade layer to bottom of the body tag.
    $('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn(); //Fade in the fade layer - .css({'filter' : 'alpha(opacity=80)'}) is used to fix the IE Bug on fading transparencies 
    return false;
});
//Close Popups and Fade Layer
$('a.close, #fade').live('click', function() { //When clicking on the close or fade layer...
    $('#fade , .popup_block').fadeOut(function() {
        $('#fade, a.close').remove();  //fade them both out
    });
    return false;
});
</script>

You can change The Ask me anything part into anything you like. You can also change the underlined part with any small image you want to act as a close button.

Lastly, search for codes that goes like this: <a href=”/ask>Something is in here</a>. Note that this may differ from theme to theme so the Something-is-in-here part may be different. But it usually starts with <a href=”/ask”>. If you find it, delete that up to the </a> part then replace it with these:

<a href="#?w=400" rel="popup_name" class="poplight">Ask me!</a>

After that, hit save and try it out. If you had problems in setting this up or anything, you can always hit my ask box up. It’s not pop-up though so you’ll have to get redirected.


18 notes | Comments

Comment

blog comments powered by Disqus

Notes

  1. adrengski reblogged this from tutobx and added:
    Wouldn’t it be convenient if instead of going to another page to ask someone, all you’ll have to do is click on a link...
  2. tutobx posted this
/ask

Questions! Questions!


Before asking a question, make sure to check the FAQs page or the Answers page first incase it's already answered there. If it isn't then ask away!

All questions/TAs, anon or not, will be published on the Answers page so check it if it's already there. The post will be tagged under your URL , too, so tracking your URLs would be a nice way to notify you.

Also note that I may not be able to answer questions ASAP since unfortunately, I also have this evil stuff called "Real life" and it requires me to do things like "Working" and "Socializing". Rest assured though, that I will be answering all questions whenever I go online and if there's any.

DONATE! On a related note, You could also increase the chance of getting answered immediately by Donating! You see, if you donate, that would mean more moolah. If there's moolah around, I don't have to work that much. And if I don't have to work that much, that would mean more time in answering your queries! I mean, that's the only thing that's keeping me away from here anyway. So yeah, a buck wouldn't hurt, right?


Scroll to top