Skip to content

Instantly share code, notes, and snippets.

@kamranzafar
Created July 18, 2012 14:40
Show Gist options
  • Star 38 You must be signed in to star a gist
  • Fork 13 You must be signed in to fork a gist
  • Save kamranzafar/3136584 to your computer and use it in GitHub Desktop.
Save kamranzafar/3136584 to your computer and use it in GitHub Desktop.
JQuery Mobile Android-style Toast popup
var toast=function(msg){
$("<div class='ui-loader ui-overlay-shadow ui-body-e ui-corner-all'><h3>"+msg+"</h3></div>")
.css({ display: "block",
opacity: 0.90,
position: "fixed",
padding: "7px",
"text-align": "center",
width: "270px",
left: ($(window).width() - 284)/2,
top: $(window).height()/2 })
.appendTo( $.mobile.pageContainer ).delay( 1500 )
.fadeOut( 400, function(){
$(this).remove();
});
}
Copy link

ghost commented Oct 15, 2012

Thank you very much!

@emad-elsaid
Copy link

Yup, thanks that works like a charm.

@teknofreek
Copy link

Thanks, please can u tell me how to use this in an HTML file..?

@joshfromperth
Copy link

Signed up just to say thanks, though it's about time I signed up.
Thank you dude!

@brucelandgate
Copy link

Nice.. works a treat. Thanks very much!

@dcimring
Copy link

dcimring commented Apr 3, 2013

Very nice :) Thanks for sharing.

@subinsebastien
Copy link

Nice piece of code. Thank you!

@uxDaniel
Copy link

uxDaniel commented Jul 9, 2013

Thank you!

@obook
Copy link

obook commented Jul 13, 2013

Cleaver, thank you.

@WebSerGe
Copy link

Thank you

@pengwll
Copy link

pengwll commented Sep 16, 2013

Nice, thank you!

@ahmedali2
Copy link

Amazing!! thank you!!!!!!

@dakshas-iprogrammer
Copy link

Thanks for sharing :)

@fedyunin
Copy link

Thanks!

@xiaobitao
Copy link

good code.
Thank for sharing

@ParAnton
Copy link

ParAnton commented Mar 3, 2014

Works like a charm!

@jlcmes
Copy link

jlcmes commented Mar 5, 2014

I changed:

left: ($(window).width() - 284)/2,
top: $(window).height()/2 })

to:

top: "50%",
left: "50%" })

I used top and left 50% to center the div propertly. Thanks for your code. Hope this helps someone

@xzelin
Copy link

xzelin commented Mar 9, 2014

Thanks! And I have a little change too.

$("《div class='ui-loader ui-overlay-shadow ui-corner-all'》 《p style='word-break:break-all'》“+msg+"《/p》《/div》").css({
"display": "block", "opacity": 0.90, "text-align": "center", "width": "80%", "top": "50%", "left": "10%"
}).appendTo($.mobile.pageContainer).delay(1500).fadeOut(400, function(){$(this).remove()});

@adnanpirota
Copy link

Thank's a lot everyone

@botweb
Copy link

botweb commented Jun 12, 2014

My changes:

function toast(message) {
    var $toast = $('<div class="ui-loader ui-overlay-shadow ui-body-e ui-corner-all"><h3>' + message + '</h3></div>');

    $toast.css({
        display: 'block', 
        background: '#fff',
        opacity: 0.90, 
        position: 'fixed',
        padding: '7px',
        'text-align': 'center',
        width: '270px',
        left: ($(window).width() - 284) / 2,
        top: $(window).height() / 2 - 20
    });

    var removeToast = function(){
        $(this).remove();
    };

    $toast.click(removeToast);

    $toast.appendTo($.mobile.pageContainer).delay(2000);
    $toast.fadeOut(400, removeToast);
}

@bryanmuvi
Copy link

good changes.
Thank for sharing

@pradeeshmp
Copy link

Awesome modification, thanks for the support

@cabolanoz
Copy link

+1

@shubham-gupta-nerdware
Copy link

function toast(message,type) {
var $toast = $('

' + message + '

');
var removeToast = function(){
$(this).remove();
};
$toast.click(removeToast);
$toast.appendTo($('#mcontainer')).delay(3000);
$toast.fadeOut(1000, removeToast);
}

css:--
.toastDiv{display: block;opacity: 0.9;position: fixed;text-align: center;width: 100%;top: 0;height: auto;padding: 0.5% 15%;box-sizing: border-box;line-height: 1.4em;color: #fff;font-size: 10pt;font-family: robotoL;}
.tDanger{background:#D06e6e; border:none;}
.tInfo{background: #378C99 ; border:none;}
.tSuccess{background:#9ab512 ; border:none;}

@sriharigolla
Copy link

nice work

@sriharigolla
Copy link

botweb nice changes

@djwgit
Copy link

djwgit commented Apr 30, 2016

great,thanks, using botweb's change.

@gitdealdo
Copy link

Great, Thanks for shared.

@imspikey
Copy link

Thank you nice work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment