2013年12月31日
#
摘要: 适合Linux系统使用的命令,本文以亚马逊的Amazon Linux 为用例,希望对朋友们有点帮助!切换至root用户 sudo su 安装screen yum install screen yum update 安装Apache,MySQL... 阅读全文
希望WP爱好者能够喜欢并尝试一下‘
1.样式表 - /*SidebarTabsAd*/
- #cwpad_box{width:100%;text-align:center}
- #cwpad_box ul, #cwpad_box dd, #cwpad_box tt{
- margin:0px;
- padding:0px;
- float:left;
- list-style: none;
- }
- #cwpad_box{
- width:313px;/*250px+(n-1)*21px*/
- height:250px;
- border-left: 1px solid #740a20;
- }
- #cwpad_box dd{
- width:21px;
- height:250px;
- overflow:hidden;
- position:relative;
- }
- #cwpad_box dd.hove{
- width:250px;
- text-align:rightright;
- }
- #cwpad_box dd tt{
- width:20px;
- height:250px;
- top:0px;
- left:0px;
- color:#fff;
- cursor:pointer;
- text-align:center;
- padding:20px 0 0 0;
- background:#b9000d;
- position:absolute;
- border-right:1px solid #740a20;
- }
- #cwpad_box dd tt.hove{
- background:#620317;
- }
在上面的样式表中,假设放置的是四个250px*250px的图片广告,所以250+(4-1)*21=313px。 2.javascript代码 - <script type="text/javascript">
- function myAddEvent(obj, sEvent, fn){
- return obj.attachEvent ? obj.attachEvent('on' + sEvent, fn) : obj.addEventListener(sEvent, fn, false);
- }
- function Class(oParent, sClass){
- var aElem = oParent.getElementsByTagName('*');
- var aClass = [];
- var i = 0;
- for(i=0;i<aElem.length;i++)if(aElem[i].className == sClass)aClass.push(aElem[i]);
- return aClass;
- };
- function css(obj, attr, value){
- if(arguments.length == 2){
- var style = obj.style,
- currentStyle = obj.currentStyle;
- if(typeof attr === 'string')return currentStyle ? currentStyle[attr] : getComputedStyle(obj, false)[attr];
- for(var propName in attr)propName == 'opacity' ? (style.filter = "alpha(opacity=" + attr[propName] + ")", style.opacity = attr[propName] / 100) : style[propName] = attr[propName];
- }else if(arguments.length == 3){
- switch(attr){
- case "width":
- case "height":
- case "paddingTop":
- case "paddingRight":
- case "paddingBottom":
- case "paddingLeft":
- case "top":
- case "right":
- case "bottom":
- case "left":
- case "marginTop":
- case "marginRigth":
- case "marginBottom":
- case "marginLeft":
- obj.style[attr] = value + "px";
- break;
- case "opacity":
- obj.style.filter = "alpha(opacity=" + value + ")";
- obj.style.opacity = value / 100;
- break;
- default:
- obj.style[attr] = value
- }
- }
- };
- function extend(destination, source){
- for (var propName in source) destination[propName] = source[propName];
- return destination
- };
- function doMove(obj, json, fnEnd){
- clearInterval(obj.timer);
- obj.iSpeed = 0;
- fnEnd = extend({
- type: "buffer",
- callback: function() {}
- }, fnEnd);
- obj.timer = setInterval(function(){
- var iCur = 0,
- iStop = true;
- for(var propName in json){
- iCur = parseFloat(css(obj, propName));
- propName == 'opacity' && (iCur = Math.round(iCur * 100));
- switch(fnEnd.type){
- case 'buffer':
- obj.iSpeed = (json[propName] - iCur) / 5;
- obj.iSpeed = obj.iSpeed > 0 ? Math.ceil(obj.iSpeed) : Math.floor(obj.iSpeed);
- json[propName] == iCur || (iStop = false, css(obj, propName, iCur + obj.iSpeed));
- break;
- case 'elasticity':
- obj.iSpeed += (json[propName] - iCur) / 5;
- obj.iSpeed *= 0.75;
- Math.abs(json[propName] - iCur) <= 1 && Math.abs(obj.iSpeed) <= 1 ? css(obj, propName, json[propName]) : css(obj, propName, json[propName]) || (iStop = false, css(obj, propName, iCur + obj.iSpeed));
- break;
- case 'accelerate':
- obj.iSpeed = obj.iSpeed + 5;
- iCur >= json[propName] ? css(obj, propName, json[propName]) : css(obj, propName, json[propName]) || (iStop = false, css(obj, propName, iCur + obj.iSpeed));
- break;
- }
- }
- if(iStop){
- clearInterval(obj.timer);
- obj.timer = null;
- obj.iSpeed = 0;
- fnEnd.callback();
- }
- },30);
- };
-
- window.onload = function(){
- var oBox = document.getElementById('cwpad_box')
- var aSpan = document.getElementsByTagName('tt');
- var aLi = document.getElementsByTagName('dd');
- var playtime = null;
- var iNow = 0;
- for(i=0;i<aSpan.length;i++){
- aSpan[i].index = i;
- aSpan[i].onclick = function(){
- for(var len=aLi.length,i=0;i<len;i++)doMove(aLi[i], {width:21});
- for(var len=aSpan.length,i=0;i<len;i++)aSpan[i].className = '';
- this.className = 'hove';
- doMove(this.parentNode, {width:250});
- iNow = this.index;
- };
- }
- playtime = setInterval(tab,3500);
- oBox.onmouseover = function(){
- clearInterval(playtime);
- }
- oBox.onmouseout = function(){
- playtime = setInterval(tab,3500);
- }
- function tab(){
- iNow == aLi.length-1 ? iNow = 0 : iNow++;
- aSpan[iNow].onclick();
- }
- };
- </script>
3.示例的HTML代码 - <div id="cwpad_box">
- <ul>
- <dd class="hove">
- <tt class="hove">网站设计及培训</tt>
- <a href="http://suoling.net/" target=_blank title="网站设计及培训"><img src="http://fakeimg.pl/250x250/?text=Hello,A!"></a>
- </dd>
- <dd>
- <tt>网站优化及培训</tt>
- <a href="http://suoling.net/" target=_blank title="网站优化及培训"><img src="http://fakeimg.pl/250x250/?text=Hello,B!"></a>
- </dd>
- <dd>
- <tt>网站诊断</tt>
- <a href="http://suoling.net/" target=_blank title="网站诊断"><img src="http://fakeimg.pl/250x250/?text=Hello,C!"></a>
- </dd>
- <dd>
- <tt>电子商务培训</tt>
- <a href="http://suoling.net/" target=_blank title="电子商务培训"><img src="http://fakeimg.pl/250x250/?text=Hello,D!"></a>
- </dd>
- </ul>
- </div>
使用的是索凌网络前面介绍过的"假图"生成网站fakeimg.pl生成的"假图"。 这组代码的一个显著缺点是:不适合移动设备显示。
- if(is_admin())
- {
- new Cool_Wp_List_Table();
- }
-
- /**
- * Cool_Wp_List_Table class will create the page to load the table
- */
- class Cool_Wp_List_Table
- {
- /**
- * Constructor will create the menu item
- */
- public function __construct()
- {
- add_action( 'admin_menu', array($this, 'add_menu_example_list_table_page' ));
- }
-
- /**
- * Menu item will allow us to load the page to display the table
- */
- public function add_menu_example_list_table_page()
- {
- add_menu_page( 'Coowp示例表格', 'Coowp示例表格', 'manage_options', 'coolwp-list-table.php', array($this, 'list_table_page') );
- }
-
- /**
- * Display the list table page
- *
- * @return Void
- */
- public function list_table_page()
- {
- $exampleListTable = new Example_List_Table();
- $exampleListTable->prepare_items();
- ?>
- <div class="wrap">
- <div id="icon-users" class="icon32"></div>
- <h2>Coowp示例表格-页面标题</h2>
- <?php $exampleListTable->display(); ?>
- </div>
- <?php
- }
- }
-
- // WP_List_Table is not loaded automatically so we need to load it in our application
- if( ! class_exists( 'WP_List_Table' ) ) {
- require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
- }
-
- /**
- * Create a new table class that will extend the WP_List_Table
- */
- class Example_List_Table extends WP_List_Table
- {
- /**
- * Prepare the items for the table to process
- *
- * @return Void
- */
- public function prepare_items()
- {
- $columns = $this->get_columns();
- $hidden = $this->get_hidden_columns();
- $sortable = $this->get_sortable_columns();
-
- $data = $this->table_data();
- usort( $data, array( &$this, 'sort_data' ) );
-
- $perPage = 2;
- $currentPage = $this->get_pagenum();
- $totalItems = count($data);
-
- $this->set_pagination_args( array(
- 'total_items' => $totalItems,
- 'per_page' => $perPage
- ) );
-
- $data = array_slice($data,(($currentPage-1)*$perPage),$perPage);
-
- $this->_column_headers = array($columns, $hidden, $sortable);
- $this->items = $data;
- }
-
- /**
- * Override the parent columns method. Defines the columns to use in your listing table
- *
- * @return Array
- */
- public function get_columns()
- {
- $columns = array(
- 'id' => __('ID'),
- 'title' => __('Title'),
- 'description' => __('描述'),
- //__('Description'),怎么被Wordpress翻译为“图像描述”了?
- 'date' => __('Date'),
- 'price' => __('价格'),//__('Price'),
- 'rating' => __('Rating')
- );
-
- return $columns;
- }
-
- /**
- * Define which columns are hidden
- *
- * @return Array
- */
- public function get_hidden_columns()
- {
- return array();
- }
-
- /**
- * Define the sortable columns
- *
- * @return Array
- */
- public function get_sortable_columns()
- {
- return array('title' => array('title', false));
- }
-
- /**
- * Get the table data
- *
- * @return Array
- */
- private function table_data()
- {
- $data = array();
-
- $data[] = array(
- 'id' => 1,
- 'title' => '某IT设备租赁公司:杨先生',
- 'description' => '上海,需求描述',
- 'date' => '2013.01.01',
- 'price' => '---',
- 'rating' => '7.3'
- );
-
- $data[] = array(
- 'id' => 2,
- 'title' => '某婚摄团队:李先生',
- 'description' => '台湾,台北',
- 'date' => '2013.12.15',
- 'price' => '---',
- 'rating' => '7.2'
- );
-
- $data[] = array(
- 'id' => 3,
- 'title' => '在校研究生:梁小姐',
- 'description' => '墨尔本大学:艺术设计',
- 'date' => '2013.12.03',
- 'price' => '---',
- 'rating' => '7.0'
- );
-
- $data[] = array(
- 'id' => 4,
- 'title' => '某私人航空公司',
- 'description' => '仅前端交互:何小姐',
- 'date' => '2014.01.01',
- 'price' => '---',
- 'rating' => '7.0'
- );
- return $data;
- }
-
- /**
- * Define what data to show on each column of the table
- *
- * @param Array $item Data
- * @param String $column_name - Current column name
- *
- * @return Mixed
- */
- public function column_default( $item, $column_name )
- {
- switch( $column_name ) {
- case 'id':
- case 'title':
- case 'description':
- case 'date':
- case 'price':
- case 'rating':
- return $item[ $column_name ];
-
- default:
- return print_r( $item, true ) ;
- }
- }
-
- /**
- * Allows you to sort the data by the variables set in the $_GET
- *
- * @return Mixed
- */
- private function sort_data( $a, $b )
- {
- // Set defaults
- $orderby = 'title';
- $order = 'asc';
-
- // If orderby is set, use this as the sort column
- if(!emptyempty($_GET['orderby']))
- {
- $orderby = $_GET['orderby'];
- }
-
- // If order is set use this as the order
- if(!emptyempty($_GET['order']))
- {
- $order = $_GET['order'];
- }
-
- $result = strcmp( $a[$orderby], $b[$orderby] );
-
- if($order === 'asc')
- {
- return $result;
- }
-
- return -$result;
- }
- }
ENJOY IT!
如果网页包含大量图片,那么,采用Lazyload来延迟图片的载入以加速网页整体在浏览器中的载入是个不错的方法!
上面这句话并不是翻译来的,只是我想一句话说完。
下面开始吧:
1.在页面头部加载jQuery和这个Lazyload插件,如果已经加载过了jQuery,那就不用再次加载了:
<script src="http://upcdn.b0.upaiyun.com/libs/jquery/jquery-1.8.3.min.js" type="text/javascript"></script> <script src="jquery.lazyload.js" type="text/javascript"></script>
是的,我习惯在国内用又拍云的云加速。
对图片的处理:
<img class="lazy" src="img/grey.gif" data-original="img/true_image.jpg" width="730" heigh="300">
上面示例中的grey.gif实际上相当于一个占位符,建议采用1*1px的灰色png或者gif,data-original后面的才是真正的图片链接,class="lazy"是个可以定义的特定class。 Lazyload基本设置
<script type="text/javascript" charset="utf-8"> $(function() { $("img.lazy").lazyload(); }); </script>
Lazyload基本设置的在线DEMO:Lazyload DEMO1 对不支持js浏览器的处理
<img class="lazy" src="img/grey.gif" data-original="img/true_image.jpg" width="730" heigh="300"> <noscript><img src="img/true_image.jpg" width="730" heigh="300"></noscript>
用CSS隐藏占位符:
.lazy { display: none; }
对支持js的浏览器,应该在DOM准备阶段就初始化插件:
$("img.lazy").show().lazyload();
当然了,这样处理兼容性更好,不过现在的浏览器大多都是支持js的。 加载敏感度
默认的情况下,图片将会在出现在屏幕上时显示,如果想提载入图片,可以使用 threshold 进行设置,下例的含义是:在图片距离屏幕180px时提前载入:
$("img.lazy").lazyload({ threshold :180});
占位图片
可以自定义一个简单的浅色或灰色系的小图片(越小越好,1*1px最佳,格式推荐采用gif)作为占位图片来触发加载动作。 事件触发
可以是jQuery的任何事件(如click、mouseover),还可以使用自己定义的事件。
例如:处于等待状态, 直到浏览者滚动到窗口中图片所在位置,在占位图片被点击之前不加载图片, 可以这样做:
$("img").lazyload({ placeholder : "img/grey.gif", event : "click" });
特效的使用
当图片完全加载的时候,默认使用show()方法来显示图片,所以,上面的那个基本设置示例中未写出show(),但是可以照常运行。 图片淡入(FadeIn)效果
$("img.lazy").lazyload({ effect : "fadeIn" });
Lazyload图片淡入效果演示 将图片放在特定容器中
先看示例:水平滚动演示页面和垂直滚动的演示页面
CSS部分示例
#container { height: 600px; overflow: scroll; }
js部分示例
$("img.lazy").lazyload({ container: $("#container") });
图片未按顺序排列的情况
滚动页面的时候,Lazyload会按照在HTML代码中的顺序先后可视范围内的加载图片,在第一张不在可视范围内的图片处停止执行,但是在某些页面布局中,这种聪明的假设可能是不成立的,那么可以用failurelimit来控制加载动作:
$("img.lazy").lazyload({ failure_limit : 10 });
上面的意思是:在找到10张不在可视范围内的图片时停止执行。额,好吧,如果你的页面布局猥琐到10不足以满足的时候,那就再大一些吧。 Lazyload定时延迟图片载入
Lazyload的一个并不完备的功能,并不影响使用,但是实际用途并不大!用途描述:在页面和可见图片载入后一定时间内载入图片。Lazyload定时延迟图片载入示例
$(function() { $("img:below-the-fold").lazyload({ event : "sporty" }); }); $(window).bind("load", function() { var timeout = setTimeout(function() {$("img.lazy").trigger("sporty")}, 5000); });
上例中采用的参数或者说定时是5秒。 加载隐藏的图片
你的页面上可能隐藏了很多不可见的图片用作特殊用途,Lazyload默认是忽略这些图片的,如果不想忽略掉,可以这样:
$("img.lazy").lazyload({ skip_invisible : false });
Lazyload下载与兼容性
最新的未压缩版 source与压缩版 minified。
你看到这篇文章时可能有更新的版本了,请点击Lazyload了解更多!
兼容于:
OSX平台: Safari 5.1, Safari 6, Chrome 20, Firefox 12
WIN平台:Chrome 20, IE 8 and IE 9 on Windows
iPhone和 iPad上:Safari 5.1
本文介绍一组适用于在Wordpress侧栏放置的图片广告轮播(js)代码:可自动播放,同时响应访客的点击 1.样式表 - /*SidebarTabsAd*/
- #cwpad_box{width:100%;text-align:center}
- #cwpad_box ul, #cwpad_box dd, #cwpad_box tt{
- margin:0px;
- padding:0px;
- float:left;
- list-style: none;
- }
- #cwpad_box{
- width:313px;/*250px+(n-1)*21px*/
- height:250px;
- border-left: 1px solid #740a20;
- }
- #cwpad_box dd{
- width:21px;
- height:250px;
- overflow:hidden;
- position:relative;
- }
- #cwpad_box dd.hove{
- width:250px;
- text-align:rightright;
- }
- #cwpad_box dd tt{
- width:20px;
- height:250px;
- top:0px;
- left:0px;
- color:#fff;
- cursor:pointer;
- text-align:center;
- padding:20px 0 0 0;
- background:#b9000d;
- position:absolute;
- border-right:1px solid #740a20;
- }
- #cwpad_box dd tt.hove{
- background:#620317;
- }
在上面的样式表中,假设放置的是四个250px*250px的图片广告,所以250+(4-1)*21=313px。 2.javascript代码 - <script type="text/javascript">
- function myAddEvent(obj, sEvent, fn){
- return obj.attachEvent ? obj.attachEvent('on' + sEvent, fn) : obj.addEventListener(sEvent, fn, false);
- }
- function Class(oParent, sClass){
- var aElem = oParent.getElementsByTagName('*');
- var aClass = [];
- var i = 0;
- for(i=0;i<aElem.length;i++)if(aElem[i].className == sClass)aClass.push(aElem[i]);
- return aClass;
- };
- function css(obj, attr, value){
- if(arguments.length == 2){
- var style = obj.style,
- currentStyle = obj.currentStyle;
- if(typeof attr === 'string')return currentStyle ? currentStyle[attr] : getComputedStyle(obj, false)[attr];
- for(var propName in attr)propName == 'opacity' ? (style.filter = "alpha(opacity=" + attr[propName] + ")", style.opacity = attr[propName] / 100) : style[propName] = attr[propName];
- }else if(arguments.length == 3){
- switch(attr){
- case "width":
- case "height":
- case "paddingTop":
- case "paddingRight":
- case "paddingBottom":
- case "paddingLeft":
- case "top":
- case "right":
- case "bottom":
- case "left":
- case "marginTop":
- case "marginRigth":
- case "marginBottom":
- case "marginLeft":
- obj.style[attr] = value + "px";
- break;
- case "opacity":
- obj.style.filter = "alpha(opacity=" + value + ")";
- obj.style.opacity = value / 100;
- break;
- default:
- obj.style[attr] = value
- }
- }
- };
- function extend(destination, source){
- for (var propName in source) destination[propName] = source[propName];
- return destination
- };
- function doMove(obj, json, fnEnd){
- clearInterval(obj.timer);
- obj.iSpeed = 0;
- fnEnd = extend({
- type: "buffer",
- callback: function() {}
- }, fnEnd);
- obj.timer = setInterval(function(){
- var iCur = 0,
- iStop = true;
- for(var propName in json){
- iCur = parseFloat(css(obj, propName));
- propName == 'opacity' && (iCur = Math.round(iCur * 100));
- switch(fnEnd.type){
- case 'buffer':
- obj.iSpeed = (json[propName] - iCur) / 5;
- obj.iSpeed = obj.iSpeed > 0 ? Math.ceil(obj.iSpeed) : Math.floor(obj.iSpeed);
- json[propName] == iCur || (iStop = false, css(obj, propName, iCur + obj.iSpeed));
- break;
- case 'elasticity':
- obj.iSpeed += (json[propName] - iCur) / 5;
- obj.iSpeed *= 0.75;
- Math.abs(json[propName] - iCur) <= 1 && Math.abs(obj.iSpeed) <= 1 ? css(obj, propName, json[propName]) : css(obj, propName, json[propName]) || (iStop = false, css(obj, propName, iCur + obj.iSpeed));
- break;
- case 'accelerate':
- obj.iSpeed = obj.iSpeed + 5;
- iCur >= json[propName] ? css(obj, propName, json[propName]) : css(obj, propName, json[propName]) || (iStop = false, css(obj, propName, iCur + obj.iSpeed));
- break;
- }
- }
- if(iStop){
- clearInterval(obj.timer);
- obj.timer = null;
- obj.iSpeed = 0;
- fnEnd.callback();
- }
- },30);
- };
-
- window.onload = function(){
- var oBox = document.getElementById('cwpad_box')
- var aSpan = document.getElementsByTagName('tt');
- var aLi = document.getElementsByTagName('dd');
- var playtime = null;
- var iNow = 0;
- for(i=0;i<aSpan.length;i++){
- aSpan[i].index = i;
- aSpan[i].onclick = function(){
- for(var len=aLi.length,i=0;i<len;i++)doMove(aLi[i], {width:21});
- for(var len=aSpan.length,i=0;i<len;i++)aSpan[i].className = '';
- this.className = 'hove';
- doMove(this.parentNode, {width:250});
- iNow = this.index;
- };
- }
- playtime = setInterval(tab,3500);
- oBox.onmouseover = function(){
- clearInterval(playtime);
- }
- oBox.onmouseout = function(){
- playtime = setInterval(tab,3500);
- }
- function tab(){
- iNow == aLi.length-1 ? iNow = 0 : iNow++;
- aSpan[iNow].onclick();
- }
- };
- </script>
3.示例的HTML代码 - <div id="cwpad_box">
- <ul>
- <dd class="hove">
- <tt class="hove">网站设计及培训</tt>
- <a href="http://suoling.net/" target=_blank title="网站设计及培训"><img src="http://fakeimg.pl/250x250/?text=Hello,A!"></a>
- </dd>
- <dd>
- <tt>网站优化及培训</tt>
- <a href="http://suoling.net/" target=_blank title="网站优化及培训"><img src="http://fakeimg.pl/250x250/?text=Hello,B!"></a>
- </dd>
- <dd>
- <tt>网站诊断</tt>
- <a href="http://suoling.net/" target=_blank title="网站诊断"><img src="http://fakeimg.pl/250x250/?text=Hello,C!"></a>
- </dd>
- <dd>
- <tt>电子商务培训</tt>
- <a href="http://suoling.net/" target=_blank title="电子商务培训"><img src="http://fakeimg.pl/250x250/?text=Hello,D!"></a>
- </dd>
- </ul>
- </div>
使用的是索凌网络前面介绍过的"假图"生成网站fakeimg.pl生成的"假图"。 这组代码的一个显著缺点是:不适合移动设备显示。
|