原生手机客户端提示信息自定义内容、显示时间

 时间:2026-02-15 18:33:06

1、准备好需要用到的图标。

原生手机客户端提示信息自定义内容、显示时间

2、新建html文档。

原生手机客户端提示信息自定义内容、显示时间

3、书写hmtl代码。

<h2 onclick="aaaaaa.message('自定义显示内容,3秒后消失',3000)">点我显示提示信息<br />支持显示提示内容,消失时间也可控制</h2>

原生手机客户端提示信息自定义内容、显示时间

4、书写css代码。

<style>

*{margin:0;padding: 0;list-style: none;}

body{font-size:62.5%;background: #ebebeb;}

h2{font-size: 0.14rem;text-align: center;}

</style>

原生手机客户端提示信息自定义内容、显示时间

5、书写并添加js代码。

<script src="jquery.min.js"></script>

<script>

var aaaaaa = {

message:function(text,time){

if(!text || !time){

return false;

}

var str = $("<div class='popMessage'><div class='mobileMessage'>"+text+"</div></div>");

str.appendTo("body");

$('.popMessage').css({

position:'fixed',

width:'100%',

height:'100%',

left:'0',

top:'0',

'z-index':'50'

})

$('.mobileMessage').css({

width:'1.4rem',

height:'auto',

position:'absolute',

top:'50%',

left:'50%',

padding:'0.8rem 0.1rem 0.1rem 0.1rem',

'border-radius':'0.1rem',

background:'url(images/message.png) no-repeat center 0.1rem rgba(0,0,0,0.7)',

'background-size':'38% 48%',

overflow:'hidden',

'text-align':'center',

color:'#fff',

'font-size':'0.16rem',

'z-index':'9999',

'-webkit-transform': 'translate(-50%,-50%)',

'-moz-transform': 'translate(-50%,-50%)',

'transform': 'translate(-50%,-50%)'

});

var offMessage = function remove(){

$('.popMessage').remove();

}

setTimeout(offMessage,time);

}

}

</script>

原生手机客户端提示信息自定义内容、显示时间

6、代码整体结构。

原生手机客户端提示信息自定义内容、显示时间

7、查看效果。

原生手机客户端提示信息自定义内容、显示时间

  • 宝宝吃奶后总吐奶该怎么办?
  • 糖醋五花肉怎么做?
  • 如何做蒜苔炒肚条
  • 乡村大拌菜的做法
  • 开启金山电池医生自动省电模式的方法
  • 热门搜索
    唐山旅游景点大全 佛山旅游景点大全 库尔勒旅游 云南有哪些旅游景点 鞍山旅游 雪乡旅游 嘉峪关旅游 成都旅游公司 爱好旅游 南昌旅游必去景点