手机端投票

// JavaScript Document
$(function(){
    mobile.init();
})
var mobile={
    init:function(){
        //mobile.vote();//投TA一票
        mobile.dragDrop();//投票弹层提示动画
        mobile.getVerCode();//获取验证码
        mobile.download();//投TA一票进入下载
        mobile.pic();
    },   
    download:function(){          
        /*$(document).on("click",".download_app",function(){       
         //查询手机设备是否有这个APP,有的话直接进入,没有则提示下载该软件,用户可以不下载,关闭弹窗
        */
    },
        pic:function (){
        if($(".carousel img").attr("display") !== "none"){
            $(".carousel img").each(       
            function(){   
                var height = $(this).height();
                var pa_height = $(this).parent().parent().height();       
                var delta_height = height - pa_height;   
                //alert(height  + " " +  pa_height);        //alert执行了好几次,第一个是对的,为何后面的图片因为隐藏而显示为零?
                 var rate = delta_height/2;           
                $(this).css({position:"absolute",top:"-"+rate+"px"});        //为何只执行了一次?                
            });
 
            }
 
    },
 
    dragDrop:function(){
        $(".tbsucc ul li:nth-child(1) a").click(function(){
            //$(".tbsucc").hide();
        });
    },
    getVerCode:function(){
        $('#getcode').bind({
        showTime : function(){
            var n=$(this).attr('showtime');   
            n--;
            if(n<0){
                $(this).attr('showtime',n).removeClass('no').html('发送验证码');
                var id=$(this).attr('intid');
                clearInterval(id);
            }else{
                $(this).attr('showtime',n).addClass('no').html('重新获取('+n+')');
                var id=$(this).attr('intid');
            }
        },
        intTimeShow : function() {
            var id = $(this).attr("intid");
            clearInterval(id);
            $(this).addClass('no');
            $(this).attr('showtime',60).addClass('no').html('重新获取('+60+')');
            var $this = this;
            id=setInterval(function() {
                $($this).trigger("showTime");
            }, 1000);
            $(this).attr("intid",id);
        },
        getPhoneRandCode : function(){
            if($(this).hasClass('no')){
                return false;
            }
            var vs=$.trim($("#zh_phone").val());
            if($.isEmpty(vs)){
                $.promptBox("请填写手机号",'#zh_phone');
                return false;
            }else if(!$.isPhone(vs)){
                $.promptBox("请输入正确手机号",'#zh_phone');
                return false;
            }else {
                $.get(rootPath+'/ajax/user/sms/send?type=2&phone='+vs,function(data){
                    if(data.result=1){
                        $('#getcode').trigger("intTimeShow");
 
                    }else if(data.result==11112){
                        $.promptBox("用户未激活",'#zh_phone');
 
                    }else if(data.result==11252){
                        $.promptBox("短信验证码过期或者不存在",'#zh_code');
                    }else if(data.result==11253){
                        $.promptBox("手机号不正确",'#zh_phone');
                    }else if(data.result==11255){
                        $.promptBox("验证码过期",'#zh_code');
                    }else{
                        //发送失败
                        //$.promptBox("系统繁忙");
                        alert('发送失败')
                    }
                })
            }
 
        }
    }).click(function(){
        $(this).trigger("getPhoneRandCode");
    });
 
    }
}
 
 
 //点击投他一票  弹出提示下载和打开应用信息
$(document).on("click",".download_app",function(){     
     $(".inform_download").css("display","block");
     $(".filter").css("display","block");    
});
//点击下载横幅的 关闭图片,关闭提示下载横幅
$(".alert_download .close_it").on("click",function(){     
     $(this).parent().css("display","none");
 
});
//点击提示信息的关闭图片,关闭提示下载和打开应用的信息
$(".inform_download .close_it").on("click",function(){     
     $(this).parent().parent().css("display","none");
     $(".filter").css("display","none");
});
 
 
 
//to_download  下载横幅,点击下载客户端,判断手机设备,进行下载
$(document).on("click",".to_download",function(){   
        var url;
        if (navigator.userAgent.match(/(iPhone|iPod|iPad);?/i)) {
            if(navigator.userAgent.match(/micromessenger/i)){
                alert("请在别的浏览器打开!");
            }               
             url = 'itms-apps://itunes.apple.com/cn/app/1093025311';// 苹果手机 下载链接                   
        } else if (navigator.userAgent.match(/android/i)) {
            if(navigator.userAgent.match(/micromessenger/i)){
                alert("请在别的浏览器打开!");       
            }
              url ='http://jxc.ds70.com/Download/jxch20160406.apk';//打开 安卓手机下载链接   
        }         
        var ret = window.open(url,"app");      
});
 
 
 
// 点击提示弹窗的 已安装:打开应用 open_app
//判断手机设备,并判断是否下载软件
$(document).on("click",".open_app",function(){           
         //查询手机设备是否有这个APP,有的话直接进入,没有则提示下载该软件,用户可以不下载,关闭弹窗
        if (navigator.userAgent.match(/(iPhone|iPod|iPad);?/i)) {
                var ret = window.open("JXCAppLink://","app"); //打开软件
                if(navigator.userAgent.match(/micromessenger/i)){
                    alert("微信内无法打开,请在别的浏览器打开!");           
                }   
                setTimeout(function(){
                    ret.location.href= 'itms-apps://itunes.apple.com/cn/app/1093025311';//打开下载链接                   
                },500);
 
        } else if (navigator.userAgent.match(/android/i)) {
              var ret = window.open("myscheme://com.jxch.app/get/info?id=10000","app");//打开软件
                if(navigator.userAgent.match(/micromessenger/i)){
                    alert("微信内无法打开,请在别的浏览器打开!");           
                }   
                setTimeout(function(){
                        var down = window.open('http://jxc.ds70.com/Download/jxch20160415.apk',"app");//打开下载链接   
                },500);
 
        }
 
});
//前去下载 按钮go_download
$(document).on("click",".go_download",function(){           
         //查询手机设备是否有这个APP,有的话直接进入,没有则提示下载该软件,用户可以不下载,关闭弹窗
        if (navigator.userAgent.match(/(iPhone|iPod|iPad);?/i)) {
                var down =window.open('itms-apps://itunes.apple.com/cn/app/1093025311');//打开下载链接
                if(navigator.userAgent.match(/micromessenger/i)){
                    alert("微信内无法打开,请在别的浏览器打开!");           
                }                               
        } else if (navigator.userAgent.match(/android/i)) {
              var down = window.open('http://jxc.ds70.com/Download/jxch20160415.apk',"app");//打开下载链接
                if(navigator.userAgent.match(/micromessenger/i)){
                    alert("微信内无法打开,请在别的浏览器打开!");           
                }                                               
        }
 
});
//方案1,用js,倒计时,获取图片高度,和父元素高度,二者之差,除以2,图片的top定位高度就是这个平均值。
//如何只显示一张超过div大小的图片的正中间部分
//局限性:图片在页面刚加载的时候,会闪一下,然后才居中
 setTimeout(pic_mid,10);  //页面一开始就执行
var length = $(".carousel img").length;
var i=0;
function pic_mid(){
    $(".carousel img").each(
    function(){   
        var height = $(this).height();
        var pa_height = $(this).parent().parent().height();       
        var delta_height = height - pa_height;   
        //alert(height  + " " +  pa_height);            
         var rate = delta_height/2;           
        $(this).css({position:"absolute",top:"-"+rate+"px"});       
         if(i<=length - 1){   
            //alert(i);   
             timer = setInterval(pic_mid,1000);               
            }else{               
                clearInterval(timer);               
            }
            i++;   
            }
    );
}   
//详情页 点赞 数量加1,再点 取消赞,减一 zan_count
var flag = true ;
$(document).on("click",".zan_count",function(){
    var zan_count = $(this).text();
    if(flag){
        zan_count ++;
        $(this).css("color","#66c5f8");
        flag = false;
    }else{
        zan_count --;
        flag = true;
        $(this).css("color","#555");
    }
    $(this).text(zan_count);
});
 
//详情页 楼层数量增加
function floorFunc(){
var floor_num  = $(".lists  ul").length;
for(var i = 0;i<=floor_num - 1;i++){
    $(".lists  ul").eq(i).find("span.floor").text(i+1 + "楼");
}
}
//window.onload = floorFunc;
 
//要完整显示,点赞头像个数的计算,多余的隐藏
window.onload = function(){floorFunc();show_num();} ;
function show_num(){   
    //获取.awarp的父元素的总宽度,再减去前面点赞的宽度,再减去more图片的宽度,
    var all_width = $("article li .awrap").parent().width();   
    var count_width = $("article li .count").width();
    var count_left = parseInt($("article li .count").css("margin-left"));       
    //当点赞头像图的个数乘以每个头像所占的宽度,
    var length = $("article li .awrap a").length ;
    var awrap_width = all_width - 30 - count_width - count_left;   
    var img_width = $("article li .awrap a").width();
    var margin_width = $("article li .awrap a").css("margin-left");//5px
    var each_width = img_width+2+ parseInt(margin_width);
    var show_num = awrap_width /each_width;   
    //alert(all_width+" " +"awrap_width = "+awrap_width  +"count_width = " +count_width);
    $("article li .awrap ").width(awrap_width);   
    //要完整显示,点赞头像个数的计算,多余的隐藏
    for (var i =0;i< length;i++){
        if(i < parseInt(show_num)){
            $("article li .awrap a").eq(i).css("display","inline-block");
        }else{
            $("article li .awrap a").eq(i).css("display","none");
        }
    }
    //是否显示更多(...)图片
    if(parseInt(show_num) < length){
        $("article li .more").css("display","inline-block");
 
    }else{
        $("article li .more").css("display","none");
    }
    // 图片的等比例高度显示
    var a_width = $(".pic2 a").css("width");
    var a_height = $(".pic2 a").css("height");
    var new_height = 1.1*parseInt(a_width);
    //alert(width +' '+a_width+ ' ' +new_height);
    $(".pic2 a").css("height",new_height);
}
 
//点击详情页的评论,显示评论和举报,再点击隐藏
var flag= true;
$(".open").on("click",function(){
    if(flag == true){
        $(this).find("p").css("display","block");
        flag = false;
    }else{
        $(this).find("p").css("display","none");
        flag = true;
    }
 
 
});

转载于:https://www.cnblogs.com/shuxin6009/p/5889030.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值