移動開發框架,第【一】彈:QuoJs 官方文檔(漢化版)


作者:一只猿

原文地址:

http://www.92ez.com

轉載請注明出處,謝謝

幫助說明

如果您認為QuoJS只是一個觸摸事件管理器,那你就錯了,它是一個功能豐富的類庫,無需第三方JavaScript庫(例如 jQuery, Prototype, Kendo ...)來創建基於瀏覽器應用程序的復雜項目。

 


如何使用
QuoJS使用的命名空間是$$,所以如果你需要的話,你還可以使用其它的JavaScript類庫例如(jQuery,Zepto...)使用通用符號$。

// Find all <span> elements in <p> elements
$$('span', 'p');

//Subscribe to a tap event with a callback
$$('p').tap(function() {
    // affects "span" children/grandchildren
    $$('span', this).style('color', 'red');
});

// Chaining methods
$$('p > span').html('tapquo').style('color', 'blue');

查詢方法
QuoJs有DOM元素查詢引擎與其它著名的類庫非常相似.你已經使用的jQuery的很多方法在這里都可以使用.

// jQuery的支持的查詢方
.get(index)
.find('selector')
.parent()
.siblings('selector')
.children('selector')
.first()
.last()
.closest('selector')
.each(callback)

元素方法
QuoJs有DOM元素查詢引擎與其它著名的類庫非常相似.你已經使用的jQuery的很多方法在這里都可以使用.

// Get/Set element attribute
.attr('attribute')
.attr('attribute', 'value')
.removeAttr('attribute')
// Get/Set the value of the "data-name" attribute
.data('name')
.data('name', 'value')
// Get/Set the value of the form element
.val()
.val('value')
// Show/Hide a element
.show()
.hide()
// get object dimensions in px
.offset('selector')
.height()
.width()
// remove element
.remove()

樣式方法
QuoJS可以輕松管理你任何DOM元素的CSS樣式,這些方法很箱子,你很容易記住所有的CSS方法

// set a CSS property
.style('css property', 'value')
 // add/remove a CSS class name
.addClass('classname')
.removeClass('classname')
.toggleClass('classname')
// returns true of first element has a classname set
.hasClass('classname')
// Set a style with common vendor prefixes
.vendor('transform', 'translate3d(50%, 0, 0)');

$$('article').style('height', '128px');
$$('article input').addClass('hide');

var houses = $$('.house');
if (houses.hasClass('ghost')) {
    houses.addClass('buuhh');
}
DOM操作方法
這些方法允許我們插入/更新現有的元素,里面的內容。
// get first element's .innerHTML
.html()
// set the contents of the element(s)
.html('new html')
// get first element's .textContent
.text()
// set the text contents of the element(s)
.text('new text')
// add html (or a DOM Element) to element contents
.append(), prepend()
// If you like set a new Dom Element in a existing element
.replaceWith()
// Empty element
.empty()

$$('article').html('tapquo');
var content = $$('article').html(); //content is 'tapquo'
事件處理
每一個前端項目需要一個高效的事件管理,你可以創建自己的活動,以及現有的訂閱。
// add event listener to elements
.on(type, [selector,] function);
// remove event listener from elements
.off(type, [selector,] function);
// triggers an event
.trigger(type);
//If loaded correctly all resources
.ready(function);

// Subscribe for a determinate event
$$(".tapquo").on("tap", function);
// Trigger custom event
$$(".quojs").trigger("loaded");
// Loaded page
$$.ready(function() {
    alert("QuoJS rulz!");
});

手勢事件
既然QuoJs支持瀏覽器的觸摸事件,那么你有無數的事件和手勢來幫助你做任何一個項目

//Tap event, common event
.tap(function);
//Long tap event (650 miliseconds)
.hold(function);
//A tap-delay event to combine with others events
.singleTap(function);
//If you send two singleTap
.doubleTap(function);

滑動方法
不僅有基本的滑動方法,常見的應用程序中有很多的滑動你都可以使用

.swipe(function);
//Detect if is swipping
.swiping(function);
//Swipe directions
.swipeLeft(function);
.swipeRight(function);
.swipeDown(function);
.swipeUp(function);

捏方法(類似iphone圖片縮小的手勢 )

As with the previous gesture, QuoJS have easy control over this gesture and its variations.
.pinch(function);
//Detect if is pinching
.pinching(function);
//Pinch zoom
.pinchIn(function);
.pinchOut(function);

旋轉方法(Rotate methods)

.rotate(function);
//Detect if is rotating
.rotating(function);
//Rotate directions
.rotateLeft(function);
.rotateRight(function);

Ajax方法

$$.get(url, [parameters], [callback], [mime-type]);
$$.post(url, [parameters], [callback], [mime-type]);
$$.put(url, [parameters], [callback], [mime-type]);
$$.delete(url, [parameters], [callback], [mime-type]);
$$.json(url, [parameters], [callback]);

$$.json(url, {id: 1980, user: 'dan'}, function(data){ ... });

$$.ajax({
    type: 'POST', // defaults to 'GET'
    url: 'http://rest',
    data: {user: 'soyjavi', pass: 'twitter'},
    dataType: 'json', //'json', 'xml', 'html', or 'text'
    async: true,
    success: function(response) { ... },
    error: function(xhr, type) { ... }
});
//Default Settings
$$.ajaxSettings = {
    async: true,
    success: {},
    error: {},
    timeout: 0
};

//Set de default timeout to 1 second (1000 miliseconds)
$$.ajaxSettings.timeout = 1000;

//Set de default callback when ajax request failed
$$.ajaxSettings.error = function(){ ... };

$$.ajaxSettings.async = false;
var response = $$.json('http://', {id: 1980, user: 'dan'});

環境事件
The environment object contains useful information to learn more about your device.

var env = $$.environment();

env.browser     //[STRING] Browser of your mobile device
env.isMobile    //[BOOLEAN]
env.os.name     //[STRING] iOS, Android, Blackberry...
env.os.version  //[STRING] Versión of OS
env.screen      //[OBJECT] With properties: width & height

 



免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM