新聞中心
jQuery是一個(gè)快速、簡(jiǎn)潔的JavaScript框架,是繼Prototype之后又一個(gè)優(yōu)秀的JavaScript代碼庫(kù)(框架)于2006年1月由[John Resig](https://baike.baidu.com/item/John Resig/6336344)發(fā)布。jQuery設(shè)計(jì)的宗旨是“write Less,Do More”,即倡導(dǎo)寫更少的代碼,做更多的事情。它封裝JavaScript常用的功能代碼,提供一種簡(jiǎn)便的JavaScript設(shè)計(jì)模式,優(yōu)化HTML文檔操作、事件處理、動(dòng)畫設(shè)計(jì)和Ajax交互。

成都創(chuàng)新互聯(lián)公司是專業(yè)的平羅網(wǎng)站建設(shè)公司,平羅接單;提供成都做網(wǎng)站、網(wǎng)站建設(shè),網(wǎng)頁(yè)設(shè)計(jì),網(wǎng)站設(shè)計(jì),建網(wǎng)站,PHP網(wǎng)站建設(shè)等專業(yè)做網(wǎng)站服務(wù);采用PHP框架,可快速的進(jìn)行平羅網(wǎng)站開發(fā)網(wǎng)頁(yè)制作和功能擴(kuò)展;專業(yè)做搜索引擎喜愛的網(wǎng)站,專業(yè)的做網(wǎng)站團(tuán)隊(duì),希望更多企業(yè)前來(lái)合作!
檢測(cè)Internet Explorer版本
當(dāng)涉及到CSS設(shè)計(jì)時(shí),對(duì)開發(fā)者和設(shè)計(jì)者而言Internet Explorer一直是個(gè)問題。盡管IE6的黑暗時(shí)代已經(jīng)過(guò)去,IE也越來(lái)越不流行,它始終是一個(gè)能夠容易檢測(cè)的好東西。當(dāng)然了,下面的代碼也能用于檢測(cè)別的瀏覽器。
jQuery檢測(cè)Internet Explorer版本
$(document).ready(function() {
if (navigator.userAgent.match(/msie/i) ){
alert('I am an old fashioned Internet Explorer');
}
});
平穩(wěn)滑動(dòng)到頁(yè)面頂部
這是一個(gè)最廣泛使用的jQuery效果:對(duì)一個(gè)鏈接點(diǎn)擊下會(huì)平穩(wěn)地將頁(yè)面移動(dòng)到頂部。這里沒什么新的內(nèi)容,但是每個(gè)開發(fā)者必須要會(huì)偶爾編寫一下類似函數(shù)
jQuery平穩(wěn)滑動(dòng)到頁(yè)面頂部
$("a[href='#top']").click(function() {
$("html, body").animate({ scrollTop: 0 }, "slow");
return false;
});
固定在頂部
非常有用的代碼片段,它允許一個(gè)元素固定在頂部。對(duì)導(dǎo)航按鈕、工具欄或重要信息框是超級(jí)有用的。
jQuery固定在頂部實(shí)例
$(function(){
var $win = $(window)
var $nav = $('.mytoolbar');
var navTop = $('.mytoolbar').length && $('.mytoolbar').offset().top;
var isFixed=0;
processScroll()
$win.on('scroll', processScroll)
function processScroll() {
var i, scrollTop = $win.scrollTop()
if (scrollTop >= navTop && !isFixed) {
isFixed = 1
$nav.addClass('subnav-fixed')
} else if (scrollTop $nav.removeClass('subnav-fixed')
}
}
檢測(cè)視窗寬度
現(xiàn)在移動(dòng)設(shè)備比過(guò)時(shí)的電腦更普遍,能夠方便去檢測(cè)一個(gè)更小的視窗寬度會(huì)很有幫助。幸運(yùn)的是,用jQuery來(lái)做超級(jí)簡(jiǎn)單。
jQuery檢測(cè)視窗寬度實(shí)例
var responsive_viewport = $(window).width();
/* if is below 481px */
if (responsive_viewport 'Viewport is smaller than 481px.');
}
/* end smallest screen */
自動(dòng)定位并修復(fù)損壞圖片
如果你的站點(diǎn)比較大而且已經(jīng)在線運(yùn)行了好多年,你或多或少會(huì)遇到界面上某個(gè)地方有損壞的圖片。這個(gè)有用的函數(shù)能夠幫助檢測(cè)損壞圖片并用你中意的圖片替換它,并會(huì)將此問題通知給訪客。
自動(dòng)定位并修復(fù)損壞圖片實(shí)例
$('img').error(function(){
$(this).attr('src', 'img/broken.png');
});
檢測(cè)復(fù)制、粘貼和剪切的操作
使用jQuery可以很容易去根據(jù)你的要求去檢測(cè)復(fù)制、粘貼和剪切的操作。
jQuery檢測(cè)復(fù)制、粘貼和剪切的操作實(shí)例
$("#textA").bind('copy', function() {
$('span').text('copy behaviour detected!')
});
$("#textA").bind('paste', function() {
$('span').text('paste behaviour detected!')
});
$("#textA").bind('cut', function() {
$('span').text('cut behaviour detected!')
});
遇到外部鏈接自動(dòng)添加target=”blank”的屬性
當(dāng)鏈接到外部站點(diǎn)時(shí),你可能使用target=”blank”的屬性去在新界面中打開站點(diǎn)。問題在于target=”blank”屬性并不是W3C有效的屬性。讓我們用jQuery來(lái)補(bǔ)救:下面這段代碼將會(huì)檢測(cè)是否鏈接是外鏈,如果是,會(huì)自動(dòng)添加一個(gè)target=”blank”屬性。
遇到外部鏈接自動(dòng)添加target=”blank”的屬性實(shí)例
var root = location.protocol + '//' + location.host;
$('a').not(':contains(root)').click(function(){
this.target = "_blank";
});
在圖片上停留時(shí)淡出或淡入效果
另一個(gè)“經(jīng)典的”代碼,它要放到你的工具箱里,因?yàn)槟銜?huì)不時(shí)地要實(shí)現(xiàn)它。
在圖片上停留時(shí)淡出或淡入效果
$(document).ready(function() {
$(".thumbs img").fadeTo("slow", 0.6); // This sets the opacity of the thumbs to fade down to 60% when the page loads
$(".thumbs img").hover(function() {
$(this).fadeTo("slow", 1.0); // This should set the opacity to 100% on hover
},
function() {
$(this).fadeTo("slow", 0.6); // This should set the opacity back to 60% on mouseout
});
});
在文本或密碼輸入時(shí)禁止空格鍵
在很多表格領(lǐng)域都不需要空格鍵,例如,電子郵件,用戶名,密碼等等等。這里是一個(gè)簡(jiǎn)單的技巧可以用于在選定輸入中禁止空格鍵。
jQuery禁止空格實(shí)例
$('input.nospace').keydown(function(e) {
if (e.keyCode == 32) {
return false;
}
});
本文名稱:10個(gè)提高Web開發(fā)速度的Query代碼片段
本文路徑:http://m.fisionsoft.com.cn/article/cdssisc.html


咨詢
建站咨詢
