अद्यतन:
कोड का इस्तेमाल किया:
$(function(){
$('#smsg_link').click(function(){
showMessage('#9BED87', 'black', 'This is sample success message');
return false;
});
$('#imsg_link').click(function(){
showMessage('#FFE16B', 'black', 'This is sample info message');
return false;
});
$('#emsg_link').click(function(){
showMessage('#ED869B', 'black', 'This is sample error message');
return false;
});
});
/*
showMessage function by Sarfraz:
-------------------------
Shows fancy message on top of the window
params:
- bgcolor: The background color for the message box
- color: The text color of the message box
- msg: The message text
*/
var interval = null;
function showMessage(bgcolor, color, msg)
{
$('#smsg').remove();
clearInterval(interval);
if (!$('#smsg').is(':visible'))
{
if (!$('#smsg').length)
{
$('<div id="smsg">'+msg+'</div>').appendTo($('body')).css({
position:'fixed',
top:0,
left:0,
width:'98%',
height:'30px',
lineHeight:'30px',
background:bgcolor,
color:color,
zIndex:1000,
padding:'10px',
fontWeight:'bold',
fontSize:'18px',
textAlign:'center',
opacity:0.8,
margin:'auto',
display:'none'
}).slideDown('show');
interval = setTimeout(function(){
$('#smsg').animate({'width':'hide'}, function(){
$('#smsg').remove();
});
}, 3000);
}
}
}
मैं एफ आप अपना खुद का बनाना चाहते हैं, jQuery के slideToggle
फ़ंक्शन देखें।
के बजाय एक टॉगल है संलग्न पंक्ति के बाद बस यह करें: bar.style.display = message === ''? 'कोई नहीं': 'ब्लॉक'; फिर जब आप बार से छुटकारा पाने के लिए चाहते हैं तो बस: myMessageBar.setMessage (''); –
दृश्यता टॉगल करना मेरे लिए एक और अधिक सहज ज्ञान युक्त एपीआई जैसा लगता है; मैं उम्मीद करता हूं कि रिक्त संदेश को बिना किसी बार के बजाए रिक्त संदेश के रूप में दिखाया जाएगा। – Matchu
बार के लिए एक क्लिक के रूप में आप myMessageBar.toggleVisibility() को कैसे आमंत्रित करेंगे? –