SORU
3 Mart 2009, Salı


Mesaj Başlığı sadece Yığın Taşması gibi

Bu yığın taşması ziyaret ettim ve ilk kez bir metin ve Kapat düğmesi gösteren güzel bir başlık mesajı gördüm.

Başlık çubuğu, tek bir sabit ve büyük ziyaretçi dikkatini çekmek için. Siz kimseyi kodu başlık çubuğunun aynı şey olduğunu merak ediyordum.

CEVAP
3 Mart 2009, Salı


Saf JavaScript uygulama: hızlı

function MessageBar() {
    // CSS styling:
    var css = function(el,s) {
        for (var i in s) {
            el.style[i] = s[i];
        }
        return el;
    },
    // Create the element:
    bar = css(document.createElement('div'), {
        top: 0,
        left: 0,
        position: 'fixed',
        background: 'orange',
        width: '100%',
        padding: '10px',
        textAlign: 'center'
    });
    // Inject it:
    document.body.appendChild(bar);
    // Provide a way to set the message:
    this.setMessage = function(message) {
        // Clear contents:
        while(bar.firstChild) {
            bar.removeChild(bar.firstChild);
        }
        // Append new message:
        bar.appendChild(document.createTextNode(message));
    };
    // Provide a way to toggle visibility:
    this.toggleVisibility = function() {
        bar.style.display = bar.style.display === 'none' ? 'block' : 'none';
    };
}

Nasıl kullanmak için:

var myMessageBar = new MessageBar();
myMessageBar.setMessage('hello');
// Toggling visibility is simple:
myMessageBar.toggleVisibility();

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • super1988guy

    super1988guy

    9 Aralık 2007
  • talkandroid

    talkandroid

    27 Mayıs 2010
  • wwjoshdu

    wwjoshdu

    18 ŞUBAT 2011