iTakeo

Archive for 3 月, 2017

标题固定

#fixedContent{width:400px;margin:0 auto;box-shadow:0 0 10px rgba(0,0,0,0.75)}
#fixedContent .titleBox{position:absolute;background:#eee;z-index:10;top:0;left:0;right:0;padding:25px;font-size:12px;border-top:1px solid #333}
.fixedTitle{position:relative;padding-top:52px}
.fixedBox{width: 100%;height: 500px;background: #333;}
01.
02.
03.
04.
<div id="fixedContent">
    <div class="fixedTitle">
        <p class="titleBox">Title #1</p>
        <div class="fixedBox"></div>
    </div>
    <div class="fixedTitle">
        <p class="titleBox">Title #2</p>
        <div class="fixedBox"></div>
    </div>
    ....
</div>
01.
02.
03.
04.
05.
06.
07.
08.
09.
10.
11.
window.onscroll = function(){
    ;[].forEach.call(document.querySelectorAll('.fixedTitle'),function(o){
        var top = o.getBoundingClientRect().top,
            height = o.offsetHeight,
            childTitle = o.querySelector('.titleBox'),
            titleHeight = childTitle.offsetHeight;
            if (top <= (height * -1) + titleHeight) 
                childTitle.style.marginTop = (height - titleHeight)+'px';
            else if (top <= 0) 
                childTitle.style.marginTop= ((top * (-1)) - 1)+'px';
            else 
                childTitle.style.marginTop='0';
    });
};
01.
02.
03.
04.
05.
06.
07.
08.
09.
10.
11.
12.
13.
14.
2017/03/31 2 / /
标签:  暂无标签

微信小程序toast提示插件。

微信小程序toast提示插件。

提示:3月28号微信更新了版本,showToast可以通过image参数修改默认icon了,最大时间也取消了。

以上两个更新实用很多,但icon还是无法去除。显示形式有点单一,无法自定义,可能后续更新会增加更多功能。



下载文章下面的文件,放在根目录。

然后在app.js中引入js并添加到App中,如下:

var wxToast = require('toast/toast.js')
App({
    wxToast ,
    onLaunch: function () {}
})
01.
02.
03.
04.
05.

在app.wxss中添加如下css:

.wxToast_mask{width:100%;height:100%;position:fixed;left:0px;top:0px;z-index:10000;background:rgba(0,0,0,0);opacity:0;display:none}.wxToast_show{display:block}.wxToast_content{max-width:80%;min-width:90px;position:absolute;left:50%;top:20%;transform:translate3d(-50%,0,0);padding:15px;color:#fff;font-size:17px;text-align:center;border-radius:5px;background:rgba(0,0,0,.8)}.wxToast_img{width:55px;height:55px;display:block;margin:0 auto 8px auto}
01.

接着在页面xxx.wxml中添加如下内容:

<import src="../../toast/toast.wxml"/>
<template is="wxToast" data="{{...wxToastConfig}}"></template>
01.
02.

最后在页面xxx.js中就可以调用了。

var app = getApp();  //wxToast挂载在app下面,所以必须先获取app
Page({
    toast: {
        //调用
        app.wxToast({
            title : '加载中'
        })
    },
    onLoad : function( ){}
})
01.
02.
03.
04.
05.
06.
07.
08.
09.
10.

更多方法:

app.wxToast({
    title : '验证码错误',  //标题,不写默认正在加载
    img : '../../images/cc.png', //icon路径,不写不显示
    imgClass : 'images',  //icon添加class类名
    contentClass : 'content',  //内容添加class类名
    duration : 3000,     //延时关闭,默认2000
    tapClose : false,    //点击关闭,默认false
    show : function(){    //显示函数
        console.log('显示啦')
    },
    hide : function(){     //关闭函数
        console.log('消失啦')
    }
});
01.
02.
03.
04.
05.
06.
07.
08.
09.
10.
11.
12.
13.
14.
app.wxToast(false); //如果需要隐藏,参数设置为false即可。
setTimeout(function(){
    app.wxToast(false);
},3000) 
01.
02.
03.
04.

点击这里下载文件

2017/03/29 1 / /
标签:  暂无标签
回到顶部