jQuery substring
jQuery('#textArea').keypress(function() {
var text = jQuery('#textArea').val();
if(text.length > 400) {
text = text.substring(0, 400);
jQuery('#textArea').val(text); }
});
jQuery refresh page
jQuery('#refresh-link').click(function() {
location.reload();
});
jQuery message box
#darkbg {
display: none;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: #000;
opacity: .5;
filter: alpha(opacity=50);
-ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=50)";
}
#message_box {
width: 300px;
height: 150px;
background: #fff;
border: 4px solid #f0f0f0;
border-radius: 10px;
-moz-border-radius: 10px;
-webkit-border-radius: 10px;
position: absolute;
top: 100px;
left: 50%;
margin-left: -150px;
text-align: center;
z-index: 1000;
display: none;
}
#message_box input[type=button] {
float: right;
margin-right: 10px;
}
var message_box = function() {
var button = '<input type="button" onclick="message_box.close_message();" value="Okay!" />';
return {
show_message: function(title, body) {
if(jQuery('#message_box').html() === null) {
var message = '<div id="message_box"><h1>' + title + '</h1>' + body + '<br/>' + button + '</div>';
jQuery(document.body).append( message );
jQuery(document.body).append( '<div id="darkbg"></div>' );
jQuery('#darkbg').show();
jQuery('#darkbg').css('height', jQuery('html, body').height());
jQuery('#message_box').css('top', jQuery('html, body').scrollTop() + 150);
jQuery('#message_box').show('slow');
} else {
var message = '<h1>' + title + '</h1>' + body + '<br/>' + button;
jQuery('#darkbg').show();
jQuery('#darkbg').css('height', jQuery('html, body').height());
jQuery('#message_box').css('top', jQuery('html, body').scrollTop() + 150);
jQuery('#message_box').show('slow');
jQuery('#message_box').html( message );
}
},
close_message: function() {
jQuery('#message_box').hide('fast');
jQuery('#darkbg').hide();
}
}
}();
----------
message_box.show_message('Hi!', 'Whatup?!');
-------------
jQuery('#some_link').onclick(function() { message_box.show_message('Hi!', 'Whatup?!'); });
No comments:
Post a Comment