0

0

右侧带索引通讯录实现(附代码)

php中世界最好的语言

php中世界最好的语言

发布时间:2018-04-28 11:35:56

|

1867人浏览过

|

来源于php中文网

原创

这次给大家带来右侧带索引通讯录实现(附代码),右侧带索引通讯录实现的注意事项有哪些,下面就是实战案例,一起来看一下。

通过jquery.charfirst.pinyin.js实现点击字母自动定位。实现动态加载通讯录数据。

主要代码如下:




  
  
  
  
  
  
  通讯录首字母检索
  


  

通讯录

张三

李四

王五

刘六

马七

黄八

莫九

陈十

a九

1十

黄八

今天

突然

梵蒂冈

快乐的

撒地方

官方

分割

  • 右侧带索引通讯录实现(附代码)

style.css

html,body,p,ul,li,ol,a,input,textarea,p,dl,dt,dd{margin:0;padding:0;}
ul li{list-style: none;}
a{text-decoration: none;cursor: pointer;}
html{height: 100%;}
body{height: 100%;background: #f5f5f5;position: relative;font-family: '微软雅黑';max-width: 640px;margin:auto;}
a,input,img,textarea,span,p{outline: 0;-webkit-tap-highlight-color:rgba(255,0,0,0);}
header{
  width:100%;
  height: 45px;
  background: #ececea;
  border-bottom: 1px solid #ddd;
}
header.fixed{
  position: fixed;
  left: 0;
  top: 0;
  z-index: 99;
}
.header{
  margin:0 20px;
  text-align: center;
  color: #4e4a49;
  font-size: 1em;
  height: 45px;
  line-height: 45px;
  position: relative;
}
#letter{
  width: 100px;
  height: 100px;
  border-radius: 5px;
  font-size: 75px;
  color: #555;
  text-align: center;
  line-height: 100px;
  background: rgba(145,145,145,0.6);
  position: fixed;
  left: 50%;
  top: 50%;
  margin:-50px 0px 0px -50px;
  z-index: 99;
  display: none;
}
#letter img{
  width: 50px;
  height: 50px;
  float: left;
  margin:25px 0px 0px 25px;
}
.sort_box{
  width: 100%;
  padding-top: 45px;
  overflow: hidden;
}
.sort_list{
  padding:10px 60px 10px 80px;
  position: relative;
  height: 40px;
  line-height: 40px;
  border-bottom:1px solid #ddd;
}
.sort_list .num_logo{
  width: 50px;
  height: 50px;
  border-radius: 10px;
  overflow: hidden;
  position: absolute;
  top: 5px;
  left: 20px;
}
.sort_list .num_logo img{
  width: 50px;
  height: 50px;
}
.sort_list .num_name{
  color: #000;
}
.sort_letter{
  background-color: white;
  height: 30px;
  line-height: 30px;
  padding-left: 20px;
  color:#787878;
  font-size: 14px;
  border-bottom:1px solid #ddd;
}
.initials{
  position: fixed;
  top: 47px;
  right: 0px;
  height: 100%;
  width: 15px;
  padding-right: 10px;
  text-align: center;
  font-size: 12px;
  z-index: 99;
  background: rgba(145,145,145,0);
}
.initials li img{
  width: 14px;
}

sort.js

$(function(){
    var Initials=$('.initials');
    var LetterBox=$('#letter');
    Initials.find('ul').append('
  • A
  • B
  • C
  • D
  • E
  • F
  • G
  • H
  • I
  • J
  • K
  • L
  • M
  • N
  • O
  • P
  • Q
  • R
  • S
  • T
  • U
  • V
  • W
  • X
  • Y
  • Z
  • #
  • '); initials(); $(".initials ul li").click(function(){ var _this=$(this); var LetterHtml=_this.html(); LetterBox.html(LetterHtml).fadeIn(); Initials.css('background','rgba(145,145,145,0.6)'); setTimeout(function(){ Initials.css('background','rgba(145,145,145,0)'); LetterBox.fadeOut(); },1000); var _index = _this.index() if(_index==0){ $('html,body').animate({scrollTop: '0px'}, 300);//点击第一个滚到顶部 }else if(_index==27){ var DefaultTop=$('#default').position().top; $('html,body').animate({scrollTop: DefaultTop+'px'}, 300);//点击最后一个滚到#号 }else{ var letter = _this.text(); if($('#'+letter).length>0){ var LetterTop = $('#'+letter).position().top; $('html,body').animate({scrollTop: LetterTop-45+'px'}, 300); } } }) var windowHeight=$(window).height(); var InitHeight=windowHeight-45; Initials.height(InitHeight); var LiHeight=InitHeight/28; Initials.find('li').height(LiHeight); }) function initials() {//排序 var SortList=$(".sort_list"); var SortBox=$(".sort_box"); SortList.sort(asc_sort).appendTo('.sort_box');//按首字母排序 function asc_sort(a, b) { return makePy($(b).find('.num_name').text().charAt(0))[0].toUpperCase() < makePy($(a).find('.num_name').text().charAt(0))[0].toUpperCase() ? 1 : -1; } var initials = []; var num=0; SortList.each(function(i) { var initial = makePy($(this).find('.num_name').text().charAt(0))[0].toUpperCase(); if(initial>='A'&&initial<='Z'){ if (initials.indexOf(initial) === -1) initials.push(initial); }else{ num++; } }); $.each(initials, function(index, value) {//添加首字母标签 SortBox.append('

    ' + value + '

    '); }); if(num!=0){SortBox.append('

    #

    ');} for (var i =0;i

    最终效果:

    相信看了本文案例你已经掌握了方法,更多精彩请关注php中文网其它相关文章!

    推荐阅读:

    Endel.io
    Endel.io

    Endel是一款可以创造个性化舒缓声音的应用程序,可帮助您集中注意力、放松身心和入睡。

    下载

    分享页面后跳转回首页

    Vue自定义动态组件使用详解

    相关专题

    更多
    vlookup函数使用大全
    vlookup函数使用大全

    本专题整合了vlookup函数相关 教程,阅读专题下面的文章了解更多详细内容。

    26

    2025.12.30

    金山文档相关教程
    金山文档相关教程

    本专题整合了金山文档相关教程,阅读专题下面的文章了解更多详细操作。

    28

    2025.12.30

    PS反选快捷键
    PS反选快捷键

    本专题整合了ps反选快捷键介绍,阅读下面的文章找到答案。

    25

    2025.12.30

    表格中一行两行的方法
    表格中一行两行的方法

    本专题整合了表格中一行两行的相关教程,阅读专题下面的文章了解更多详细内容。

    3

    2025.12.30

    cpu温度过高解决方法大全
    cpu温度过高解决方法大全

    本专题整合了cpu温度过高相关教程,阅读专题下面的文章了解更多详细内容。

    5

    2025.12.30

    ASCII码介绍
    ASCII码介绍

    本专题整合了ASCII码相关内容,阅读专题下面的文章了解更多详细内容。

    31

    2025.12.30

    GPS是什么
    GPS是什么

    本专题整合了GPS相关内容,阅读专题下面的文章了解更多详细内容。

    3

    2025.12.30

    wifi拒绝接入
    wifi拒绝接入

    本专题整合了wifi拒绝接入相关教程,阅读下面的文章了解更多详细方法。

    9

    2025.12.30

    丰网速运介绍
    丰网速运介绍

    本专题整合了丰网速运查询入口以及相关内容,阅读专题下面的文章了解更多内容。

    3

    2025.12.30

    热门下载

    更多
    网站特效
    /
    网站源码
    /
    网站素材
    /
    前端模板

    精品课程

    更多
    相关推荐
    /
    热门推荐
    /
    最新课程
    【李炎恢】ThinkPHP8.x 后端框架课程
    【李炎恢】ThinkPHP8.x 后端框架课程

    共50课时 | 4.3万人学习

    Golang进阶实战编程
    Golang进阶实战编程

    共34课时 | 2.6万人学习

    关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
    php中文网:公益在线php培训,帮助PHP学习者快速成长!
    关注服务号 技术交流群
    PHP中文网订阅号
    每天精选资源文章推送

    Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号