亚洲AV永久无码精品放毛片,精品国产免费久久,成人午夜免费无码视频播放器,国产精品一区二区色欲AV

網(wǎng)站建設(shè)

結(jié)合設(shè)計(jì)經(jīng)驗(yàn)與營銷實(shí)踐,提供有價(jià)值的企業(yè)營銷資訊

首頁 > 新聞資訊 > 網(wǎng)站建設(shè)

程序猿都要了解的35個(gè) jQuery 小技巧(上)

2016/11/26 11:26:00 來源:網(wǎng)站建設(shè)公司
內(nèi)容摘要:深圳專業(yè)的網(wǎng)站建設(shè)公司,業(yè)務(wù)包含網(wǎng)站建設(shè)、網(wǎng)站設(shè)計(jì)、網(wǎng)站制作、網(wǎng)頁設(shè)計(jì)等服務(wù)的高端網(wǎng)站建設(shè)公司。為企業(yè)提供網(wǎng)站建設(shè)一站式服務(wù)。
收集的35個(gè) jQuery 小技巧/代碼片段,可以幫你快速開發(fā).

1. 禁止右鍵點(diǎn)擊

$(document).ready(function(){
    $(document).bind("contextmenu",function(e){
            return false;
    });
});
2. 隱藏搜索文本框文字

Hide when clicked in the search field, the value.(example can be found below in the comment fields)

$(document).ready(function() {
$("input.text1").val("Enter your search text here");
   textFill($('input.text1'));
}); 
    function textFill(input){ //input focus text function
     var originalvalue = input.val();
     input.focus( function(){
               if( $.trim(input.val()) == originalvalue ){ input.val(''); }
     });
     input.blur( function(){
               if( $.trim(input.val()) == '' ){ input.val(originalvalue); }
     });
}
3. 在新窗口中打開鏈接

XHTML 1.0 Strict doesn’t allow this attribute in the code, so use this to keep the code valid.

$(document).ready(function() {
   //Example 1: Every link will open in a new window
   $('a[href^="http://"]').attr("target", "_blank"); 
   //Example 2: Links with the rel="external" attribute will only open in a new window
   $('a[@rel$='external']').click(function(){
         this.target = "_blank";
   });
});// how to use
<a rel=external>open link</a>
4. 檢測瀏覽器

注: 在版本jQuery 1.4中,$.support 替換掉了$.browser 變量

$(document).ready(function() {
// Target Firefox 2 and above
if ($.browser.mozilla && $.browser.version >= "1.8" ){
    // do something
}
// Target Safari
if( $.browser.safari ){
    // do something
}
// Target Chrome
if( $.browser.chrome){
    // do something
}
// Target Camino
if( $.browser.camino){
    // do something
}
// Target Opera
if( $.browser.opera){
    // do something
}
// Target IE6 and below
if ($.browser.msie && $.browser.version <= 6 ){
    // do something
}
// Target anything above IE6
if ($.browser.msie && $.browser.version > 6){
    // do something
}
});
5. 預(yù)加載圖片

This piece of code will prevent the loading of all images, which can be useful if you have a site with lots of images.

$(document).ready(function() {
jQuery.preloadImages = function()
{
  for(var i = 0; i<ARGUMENTS.LENGTH; jQuery(?<img { i++)>").attr("src", arguments[i]);
  }
}
// how to use
$.preloadImages("image1.jpg");
});
6. 頁面樣式切換

$(document).ready(function() {
    $("a.Styleswitcher").click(function() {
        //swicth the LINK REL attribute with the value in A REL attribute
        $('link[rel=stylesheet]').attr('href' , $(this).attr('rel'));
    });
// how to use
// place this in your header
<LINK rel=stylesheet type=text/css href="default.css">
// the links
<A class=Styleswitcher href="#" rel=default.css>Default Theme</A>
<A class=Styleswitcher href="#" rel=red.css>Red Theme</A>
<A class=Styleswitcher href="#" rel=blue.css>Blue Theme</A>
});
7. 列高度相同

如果使用了兩個(gè)CSS列,使用此種方式可以是兩列的高度相同。

$(document).ready(function() {function equalHeight(group) {
    tallest = 0;
    group.each(function() {
        thisHeight = $(this).height();
                if(thisHeight > tallest) {
            tallest = thisHeight;
        }
    });
    group.height(tallest);
}// how to use$(document).ready(function() {
    equalHeight($(".left"));
    equalHeight($(".right"));
});
});
8. 動(dòng)態(tài)控制頁面字體大小

用戶可以改變頁面字體大小

$(document).ready(function() {
  // Reset the font size(back to default)
  var originalFontSize = $('html').css('font-size');
    $(".resetFont").click(function(){
    $('html').css('font-size', originalFontSize);
  });  // Increase the font size(bigger font0
  $(".increaseFont").click(function(){
      var currentFontSize = $('html').css('font-size');
          var currentFontSizeNum = parseFloat(currentFontSize, 10);
              var newFontSize = currentFontSizeNum*1.2;
    $('html').css('font-size', newFontSize);    return false;
  });  // Decrease the font size(smaller font)
  $(".decreaseFont").click(function(){
      var currentFontSize = $('html').css('font-size');
          var currentFontSizeNum = parseFloat(currentFontSize, 10);
              var newFontSize = currentFontSizeNum*0.8;
    $('html').css('font-size', newFontSize);
        return false;
  });
});
9. 返回頁面頂部功能

For a smooth(animated) ride back to the top(or any location).

$(document).ready(function() {
$('a[href*=#]').click(function() {
 if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
 && location.hostname == this.hostname) {
   var $target = $(this.hash);
   $target = $target.length && $target
   || $('[name=' + this.hash.slice(1) +']');
   if ($target.length) {
  var targetOffset = $target.offset().top;
  $('html,body')
  .animate({scrollTop: targetOffset}, 900);
    return false;
   }
  }
  });
// how to use
// place this where you want to scroll to
<A name=top></A>
// the link
<A href="#top">go to top</A>
});
10. 獲得鼠標(biāo)指針XY值

Want to know where your mouse cursor is?

$(document).ready(function() {
   $().mousemove(function(e){
     //display the x and y axis values inside the div with the id XY
    $('#XY').html("X Axis : " + e.pageX + " | Y Axis " + e.pageY);
  });
// how to use
<DIV id=XY></DIV>
});
11.返回頂部按鈕

你可以利用 animate 和 scrollTop 來實(shí)現(xiàn)返回頂部的動(dòng)畫,而不需要使用其他插件。

// Back to top
$('a.top').click(function () {
  $(document.body).animate({scrollTop: 0}, 800);
  return false;
});<!-- Create an anchor tag --><a class="top" href="#">Back to top</a>
改變 scrollTop 的值可以調(diào)整返回距離頂部的距離,而 animate 的第二個(gè)參數(shù)是執(zhí)行返回動(dòng)作需要的時(shí)間(單位:毫秒)。

12.預(yù)加載圖片

如果你的頁面中使用了很多不可見的圖片(如:hover 顯示),你可能需要預(yù)加載它們:

$.preloadImages = function () {  for (var i = 0; i < arguments.length; i++) {
    $('<img>').attr('src', arguments[i]);
  }
};

$.preloadImages('img/hover1.png', 'img/hover2.png');
13.檢查圖片是否加載完成

有時(shí)候你需要確保圖片完成加載完成以便執(zhí)行后面的操作:

$('img').load(function () {
  console.log('image load successful');
});
你可以把 img 替換為其他的 ID 或者 class 來檢查指定圖片是否加載完成。

14.自動(dòng)修改破損圖像

如果你碰巧在你的網(wǎng)站上發(fā)現(xiàn)了破碎的圖像鏈接,你可以用一個(gè)不易被替換的圖像來代替它們。添加這個(gè)簡單的代碼可以節(jié)省很多麻煩:

$('img').on('error', function () {
  $(this).prop('src', 'img/broken.png');
});
即使你的網(wǎng)站沒有破碎的圖像鏈接,添加這段代碼也沒有任何害處。

15.鼠標(biāo)懸停(hover)切換 class 屬性

假如當(dāng)用戶鼠標(biāo)懸停在一個(gè)可點(diǎn)擊的元素上時(shí),你希望改變其效果,下面這段代碼可以在其懸停在元素上時(shí)添加 class 屬性,當(dāng)用戶鼠標(biāo)離開時(shí),則自動(dòng)取消該 class 屬性:

$('.btn').hover(function () {
  $(this).addClass('hover');
  }, function () {
    $(this).removeClass('hover');
  });
你只需要添加必要的CSS代碼即可。如果你想要更簡潔的代碼,可以使用 toggleClass 方法:

$('.btn').hover(function () { 
  $(this).toggleClass('hover'); 
});
注:直接使用CSS實(shí)現(xiàn)該效果可能是更好的解決方案,但你仍然有必要知道該方法。

16.禁用 input 字段

有時(shí)你可能需要禁用表單的 submit 按鈕或者某個(gè) input 字段,直到用戶執(zhí)行了某些操作(例如,檢查“已閱讀條款”復(fù)選框)??梢蕴砑?disabled 屬性,直到你想啟用它時(shí):

$('input[type="submit"]').prop('disabled', true);
你要做的就是執(zhí)行 removeAttr 方法,并把要移除的屬性作為參數(shù)傳入:

$('input[type="submit"]').removeAttr('disabled');


程序猿都要了解的35個(gè) jQuery 小技巧(下)

http://www.ezekroy.com/jianzhanzhishi/7224.html 程序猿都要了解的35個(gè) jQuery 小技巧(上)

特別聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:0755-85297058;郵箱:2295772445#qq.com (#替換成@)。

標(biāo)簽:

QQ咨詢
微信咨詢
微信咨詢
電話咨詢
周一至周五 9:00-18:00
135-1055-3738
回頂部 久久精品无码专区免费久久精品| 国产熟女高潮一区二区三区| 玖玖热| 日韩人妻一区第一页中文字幕| 97久久碰国产精品2023| 日韩欧美综合精品| 国产传媒专区| 亚洲综合久久成人av| 欧美日韩一区一起草| 欧美另类z0z000| 噜噜噜精品欧美成| 91香蕉在线| 久久久久久久A V| 青青草97国产精品麻豆| 加勒比一区在线| 精品人妻无码一区二区三| 日韩小黄片| 91av导航| 最新欧美日韩| 色欲麻豆国产福利精品| 日韩另类一区| 麻豆一级人人| 在线看国产后入| 亚洲欧美第一区在线视频观看| 成人在线高清无码| 亚洲成人电影一区二区三区| 你懂的av| 久久精品人人做人人爱爱漫画| 亚洲 日韩 国产 欧美| 日本偷拍一区二区三区| 久久青青精品| 日本道精品在线999| 日韩免费黄片| 久久亚洲高清| 天堂欧美日韩| 日本午夜人妻中文字幕| 国内精品免费版久久亚瑟| 日韩天天视频| 久久久免费A级毛片| 97人人干| 无码国产精品久久一区免费温色 |