收集的一些jQuery (我平常用的少的,但确实挺有效果的)
生活随笔
收集整理的這篇文章主要介紹了
收集的一些jQuery (我平常用的少的,但确实挺有效果的)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
禁用Jquery(動畫)效果
jQuery.fx.off = true;?
使用自己的 Bullets(這個有一丁點兒的小技巧)
//這里是js代碼 也就是給每個ul添加一個類名 然后給ul的子li前面添加html 你想要使用的Bullets $("ul").addClass("Replaced"); $("ul > li").prepend("? ");//在css里面這樣寫ul.Replaced { list-style : none; }?
寫自己的選擇器
$.extend($.expr[':'], {moreThen1000px: function(a) {return $(a).width() > 1000;}});$('.box:moreThen1000px').click(function() {// creating a simple js alert boxalert('The element that you have clicked is over 1000 pixels wide');});?
使元素屏幕居中
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();?
獲得鼠標指針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);});?
返回頁面頂部功能
$('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; } } });?
在新窗口中打開鏈接
//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";});?
轉載于:https://www.cnblogs.com/liyunhua/p/4495536.html
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的收集的一些jQuery (我平常用的少的,但确实挺有效果的)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: JSP-05- JSP总结
- 下一篇: Chapter 1. Introduce