收集的一些jQuery (我平常用的少的,但確實挺有效果的)

來源:互聯網
上載者:User

標籤:style   blog   http   io   ar   color   os   使用   sp   

1、 禁用Jquery(動畫)效果
jQuery.fx.off = true;
2、使用自己的 Bullets(這個有一丁點兒的小技巧)
//這裡是js代碼  也就是給每個ul添加一個類名  然後給ul的子li前面添加html 你想要使用的Bullets$("ul").addClass("Replaced");$("ul > li").prepend("? "); //在css裡面這樣寫 ul.Replaced { list-style : none; }
3、寫自己的選取器
$.extend($.expr[‘:‘], {       moreThen1000px: function(a) {           return $(a).width() > 1000;      }   });  $(‘.box:moreThen1000px‘).click(function() {      // creating a simple js alert box      alert(‘The element that you have clicked is over 1000 pixels wide‘);  });
4、使元素螢幕置中
jQuery.fn.center = function () {      this.css("position","absolute");      this.css("top", ( $(window).height() - this.height() ) / 2+$(window).scrollTop() + "px");      this.css("left", ( $(window).width() - this.width() ) / 2+$(window).scrollLeft() + "px");      return this;  }//寬度置中的位置應該就是視窗寬度減去當前元素寬度再除以2 最後減掉左部滾動寬度 高度同理$("#id").center();
5、獲得滑鼠指標XY值
$().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);  });
6、返回頁面頂部功能
$(‘a[href*=#]‘).click(function() { if (location.pathname.replace(/^\//,‘‘) == this.pathname.replace(/^\//,‘‘) && location.hostname == this.hostname) {//為什麼會用replace呢  後來想想明白了 因為很多url裡面會有雙重的/這樣replace之後再比較比如好   var $target = $(this.hash);   $target = $target.length && $target|| $(‘[name=‘ + this.hash.slice(1) +‘]‘);//寫這麼晦澀的文法  意思就是說當前a元素的hash長度必須大於0並且不為undefined   則去找name等於獲得的hash值的元素   if ($target.length) {  var targetOffset = $target.offset().top;//獲得目標元素的高度  $(‘html,body‘).animate({scrollTop: targetOffset}, 900);

return false; } } });
7、在新視窗中開啟連結
//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";   });

 

 

收集的一些jQuery (我平常用的少的,但確實挺有效果的)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.