Welcom to 评论 - lizhenqiu blog!
#1084
#1085
#1086
#1087
语法:writing-mode : lr-tb、tb-rl 参数:lr-tb:从左向右,从上往下 tb-rl:从上往下,从右向左 示例:div { writing-mode: tb-rl; }
语法:text-align : left、right、center、justify 参数:left:左对齐 right:右对齐 center:居中 justify:两端对齐 示例:div { text-align : center; }
<style>.div { writing-mode: tb-rl; } </style> <div class="div">fdsafasdfads设置css文字居中</div>
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>竖列排版实例 在线演示 www.divcss5.com</title> <style> body{width: 20px;text-align:center; line-height:22px} /* CSS注释说明:设置css文字居中,css行高为22px间隔 */ </style> </head> <body> 我<br>是<br>竖<br>列<br>排<br>版 </body> </html>
<ul> <li>文字</li> <li>文字</li> <li>文字</li> </ul>
#1088
#1089
/** * 短链接功能 * * @param float $long_url * 长链接 * @return string 如果没有微信短链接接口权限或者不成功,就原样返回长链接,否则返回短链接 */ function short_url($long_url)
//处理头像 function get_name_by_touxiang($val) { if(!empty($val)){ return('<img height="48px" src="'.$val.'" />'); }else{ return('<img height="48px" src="'.ADDON_PUBLIC_PATH.'/face.png" />'); } } // 拉取10000个用户列表,通过openid获取微信用户基本信息,此功能只有认证的服务号才能用 function getWeixinUserAllInfo($token) { $access_token = get_access_token ( $token ); if (empty ( $access_token )) { return false; } $param ['access_token'] = $access_token; $url = 'https://api.weixin.qq.com/cgi-bin/user/get?'. http_build_query ( $param ); $content = file_get_contents ( $url ); $content = json_decode ( $content, true ); return $content; }
<?php namespace Common\Model; use Think\Model; use User\Api\UserApi; /** * 粉丝操作 */ class FollowModel extends Model { function init_follow($openid) { if (empty ( $openid ) || $openid == - 1) return false; $data ['token'] = get_token (); $data ['openid'] = $openid; $winfo = getWeixinUserInfo ($openid, $data ['token']); //获取用户所有信息 $info = $this->where ( $data )->find (); if ($info) { $save ['subscribe_time'] = $winfo ['subscribe_time']; $save ['nickname'] = $winfo ['nickname']; $save ['sex'] = $winfo ['sex']; $save ['city'] = $winfo ['city']; $save ['province'] = $winfo ['province']; $save ['country'] = $winfo ['country']; $save ['headimgurl'] = $winfo ['headimgurl']; $res = $this->where ( $data )->save ( $save ); } else { // $data ['subscribe_time'] = time (); // $uid = $this->get_uid_by_ucenter ( $data ['openid'], $data ['token'] ); //if ($uid > 0) { // $data ['id'] = $uid; $data ['subscribe_time'] = $winfo ['subscribe_time']; $data ['nickname'] = $winfo ['nickname']; $data ['sex'] = $winfo ['sex']; $data ['city'] = $winfo ['city']; $data ['province'] = $winfo ['province']; $data ['country'] = $winfo ['country']; $data ['headimgurl'] = $winfo ['headimgurl']; $res = $this->add ( $data ); //} $info = $data; } return $info; } //处理头像 function get_name_by_touxiang($val) { if(!empty($val)){ return('<img height="48px" src="'.$val.'" />'); }else{ return('<img height="48px" src="'.ADDON_PUBLIC_PATH.'/face.png" />'); } } // 自动初始化微信用户 function get_uid_by_ucenter($openid, $token) { static $_email_int = 0; $info ['openid'] = $openid; $info ['token'] = $token; $res = M ( 'ucenter_member' )->where ( $info )->find (); if ($res) return $res ['id']; $email = time () . rand ( 01, 99 ) . $_email_int . '@weiphp.cn'; $nickname = uniqid () . rand ( 01, 99 ) . $_email_int; /* 调用注册接口注册用户 */ $User = new UserApi (); $uid = $User->register ( $nickname, '123456', $email, '', $openid, $token ); $_email_int += 1; return $uid; } /** * 获取粉丝全部信息 */ public function getFollowInfo($id) { static $_followInfo; if (isset ( $_followInfo [$id] )) { return $_followInfo [$id]; } $_followInfo [$id] = $this->find ( $id ); return $_followInfo [$id]; } } ?>
id:粉丝编号 openid:OpenId headimgurl|get_name_by_touxiang:头像 nickname:昵称 sex|get_name_by_status:性别 province:省份 city:城市 subscribe_time|time_format:关注时间 ids:操作:[EDIT]|编辑
#1090
if(preg_match("/第[0-9一二两三四五六七八九十百千万]*[章节]/i",$hangdata,$matches)){ }
if(preg_match("/(\x{7b2c})(\s*)([\x{4e00}\x{4e8c}\x{4e09}\x{56db}\x{4e94}\x{516d}\x{4e03}\x{516b}\x{4e5d}\x{5341}\x{767e}\x{5343}0-9]+)(\s*)([\x{7ae0}\x{8282}]+)/u",$hangdata,$matches)){ }
$hangdata=mb_convert_encoding($hangdata,"UTF-8","GBK");
#1091
$conn =file_get_contents('2.txt'); //读取内容 $conn=mb_convert_encoding($conn,"UTF-8","GBK");//设置不乱码 $arr = explode('#',$conn);用#号把标题扩起来分割,('#'也可以用其它的代替) $result = array(); for($i = 1; $i < count($arr); $i++){ //循环数组,达到小说章节做为键,章节内容做为值 $result[$arr[$i]] = $arr[$i+1]; $i ++; } $k1 = array(); $v1 = array(); foreach ($result as $key => $v) { $k1[] = $key; $v1[] = $v; } //var_dump($k1); //var_dump($v1); //不懂得小伙伴可以打印一下,,也可以私聊我>
#1092
// 自动同步微信用户 C ( 'USER_LIST' ) && $this->_autoUpdateUser (); C ( 'USER_GROUP' ) && $this->_updateWechatGroup ();
function _autoUpdateUser
#1093
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <style type="text/css"> *{margin:0; padding:0;} .father{ width:100%; height: 300px; background: pink; text-align: center; line-height:300px; } .father li{ border:1px solid red; display: inline-block; _display:inline; } </style> </head> <body> <ul class="father"> <Li>1</Li> <li>2</li> <Li>1</Li> <li>2</li> <Li>1</Li> <li>2</li> </ul> </body> </html>
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <style type="text/css"> .big{ width:500px; height:500px; background: pink; text-align: center; display: table; _position: relative; } .small{ display: table-cell; vertical-align: middle; _position:absolute; _top:50%; _left:50%; } .content{ } </style> </head> <body> <div class="big"> <div class="small"> <div class="content"> 范德萨 </div> </div> </div> </body> </html>
<!--盒子自动居中 类 middlesjs 加最后--> <style> .middlesjs{width:auto;display: inline-block;}</style> <script> //自动居中 $(document).ready(function(){ $(".middlesjs").each(function(){ var nw=$(this).width(); $(this).css({'left':'50%','margin-left':'-'+(nw/2)+'px','position':'relative'}); }); }); </script> <!--end-->
<div class="bt1 middlesjs">
#1094
<img src="planets.jpg" border="0" usemap="#planetmap" alt="Planets" /> <map name="planetmap" id="planetmap"> <area shape="circle" coords="180,139,14" href ="venus.html" alt="Venus" /> <area shape="circle" coords="129,161,10" href ="mercur.html" alt="Mercury" /> <area shape="rect" coords="0,0,110,260" href ="sun.html" alt="Sun" /> </map>
#1095
#1096
<h1 id="technique-one"> <a href="#">w3cplus</a> </h1>
#technique-one { width: 329px; height: 79px; background-image: url(images/w3cplus-logo.png); } #technique-one a { display: none; }
<h1 class="technique-two">w3cplus</h1>
.technique-two { width: 2329px; height: 79px; background: url(images/w3cplus-logo.png) no-repeat top right; margin: 0 0 0 -2000px; }
<h1 class="technique-three">w3cplus</h1>
.technique-three { width: 329px; height: 79px; background: url(images/w3cplus-logo.png); text-indent: -9999px; }
<h1 class="technique-four"> <a href="#"> <img src="images/w3cplus-logo.png" alt="w3cplus" /> </a> </h1>
.technique-four { width: 329px; height: 79px; background: url(images/w3cplus-logo.png); text-indent: -9999px; }
<h1 class="technique-five"> <img src="images/blank.gif" alt="w3cplus" /> <span>w3cplus</span> </h1>
.technique-five { width: 329px; height: 79px; background: url(images/w3cplus-logo.png); } .technique-five span { display: none; }
<h1 class="technique-six">w3cplus</h1>
.technique-six { width: 329px; padding: 79px 0 0 0; height: 0px; font-size: 0; background: url(images/w3cplus-logo.png); overflow: hidden; }
<h1 class="technique-seven"> <span>w3cplus</span> </h1>
.technique-seven { width: 329px; height: 79px; background: url(images/w3cplus-logo.png); } .technique-seven span { display: block; width: 0; height: 0; font-size: 0; overflow: hidden; }
<h1 class="technique-eight"> <span></span>w3cplus </h1>
.technique-eight { width: 329px; height: 79px; position: relative; } .technique-eight span { background: url(images/w3cplus-logo.png); position: absolute; width: 100%; height: 100%; }
<h1 class="technique-nine">w3cplus</h1>
.technique-nine { width: 329px; height: 79px; background: url(images/w3cplus-logo.png); font-size: 1px; color: white; }
<h1 class="technique-ten"><span>w3cplus</span></h1>
.technique-ten { width: 329px; height: 79px; background: url(images/w3cplus-logo.png); } .technique-ten span { border: 0 !important; clip: rect(1px 1px 1px 1px); clip: rect(1px,1px,1px,1px); height: 1px !important; margin: -1px; overflow: hidden; padding: 0 !important; position: absolute !important; width: 1px; }
.hidden-text { text-indent: 100%; white-space: nowrap; overflow: hidden; }
<a class="ir" id="logo" href="http://www.w3cplus.com">W3cplus</a>
#logo { background-image: url(http://www.w3cplus.com/sites/all/themes/w3cplusResponsive/logo.png); width: 125px; height: 115px; display: block; /*下面是关键代码*/ background-color: transparent; border: 0; overflow: hidden; /* IE 6/7 fallback */ *text-indent: -9999px; } #logo:before { content: ""; display: block; width: 0; height: 150%; }
.ir { background-color: transparent; border: 0; overflow: hidden; /* IE 6/7 fallback */ *text-indent: -9999px; } .ir:before { content: ""; display: block; width: 0; height: 150%; }
#1097
touchstart touchmove touchend click{mousedown->mousemove->mouseup}
var handle = function (e) { e.preventDefault(); // 阻止浏览器默认行为 alert('fuck world'); } $('body').on(‘touchstart mousedown’, handle );
;(function(){ var isTouch = ('ontouchstart' in document.documentElement) ? 'touchstart' : 'click'; if(!$.fn.quickOn){ $.fn.quickOn= function(){ arguments[0] = (arguments[0] === 'click') ? isTouch: arguments[0]; return $.fn.on.apply(this, arguments); }; } })();
$('body').quickOn('click', function(){ alert('fuck world') ; })
;(function(){ var isTouch = ('ontouchstart' in document.documentElement) ? 'touchstart' : 'click', _on = $.fn.on; $.fn.on = function(){ arguments[0] = (arguments[0] === 'click') ? isTouch: arguments[0]; return _on.apply(this, arguments); }; })();
#1098
<style> .next_button{ cursor:pointer } </style> <div class="button"> <div class=" next_button button_left btn_red" style="width: 345px;"> 下一步 </div> </div> <script> $(document).on("click",".next_button",function(){ alert(); }); </script>
$(document).on("click",function(){})
cursor: pointer
selector { cursor:pointer }
#1099
<script> $(selector).click(function(){console.log(‘1111‘)}) </script>
#1100
<script> $(document).on("touchstart",function(){console.log(‘22222‘)}) </script>
#1101
window.addEventListener("orientationchange", function() { // 宣布新方向的数值 alert(window.orientation); }, false);
window.addEventListener("resize", function() { // 得到屏幕尺寸 (内部/外部宽度,内部/外部高度) }, false);
@media screen and (orientation:portrait) { /* portrait-specific styles */ } /* landscape */ @media screen and (orientation:landscape) { /* landscape-specific styles */ }
var mql = window.matchMedia("(orientation: portrait)"); // 如果有匹配,则我们处于垂直视角 if(mql.matches) { // 直立方向 alert("1") } else { //水平方向 alert("2") } // 添加一个媒体查询改变监听者 mql.addListener(function(m) { if(m.matches) { // 改变到直立方向 document.getElementById("test").innerHTML="改变到直立方向"; } else { document.getElementById("test").innerHTML="改变到水平方向"; // 改变到水平方向 } });
#1102
$(window).resize(function() { var width = $(this).width(); var height = $(this).height(); });
确定要清除编辑框内容吗?
该删除操作将不可恢复。
删除 取消
激活Windows
转到"设置"以激活Windows。
#1084
#1085
#1086
#1087
1. writing-mode(设置对象书写方向)
语法:writing-mode : lr-tb、tb-rl 参数:lr-tb:从左向右,从上往下 tb-rl:从上往下,从右向左 示例:div { writing-mode: tb-rl; }
2. text-align(设置对象中文本的对齐方式)
语法:text-align : left、right、center、justify 参数:left:左对齐 right:右对齐 center:居中 justify:两端对齐 示例:div { text-align : center; }
示例代码
<style>.div { writing-mode: tb-rl; } </style> <div class="div">fdsafasdfads设置css文字居中</div>
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>竖列排版实例 在线演示 www.divcss5.com</title> <style> body{width: 20px;text-align:center; line-height:22px} /* CSS注释说明:设置css文字居中,css行高为22px间隔 */ </style> </head> <body> 我<br>是<br>竖<br>列<br>排<br>版 </body> </html>
<ul> <li>文字</li> <li>文字</li> <li>文字</li> </ul>
#1088
#1089
修改方法:
1.下载附件覆盖插件UserCenter(附件会替换所有文件,有做过修改的记得备份修改)
2.修改/Application/Common/Common/function.PHP找到
/** * 短链接功能 * * @param float $long_url * 长链接 * @return string 如果没有微信短链接接口权限或者不成功,就原样返回长链接,否则返回短链接 */ function short_url($long_url)
在这段代码之上增加以下代码
//处理头像 function get_name_by_touxiang($val) { if(!empty($val)){ return('<img height="48px" src="'.$val.'" />'); }else{ return('<img height="48px" src="'.ADDON_PUBLIC_PATH.'/face.png" />'); } } // 拉取10000个用户列表,通过openid获取微信用户基本信息,此功能只有认证的服务号才能用 function getWeixinUserAllInfo($token) { $access_token = get_access_token ( $token ); if (empty ( $access_token )) { return false; } $param ['access_token'] = $access_token; $url = 'https://api.weixin.qq.com/cgi-bin/user/get?'. http_build_query ( $param ); $content = file_get_contents ( $url ); $content = json_decode ( $content, true ); return $content; }
3.修改/Application/Common/Model/FollowModel.class.php
<?php namespace Common\Model; use Think\Model; use User\Api\UserApi; /** * 粉丝操作 */ class FollowModel extends Model { function init_follow($openid) { if (empty ( $openid ) || $openid == - 1) return false; $data ['token'] = get_token (); $data ['openid'] = $openid; $winfo = getWeixinUserInfo ($openid, $data ['token']); //获取用户所有信息 $info = $this->where ( $data )->find (); if ($info) { $save ['subscribe_time'] = $winfo ['subscribe_time']; $save ['nickname'] = $winfo ['nickname']; $save ['sex'] = $winfo ['sex']; $save ['city'] = $winfo ['city']; $save ['province'] = $winfo ['province']; $save ['country'] = $winfo ['country']; $save ['headimgurl'] = $winfo ['headimgurl']; $res = $this->where ( $data )->save ( $save ); } else { // $data ['subscribe_time'] = time (); // $uid = $this->get_uid_by_ucenter ( $data ['openid'], $data ['token'] ); //if ($uid > 0) { // $data ['id'] = $uid; $data ['subscribe_time'] = $winfo ['subscribe_time']; $data ['nickname'] = $winfo ['nickname']; $data ['sex'] = $winfo ['sex']; $data ['city'] = $winfo ['city']; $data ['province'] = $winfo ['province']; $data ['country'] = $winfo ['country']; $data ['headimgurl'] = $winfo ['headimgurl']; $res = $this->add ( $data ); //} $info = $data; } return $info; } //处理头像 function get_name_by_touxiang($val) { if(!empty($val)){ return('<img height="48px" src="'.$val.'" />'); }else{ return('<img height="48px" src="'.ADDON_PUBLIC_PATH.'/face.png" />'); } } // 自动初始化微信用户 function get_uid_by_ucenter($openid, $token) { static $_email_int = 0; $info ['openid'] = $openid; $info ['token'] = $token; $res = M ( 'ucenter_member' )->where ( $info )->find (); if ($res) return $res ['id']; $email = time () . rand ( 01, 99 ) . $_email_int . '@weiphp.cn'; $nickname = uniqid () . rand ( 01, 99 ) . $_email_int; /* 调用注册接口注册用户 */ $User = new UserApi (); $uid = $User->register ( $nickname, '123456', $email, '', $openid, $token ); $_email_int += 1; return $uid; } /** * 获取粉丝全部信息 */ public function getFollowInfo($id) { static $_followInfo; if (isset ( $_followInfo [$id] )) { return $_followInfo [$id]; } $_followInfo [$id] = $this->find ( $id ); return $_followInfo [$id]; } } ?>
4.进入后台,模型管理-粉丝管理-编辑,把列表定义改成:
id:粉丝编号 openid:OpenId headimgurl|get_name_by_touxiang:头像 nickname:昵称 sex|get_name_by_status:性别 province:省份 city:城市 subscribe_time|time_format:关注时间 ids:操作:[EDIT]|编辑
5.进入前台,基础插件-微信用户中心-拉取10000个已有粉丝,搞定
#1090
最近在做一个自动分割txt小说的东西,能够将一整个txt文件按照章节进行分割,然后分解成一个个小的.txt文件保存起来并且能够获取有多少章节和每章的章节名。
我最初的想法是:
① 先使用fopen打开文件,然后while循环使用fgets函数按txt文件中每一行读取
② 边读取 边使用正则匹配出是否在这一句话中含有 “第**章”或者是“第**节”的字符串。如果有的话就把它存到一个数组中去。
③ 全部循环完成后使用count来计算数组的大小,然后使用foreach循环数组,将每一章的章节名进行字符串拼接(比如拼接成 '#章节名#' 这样的形式存到数据库中便于以后使用explode等函数进行章节名的分割)。
然后我就按照这个思路开始敲代码了。。但是很快便遇到了第一个问题
---- 如何使用正则表达式来匹配中文!!!
之前一直都是使用正则表达式来匹配一些英文啊字符啊什么的,我也一直以来都以为正则表达式可以直接匹配汉字的,于是就写了下面这样的代码
if(preg_match("/第[0-9一二两三四五六七八九十百千万]*[章节]/i",$hangdata,$matches)){ }
我真的是把这个想的太容易了一点。。。结果就是什么也没有匹配出来。。
很多时候遇到问题第一想法就是不可能!!!然后就用把这行简单的代码看了一下,却没有发现有什么问题啊。。于是便开始百度,不得不说百度真的有很多有用的东西,很快便找到了网友共享的匹配中文字符的内容,要把汉字改成Unicode编码形式再去匹配。。。下面则是修改之后的代码
if(preg_match("/(\x{7b2c})(\s*)([\x{4e00}\x{4e8c}\x{4e09}\x{56db}\x{4e94}\x{516d}\x{4e03}\x{516b}\x{4e5d}\x{5341}\x{767e}\x{5343}0-9]+)(\s*)([\x{7ae0}\x{8282}]+)/u",$hangdata,$matches)){ }
我想这次应该是没有问题了吧~正高兴着刷新了一下网页。。。我去 怎么又没出来东西。。是不是网友的贡献出错了?于是仔细检查了一边却还是没发现有什么问题,于是网上找个一个php在线中文手册看了一下,原来使用preg_match匹配中文要求被匹配的内容是UTF-8编码。。而从txt中读取出来的一般是GBK编码的
于是又在前面加了一行字符转换代码
$hangdata=mb_convert_encoding($hangdata,"UTF-8","GBK");
现在一运行~OK 完成了
但是就在滚动页面的时候却发现同一个章节的名字却被匹配出来两次甚至更多。。这个错误很严重啊,之前人家作者写了一章的内容,用这个一分变成好多章了。。
于是就在匹配出每一章的章节名的时候和距离他最近的读取出来的章节名进行对比,看是不是一样。
于是就在最开始定义了一个空的字符串变量
每次循环的时候都与当前章节名进行对比 如果一样,就不再把当前的这一个章节名记录下来,如果不一样就记录下了并把章节名赋给这个变量。
虽然还有一点不尽人意的地方,但是主要的功能基本都已经实现了
#1091
$conn =file_get_contents('2.txt'); //读取内容 $conn=mb_convert_encoding($conn,"UTF-8","GBK");//设置不乱码 $arr = explode('#',$conn);用#号把标题扩起来分割,('#'也可以用其它的代替) $result = array(); for($i = 1; $i < count($arr); $i++){ //循环数组,达到小说章节做为键,章节内容做为值 $result[$arr[$i]] = $arr[$i+1]; $i ++; } $k1 = array(); $v1 = array(); foreach ($result as $key => $v) { $k1[] = $key; $v1[] = $v; } //var_dump($k1); //var_dump($v1); //不懂得小伙伴可以打印一下,,也可以私聊我>
#1092
// 自动同步微信用户 C ( 'USER_LIST' ) && $this->_autoUpdateUser (); C ( 'USER_GROUP' ) && $this->_updateWechatGroup ();
function _autoUpdateUser
#1093
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <style type="text/css"> *{margin:0; padding:0;} .father{ width:100%; height: 300px; background: pink; text-align: center; line-height:300px; } .father li{ border:1px solid red; display: inline-block; _display:inline; } </style> </head> <body> <ul class="father"> <Li>1</Li> <li>2</li> <Li>1</Li> <li>2</li> <Li>1</Li> <li>2</li> </ul> </body> </html>
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <style type="text/css"> .big{ width:500px; height:500px; background: pink; text-align: center; display: table; _position: relative; } .small{ display: table-cell; vertical-align: middle; _position:absolute; _top:50%; _left:50%; } .content{ } </style> </head> <body> <div class="big"> <div class="small"> <div class="content"> 范德萨 </div> </div> </div> </body> </html>
<!--盒子自动居中 类 middlesjs 加最后--> <style> .middlesjs{width:auto;display: inline-block;}</style> <script> //自动居中 $(document).ready(function(){ $(".middlesjs").each(function(){ var nw=$(this).width(); $(this).css({'left':'50%','margin-left':'-'+(nw/2)+'px','position':'relative'}); }); }); </script> <!--end-->
<div class="bt1 middlesjs">
#1094
实例
带有可点击区域的图像映射:
<img src="planets.jpg" border="0" usemap="#planetmap" alt="Planets" /> <map name="planetmap" id="planetmap"> <area shape="circle" coords="180,139,14" href ="venus.html" alt="Venus" /> <area shape="circle" coords="129,161,10" href ="mercur.html" alt="Mercury" /> <area shape="rect" coords="0,0,110,260" href ="sun.html" alt="Sun" /> </map>
#1095
#1096
很多网站的logo都使用图片替换文本来实现,而且在一些情况下也有使用图片效果来替换难以实现的文本效果。这些制作我想大家在平时制作中都或多或少的碰到过,那么今天我老话重谈,整理了十种图片替换文本的制作方法。希望对大家有所帮助。
制作原理:
使用图片替换文本,其原理是相当的简单:就是在样式中使用背景图片来替换掉HTML模板中的文本内容,从而达到一种样式无法实现的页面渲染效果。使用图片替换有其优点也有其缺点,优点就是能实现一些特殊的页面效果,缺点就是需要加载图片,而且一些不好的替换方法给残障人员浏览网页会造成一定的不良之处,另外据说会对搜索引擎的搜索有影响,对于这一点没有考究过。那么我们也不去控寻这方面的问题,我们一起来看今天所要说的图片替换文本的制作方法。
方法一:
HTML Markup
<h1 id="technique-one"> <a href="#">w3cplus</a> </h1>
CSS Code:
#technique-one { width: 329px; height: 79px; background-image: url(images/w3cplus-logo.png); } #technique-one a { display: none; }
这种方法被称为“FIR”方法, Joe Clark在《Facts and Opinion About Fahrner Image Replacement》一文中有做深入的介绍。使用这种方法需要注意两点:
结构性需要增加一个标签包裹文本;如上面的HTML Markup所示;
需要把背景图设置在外标签上,并且将文本外标签隐藏。
这种方法有一个不好的地方就是不利于阅读器浏览网页。
方法二:
HTML Markup
<h1 class="technique-two">w3cplus</h1>
CSS Code
.technique-two { width: 2329px; height: 79px; background: url(images/w3cplus-logo.png) no-repeat top right; margin: 0 0 0 -2000px; }
这种方法是Radu Darvas创建的,使用负margin配合宽度来制作。如果运用在简单之处,此方法可行,但对于复杂的布局中,大家还需慎用。因为其有可能会影响你的页面布局。
方法三:
HTML Markup
<h1 class="technique-three">w3cplus</h1>
CSS Code
.technique-three { width: 329px; height: 79px; background: url(images/w3cplus-logo.png); text-indent: -9999px; }
这种方法是由Mike Rundle创建,并且简称为Phark方法,也是目前使用图片替换文本常和的方法。这种方法简单易懂而且支持阅读器之类浏览网页。其关键之处使用“text-indent属性,并且给其设置一个较大的负值,达到隐藏文本的效果,”如果你想了解的更深可以参考一下Malarkey Image Replacement (MIR)。
方法四:
HTML Markup
<h1 class="technique-four"> <a href="#"> <img src="images/w3cplus-logo.png" alt="w3cplus" /> </a> </h1>
CSS Code
.technique-four { width: 329px; height: 79px; background: url(images/w3cplus-logo.png); text-indent: -9999px; }
这种方法,我不知道来自源于何处,也不知道其有什么优势之处,可以说他和方法三没有多大的区别,只是上面的替换的是文本,下面是替换的图片而以。这样使用我至今没有整明白是为什么?不知道是不是和SEO方面有关系。无从考究,先放上来给大家参考一下。
方法五:
HTML Markup
<h1 class="technique-five"> <img src="images/blank.gif" alt="w3cplus" /> <span>w3cplus</span> </h1>
CSS Code
.technique-five { width: 329px; height: 79px; background: url(images/w3cplus-logo.png); } .technique-five span { display: none; }
这种方法有一个特别之处我们此处使用一个透明的gif图片,通过在img标签中的“alt”属性来弥补display:none。这样阅读器之类的就能阅读到所替换的文本是什么。
方法六:
HTML Markup
<h1 class="technique-six">w3cplus</h1>
CSS Code
.technique-six { width: 329px; padding: 79px 0 0 0; height: 0px; font-size: 0; background: url(images/w3cplus-logo.png); overflow: hidden; }
这种方法是由Seamus Leahy和Stuart Langridge发明。使用零高度来隐藏文本,但为了显示背景图片,需要设置一个与替换图片一样的大小的padding值。
方法七:
HTML Markup
<h1 class="technique-seven"> <span>w3cplus</span> </h1>
CSS Code
.technique-seven { width: 329px; height: 79px; background: url(images/w3cplus-logo.png); } .technique-seven span { display: block; width: 0; height: 0; font-size: 0; overflow: hidden; }
Leon Dwyer想出的这种方法,通过把span的大小都设置为“0”,来达到隐藏文本效果,这样阅读器就能完全阅读到,而且又达到了图片替换文本的效果。真是好方法。
方法八:
HTML Markup
<h1 class="technique-eight"> <span></span>w3cplus </h1>
CSS Code
.technique-eight { width: 329px; height: 79px; position: relative; } .technique-eight span { background: url(images/w3cplus-logo.png); position: absolute; width: 100%; height: 100%; }
Levin Alexander。这种方法在利用一个空白的span标签来放置背景图片,并对其进行绝对定位,使用覆盖文本,达到隐藏替换文本的效果。
方法九:
HTML Markup
<h1 class="technique-nine">w3cplus</h1>
CSS Code
.technique-nine { width: 329px; height: 79px; background: url(images/w3cplus-logo.png); font-size: 1px; color: white; }
Levin Alexander写的这种方法很独特,设置字体为微小值,但这里需要注意一点不能忘了设置字体色和替换图片色一样,不然会有一个小点显示出来。
方法十:
HTML Markup
<h1 class="technique-ten"><span>w3cplus</span></h1>
CSS Code
.technique-ten { width: 329px; height: 79px; background: url(images/w3cplus-logo.png); } .technique-ten span { border: 0 !important; clip: rect(1px 1px 1px 1px); clip: rect(1px,1px,1px,1px); height: 1px !important; margin: -1px; overflow: hidden; padding: 0 !important; position: absolute !important; width: 1px; }
Jonathan Snook使用css的clip属性来实现图片替换文本的效果,详细可以参考Hiding Content for Accessibility。
方法十一
以前是通过text-indent的负值来隐藏文本,但其实还有一种类似的方法:
.hidden-text { text-indent: 100%; white-space: nowrap; overflow: hidden; }
方法十二
今天在整理SASS的Mixin时,打算写一个图片替代文本的效果,让我意外发现一种新的图片替代文本方法,特意动手一试,还真心不错:
<a class="ir" id="logo" href="http://www.w3cplus.com">W3cplus</a>
上面的结构,大家都清楚,就是一个logo的居住地,接下来,我们来看实现代码
#logo { background-image: url(http://www.w3cplus.com/sites/all/themes/w3cplusResponsive/logo.png); width: 125px; height: 115px; display: block; /*下面是关键代码*/ background-color: transparent; border: 0; overflow: hidden; /* IE 6/7 fallback */ *text-indent: -9999px; } #logo:before { content: ""; display: block; width: 0; height: 150%; }
其中把起这个功能作用的代码抽出来,并定义为`ir`
.ir { background-color: transparent; border: 0; overflow: hidden; /* IE 6/7 fallback */ *text-indent: -9999px; } .ir:before { content: ""; display: block; width: 0; height: 150%; }
最终效果,可以猛击:DEMO
转载 W3CPLUS
#1097
因为移动端click事件会比touchstart事件慢几拍
移动设备某个元素上事件执行顺序是:
touchstart touchmove touchend click{mousedown->mousemove->mouseup}
click事件在移动设备上虽然会识别但却是最后一个执行的,所以如果不把click事件换成touchstart事件的话,就可能造成延时导致交互上也慢了几拍
所以在移动端最好把click事件换成touchstart事件。
那么如何添加事件比较简单呢.
于是乎有了以下这种写法:
var handle = function (e) { e.preventDefault(); // 阻止浏览器默认行为 alert('fuck world'); } $('body').on(‘touchstart mousedown’, handle );
这样在pc端浏览器上面alert只执行一次,触发的事件是mousedown
在ios设备safari浏览器上面alert也只执行一次,触发的事件是touchstart
为什么只执行一次?
秘密在于当执行的是touchstart后,preventDefault掉了后面的click就不执行了,“非常完美”.
^_^! 一如既往的android设备蛋疼是必须的,测试发现除qq浏览器外其它浏览器都会alert两次
也就是说touchstart和mousedown的handle函数都执行了, 似乎是e.preventDefault()没有起作用。具体原因不明...
因为要兼容,所以就没办法了只能通过判断是否支持touch事件来分别添加事件了..
那就扩展一个jquery方法插件吧仿一个on方法的插件方法比如名称为quickOn,
;(function(){ var isTouch = ('ontouchstart' in document.documentElement) ? 'touchstart' : 'click'; if(!$.fn.quickOn){ $.fn.quickOn= function(){ arguments[0] = (arguments[0] === 'click') ? isTouch: arguments[0]; return $.fn.on.apply(this, arguments); }; } })();
quickOn虽然名字尴尬了一点,但是能用,例如:
$('body').quickOn('click', function(){ alert('fuck world') ; })
额。。后来想想,为什么不直接重载jquery的on方法呢??
来吧,试试
;(function(){ var isTouch = ('ontouchstart' in document.documentElement) ? 'touchstart' : 'click', _on = $.fn.on; $.fn.on = function(){ arguments[0] = (arguments[0] === 'click') ? isTouch: arguments[0]; return _on.apply(this, arguments); }; })();
这样暴力的来那么一下后,mmm....,on方法还是原来的用法,但如果你on的是click事件,那么在移动平台上会被替换成touchstart以迅速响应操作。
将其转成A标签即可。
$(document).on("click",'.class',function(){……});相当于$('.class').live("click",function(){……});
js生成的元素绑定事件必须使用live,但新版的jq,已经淘汰了live,可以用on方法代替,但必须注意写法。
#1098
<style> .next_button{ cursor:pointer } </style> <div class="button"> <div class=" next_button button_left btn_red" style="width: 345px;"> 下一步 </div> </div> <script> $(document).on("click",".next_button",function(){ alert(); }); </script>
使用苹果手机访问的时候,发现了一个坑爹的问题,如论如何点击“下一步”,都没有任何反应,可是在安卓和各种模拟器中一切正常。后来经过查找资料才知道,苹果有这么个设置:
对于点击的对象,拥有cursor:pointer这个样式的设置,也就是说,鼠标放上去,能够出现“手”型的图标才被认作可以使用点击事件,
$(document).on("click",function(){})
试过很多办法,在元素生成后 再绑定事件,把click改成touch事件,都没有用,最后好不容易百度到了解决办法
解决的方法很巧妙,就是给需要绑定事件的元素添加一个css
cursor: pointer
selector { cursor:pointer }
#1099
<script> $(selector).click(function(){console.log(‘1111‘)}) </script>
#1100
<script> $(document).on("touchstart",function(){console.log(‘22222‘)}) </script>
#1101
大概写一下:
方法一:用触发手机的横屏和竖屏之间的切换的事件
window.addEventListener("orientationchange", function() { // 宣布新方向的数值 alert(window.orientation); }, false);
方法二:监听调整大小的改变
window.addEventListener("resize", function() { // 得到屏幕尺寸 (内部/外部宽度,内部/外部高度) }, false);
css判断横竖屏幕
@media screen and (orientation:portrait) { /* portrait-specific styles */ } /* landscape */ @media screen and (orientation:landscape) { /* landscape-specific styles */ }
本地window.matchMedia方法允许实时媒体查询。我们可以利用以上媒体查询找到我们是处于直立或水平视角:
var mql = window.matchMedia("(orientation: portrait)"); // 如果有匹配,则我们处于垂直视角 if(mql.matches) { // 直立方向 alert("1") } else { //水平方向 alert("2") } // 添加一个媒体查询改变监听者 mql.addListener(function(m) { if(m.matches) { // 改变到直立方向 document.getElementById("test").innerHTML="改变到直立方向"; } else { document.getElementById("test").innerHTML="改变到水平方向"; // 改变到水平方向 } });
#1102
我要的效果是这样的:当浏览器窗口大小变化时(缩小或者放大浏览器窗口),能够实时获取当前浏览器窗口的宽度和高度。我说的实时指不用刷新当前页面,当浏览器窗口大小改变时就触发事件。
试试resize事件
$(window).resize(function() { var width = $(this).width(); var height = $(this).height(); });
方法二:window.onresize=function(){///.....} 在方法里面写上对应的代码即可
着两种方法基本都可以解决你的问题了